How to make function substitution in math

I have an expression D[f[x, y], x] , and I want to replace f[x,y] with x*y , I tried the following:

D[f[x, y], x] /. {f[x,y] -> x*y} D[f[x, y], x] /. {f[x,y] -> x*y} and also D[f[x, y], x] /. {f -> x*y} D[f[x, y], x] /. {f -> x*y}

But no one worked. Thank your help! Thanks.

+7
source share
3 answers

FullForm derivative in your expression

 In[145]:= D[f[x,y],x]//FullForm Out[145]//FullForm= Derivative[1,0][f][x,y] 

This should explain why the first rule failed - f[x,y] is no longer in your expression. The second rule failed because Derivative considers f function, while you substitute it with an expression. What you can do is:

 In[146]:= D[f[x,y],x]/.f->(#1*#2&) Out[146]= y 

Note that parentheses around a pure function are needed to avoid priority-related errors.

Alternatively, you can define your rhs templates:

 In[148]:= fn[x_,y_]:=x*y; D[f[x,y],x]/.f->fn Out[149]= y 

NTN

+12
source

Nothing new, as I usually think about it:

 D[f[x, y], x] /. f -> Function[{x, y}, xy] 

Output

 y 
+5
source

You can also try Hold and Release or Snooze, etc.

 Hold@D [f[x, y], x] /. {f[x, y] -> x*y} D[xy, x] Hold@D [f[x, y], x] /. {f[x, y] -> x*y} // Release y 
+2
source

All Articles