How to change variables in differential equation?

asked 2021-07-28 02:24:05 +0100

litvath gravatar image

Hey guys,

I'd like to find a way to make a change of variables in diff equation(why is there no intrinsic method?) My attempt: Assume that I have some random equation :

  G=function('G')
  F=G(r)*e^(-I*w*t)
  equa = diff(F,r,2)+diff(F,t)F

and let's say I'd like to change the variable r to z = r^2 - a^2.

The way I do it now is using the following trick:

var('z')
p=solve(z==(r^2-a^2) ,r)
T = function('T')(z)
final = equat.substitute_function(G,T).subs(r=p[0].rhs()).full_simplify()

It gives the following depreciation message:

DeprecationWarning: Substitution using function-call syntax and unnamed arguments is deprecated and will be removed from a future release of Sage; you can use named arguments instead, like EXPR(x=..., y=...)

It's very clumsy, but at least it is working.

But that is not it. The following code just gives rubbish output using more or less the same logic

var('m')
exm = function('exam')(x,y)
diffequ= diff(exm,x)
diffexp= function('probe')(m+y^2,y/x)
diffequ.substitute_function(exam,diffexp)

output: D_0(probe)(y^2+x,1)

Which is just plain wrong!

Is there a way to work around those problems?

edit retag flag offensive close merge delete

Comments

Which result did you get from the first substitution (involving G, F) and what did you expect for the second substitution? I'm modifying the function from this answer (done in SymPy) to Sage: https://stackoverflow.com/questions/57840957/differential-equation-change-of-variables-with-sympy/70872803#70872803 (https://stackoverflow.com/questions/5...)

and I want to test on different cases (has been working for me, so far). If it works, I'll post as an answer

leandro.petrini gravatar imageleandro.petrini ( 2022-01-28 14:45:44 +0100 )edit

I got: - First problem:

 -I*w*G(z)^2*e^(-2*I*t*w) + 2*(2*(a^2 + z)*diff(G(z), z, z) + diff(G(z), z))*e^(-I*t*w)
  • Second problem:

    -y*D1(y^2 + m, y/x)/x^2

leandro.petrini gravatar imageleandro.petrini ( 2022-01-28 15:10:00 +0100 )edit