I have this differential equation in terms of the variable $y$

deq[y_]=y^2 U''[y] + (a y^2 + b y + c) U'[y] + (d y + f) U[y]=0

and I want to make the change of variable y=t x and express deq[y_] as deq[x_]. Just defining y=t x, the above equation will be

(f + d t x) U[t x] + (c + b t x + a t^2 x^2) U'[t x] + t^2 x^2 U''[t x]

as can be seen, in this way, Mathematica only substitutes y by t x but according to these tranformation

$$ \frac{d}{\text{dy}}= \frac{\text{dx}}{\text{dy}} \frac{d}{\text{dx}}=\frac{1}{t} \frac{d}{\text{dx}} $$ and

$$ \frac{d^2}{\text{dy}^2}=\frac{1}{t^2} \frac{d^2}{\text{dx}^2}$$

I expect the differential equation deq[x_] as

deq[x_]=(f + d t x) U[x] + (c + b t x + a t^2 x^2) 1/t  U'[ x] + 
 t^2 x^2 1/t^2  U''[x]=0

How can I ask Mathematica to do this directly (I mean change the derivative functions as well)?


2 Answers 2

ode = y^2 *U''[y] + (a*y^2 + b*y + c)*U'[y] + (d*y + f)*U[y] == 0
DSolveChangeVariables[Inactive[DSolve][ode, U[y], y], u, x, x == y/t]

Mathematica graphics


The above function is for V 13.1 and higher. For older versions you could try Kuba's DChange

First you need to install it

(If[DirectoryQ[#], DeleteDirectory[#, DeleteContents -> True]];
    "https://raw.githubusercontent.com/" <> 
    FileNameJoin[{#, "MoreCalculus.m"}]]) &@
 FileNameJoin[{$UserBaseDirectory, "Applications", "MoreCalculus"}]

Mathematica graphics

I do not know if you can do this at University computer or not. After the the above load the package using

<< MoreCalculus`

Now you can do

ode = y^2*U''[y] + (a*y^2 + b*y + c)*U'[y] + (d*y + f)*U[y] == 0
DChange[ode, {y == x*t}, {y}, {x}, {U[y]}]

Mathematica graphics

  • $\begingroup$ I am using Mathematica 12. Running your code, I get ` DSolveChangeVariables[DSolve[(f + d y) U[y] + (c + b y + a y^2) U'[y]+ y^2U''[y] == 0, U[y], y], u, x, x == y/t] ` $\endgroup$
    – PhysFan
    Feb 3 at 15:15
  • $\begingroup$ Is the beginning of your code DSolveChangeVariables[Inactive[DSolve] correct? $\endgroup$
    – PhysFan
    Feb 3 at 15:18
  • 1
    $\begingroup$ @PhysFan According to the documentation, DSolveChangeVariables is new in Verion 14. If I recall correctly, code to change ODE independent variables for earlier versions of Mathematica was posted somewhere on this site. $\endgroup$
    – bbgodfrey
    Feb 3 at 15:49
  • 1
    $\begingroup$ @bbgodfrey actually it was added in V 13.1 in 2022. I do not know why the page says NEW but scrolling down to the bottom of the above pages says V 13.1 also this page of new features of 13.1 shows it there. So it has been around for 2 years now. Time for OP to upgrade :) $\endgroup$
    – Nasser
    Feb 3 at 21:20
  • 1
    $\begingroup$ @PhysFan you could ask your Univ. Computer lab person to update Mathematica. Meanwhile I added version for older Mathematica $\endgroup$
    – Nasser
    Feb 3 at 21:48

If you want to do it with just plain substitution you can do this.

deq = y^2  U''[y] + (a  y^2 + b  y + c)  U'[y] + (d  y + f)  U[y] == 0

deq /. {U -> (U[#/t] &)} /. y -> t  x

(*(U'[x]  (a t^2 x^2 + b t x + c))/t + U[x] (d t x + f) + x^2  U''[x] == 0*)

I think this works for any Version of Mathematica.


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.