2
$\begingroup$

I have trouble with symbolic functional derivatives and substitute , for example,

result1 =[D[f[x, y], x]]

$result1 = \frac{\partial f[x,y]}{\partial x} $

next, i want take $f[x,y]=x+y$ substitute into result1. This is very useful in symbolic computation, especially when substituting functions into expressions after complex computations.

I have try this answer with Inactivate ,this is a very early version, and Inactivate will deactivate all partial derivatives. It's very inconvenient, for example, When I only care about the properties of f,

result1 = Inactivate[D[f[x, y] Cos[x], x], D]

the output is $\frac{\partial (\cos (x) f(x,y))}{\partial x}$ , is there any better method can able to substitute f into the expression while computing known functions as much as possible?

As the follows example,

 result1 =[D[f[x, y] Cos[x], x]]  
 result2 = result1/.{f[x,y]=x+y} 

I want output is $result1 = \frac{\partial ( f(x,y))}{\partial x}\cos (x)-\sin (x) f(x,y), result2 = \cos (x)-(x+y) \sin (x)$

$\endgroup$
1
  • $\begingroup$ Maybe i can use result1 =[D[f[x, y] Cos[x], x]], result2 =Inactivate[[D[f[x, y] Cos[x], x]],D] , result3 = result2/.{f[x,y]=x+y} and at last, result4 = Activate@ result3, but this looks clumsy, any advise very be much appreciate! $\endgroup$
    – benx4
    Oct 16, 2022 at 15:26

2 Answers 2

3
$\begingroup$

Another way could be to simply define your replacement for $f(x,y)$ using Function notation as follows

ClearAll[f, x, y]
result1 = D[f[x, y] Cos[x], x]
myf = Function[{x, y}, x + y]
result2 = result1 /. f -> myf

Mathematica graphics

This is the same trick used to verify solution of an ode by plugging in the solution in Function form back into the ode which has derivatives in it.

$\endgroup$
1
  • $\begingroup$ Thank you and Neumann, this answer solved my problem perfectly! $\endgroup$
    – benx4
    Oct 16, 2022 at 15:34
2
$\begingroup$

What about

result1 = D[f[x, y] Cos[x], x] (*-f[x, y] Sin[x] + Cos[x] Derivative[1, 0][f][x, y]*)
result1 /. f -> Function[{x, y}, x + y](*Cos[x] - (x + y) Sin[x]*)
$\endgroup$
1
  • $\begingroup$ Thank you and Nasser, this answer solved my problem perfectly! $\endgroup$
    – benx4
    Oct 16, 2022 at 15:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.