If I have an equation
eq = f[x] + g[x] == 0
and I solve for f[x]
sol = Solve[eq,f[x]]
how do I use sol to replace both f[x] and its derivatives in another equation? For example
eq2 = f'[x]*g[x] + f[x] == 0
and then
eq2 /. sol
outputs
{-g[x] + g[x] f'[x] == 0}
Answer
The problem is caused by the internal structure of Derivative:
f'[x] // FullForm
(* ==> Derivative[1][f][x] *)
There's no f[x] in there to replace. Using D[f[x], x] instead of f'[x] and Holding the whole equation works:
eq2 = Hold[D[f[x], x]*g[x] + f[x] == 0];
ReleaseHold[eq2 /. sol]
(* ==> {-g[x] - g[x] Derivative[1][g][x] == 0} *)
Comments
Post a Comment