MathGroup Archive 2013

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Variable transformations

  • To: mathgroup at
  • Subject: [mg131464] Re: Variable transformations
  • From: Alexei Boulbitch <Alexei.Boulbitch at>
  • Date: Mon, 29 Jul 2013 23:21:08 -0400 (EDT)
  • Delivered-to:
  • Delivered-to:
  • Delivered-to:
  • Delivered-to:

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.


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:
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]
RowBox[{"(", "3", ")"}],
MultilineFunction->None]\)[Sin[z]] -
 Sin[z] (-Sin[z] (y^\[Prime]\[Prime])[Sin[z]] + Cos[z]^2
RowBox[{"(", "3", ")"}],
MultilineFunction->None]\)[Sin[z]]) + Cos[z]^4
RowBox[{"(", "4", ")"}],

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 +

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.
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

  • Prev by Date: Re: Finding a function within an arbitrary expression
  • Next by Date: ensuring that instructions are performed sequentially
  • Previous by thread: Re: Variable transformations
  • Next by thread: Incorrect (unexpected) output from TransformedField