Re: Variable transformations
- To: mathgroup at smc.vnet.net
 - Subject: [mg131464] Re: Variable transformations
 - From: Alexei Boulbitch <Alexei.Boulbitch at iee.lu>
 - Date: Mon, 29 Jul 2013 23:21:08 -0400 (EDT)
 - Delivered-to: l-mathgroup@mail-archive0.wolfram.com
 - Delivered-to: l-mathgroup@wolfram.com
 - Delivered-to: mathgroup-outx@smc.vnet.net
 - Delivered-to: mathgroup-newsendx@smc.vnet.net
 
Say I have some differential equation in terms of the independent variable 
x and dependent variable f(x). Now say I want to do a coordinate/variable transformation where x=x(u) and I want to write my equation in terms of only u and f(u). By pencil & paper, you can do this by applying the chain rule, but I have a complicated equation and I want to check if I've made an algebra slip-up (it involves several dependent and independent variables and up to 4th order derivatives). Is there any way to automate something like this in Mathematica? I've messed around with replacement rules, but I can't get Mathematica to do things quite how I want.
Thanks!
Hi, Nicholas,
This problem has been discussed few times, and I copy-paste here one of the answers, the one I like most. I do not remember, however, who gave it:
The rule has the form:
y->(y[g[#]]&)
the round parentheses are important. It does not work without.
(* The task is to substitute x->z^2 *)
y'[x] /. y -> (y[#^2] &) /. x -> z
y''[x] /. y -> (y[#^2] &) /. x -> z
2 z Derivative[1][y][z^2]
2 Derivative[1][y][z^2] + 4 z^2 (y^\[Prime]\[Prime])[z^2]
(* The task is to substitute x->Sin[z] into the fourth order derivative *)
y''''[x] /. y -> (y[Sin[#]] &) /. x -> z
Sin[z] Derivative[1][y][Sin[z]] -
 4 Cos[z]^2 (y^\[Prime]\[Prime])[Sin[z]] +
 2 Sin[z]^2 (y^\[Prime]\[Prime])[Sin[z]] - 5 Cos[z]^2 Sin[z]
\!\(\*SuperscriptBox[\(y\),
TagBox[
RowBox[{"(", "3", ")"}],
Derivative],
MultilineFunction->None]\)[Sin[z]] -
 Sin[z] (-Sin[z] (y^\[Prime]\[Prime])[Sin[z]] + Cos[z]^2
\!\(\*SuperscriptBox[\(y\),
TagBox[
RowBox[{"(", "3", ")"}],
Derivative],
MultilineFunction->None]\)[Sin[z]]) + Cos[z]^4
\!\(\*SuperscriptBox[\(y\),
TagBox[
RowBox[{"(", "4", ")"}],
Derivative],
MultilineFunction->None]\)[Sin[z]]
This method applies also to substitute a function into an expression containing derivatives, such that these derivatives would be calculated as well as the function itself:
Clear[expr, rule];
expr = (r[\[CurlyPhi]]^2 + 2 Derivative[1][r][\[CurlyPhi]]^2 -
    r[\[CurlyPhi]] (
      r^\[Prime]\[Prime])[\[CurlyPhi]])^2/(r[\[CurlyPhi]]^2 +
    Derivative[1][r][\[CurlyPhi]]^2)^2;
rule = r -> (r0 + r1*Cos[#] &);
expr /. rule
(r1 Cos[\[CurlyPhi]] (r0 + r1 Cos[\[CurlyPhi]]) + (r0 +
    r1 Cos[\[CurlyPhi]])^2 +
  2 r1^2 Sin[\[CurlyPhi]]^2)^2/((r0 + r1 Cos[\[CurlyPhi]])^2 +
  r1^2 Sin[\[CurlyPhi]]^2)^2
Have fun, Alexei
Alexei BOULBITCH, Dr., habil.
IEE S.A.
ZAE Weiergewan,
11, rue Edmond Reuter,
L-5326 Contern, LUXEMBOURG
Office phone :  +352-2454-2566
Office fax:       +352-2454-3566
mobile phone:  +49 151 52 40 66 44
e-mail: alexei.boulbitch at iee.lu