output formatting - Can I ask Mathematica to replace the arguments of my functions with a replacement rule?
I have an equation that I evaluate at some point (let's say $x=1$) that have terms of the form
f[1,y] D[g[1,y],{y,2}]
Is there an easy way to replace [1,y] by [x,y] with a simple replacement rule? The thing is that
g[1,y] /. g[1,y] -> g[x,y]
will indeed replace g, but it won't work for any of its derivatives, and there are far too many functions and derivatives for me to make a replacement rule for all of them.
Would there be a clever way to do this? So far, my only solution has been copy-pasting my equations in Word and using the text replacement tool in there. It would be neat not having to go outside of Mathematica to do this though.
Answer
Taking the question as "how to replace the first argument in $g(a,b)$ as well as all of its derivatives", you can do this:
Check the InputForm of the derivative:
D[g[1, y], {y, 2}] // InputForm
(* ==> Derivative[0, 2][g][1, y] *)
Add a corresponding pattern to the replacement rules:
f[1, y] D[g[1, y], {y, 2}] /.
{g[1, y] -> g[x, y], Derivative[d___][g][1, y] :> Derivative[d][g][x, y]}
Comments
Post a Comment