ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 28 Jan 2022 15:10:00 +0100How to change variables in differential equation?https://ask.sagemath.org/question/58133/how-to-change-variables-in-differential-equation/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?Wed, 28 Jul 2021 02:17:33 +0200https://ask.sagemath.org/question/58133/how-to-change-variables-in-differential-equation/Comment by leandro.petrini for <p>Hey guys,</p>
<p>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 :</p>
<pre><code> G=function('G')
F=G(r)*e^(-I*w*t)
equa = diff(F,r,2)+diff(F,t)F
</code></pre>
<p>and let's say I'd like to change the variable r to z = r^2 - a^2.</p>
<p>The way I do it now is using the following trick:</p>
<pre><code>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()
</code></pre>
<p>It gives the following depreciation message:</p>
<pre><code>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=...)
</code></pre>
<p>It's very clumsy, but at least it is working.</p>
<p>But that is not it. The following code just gives rubbish output using more or less the same logic</p>
<pre><code>var('m')
exm = function('exam')(x,y)
diffequ= diff(exm,x)
diffexp= function('probe')(m+y^2,y/x)
diffequ.substitute_function(exam,diffexp)
</code></pre>
<p>output:
D_0(probe)(y^2+x,1)</p>
<p>Which is just plain wrong!</p>
<p>Is there a way to work around those problems?</p>
https://ask.sagemath.org/question/58133/how-to-change-variables-in-differential-equation/?comment=60854#post-id-60854I 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*D[1](p)(y^2 + m, y/x)/x^2Fri, 28 Jan 2022 15:10:00 +0100https://ask.sagemath.org/question/58133/how-to-change-variables-in-differential-equation/?comment=60854#post-id-60854Comment by leandro.petrini for <p>Hey guys,</p>
<p>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 :</p>
<pre><code> G=function('G')
F=G(r)*e^(-I*w*t)
equa = diff(F,r,2)+diff(F,t)F
</code></pre>
<p>and let's say I'd like to change the variable r to z = r^2 - a^2.</p>
<p>The way I do it now is using the following trick:</p>
<pre><code>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()
</code></pre>
<p>It gives the following depreciation message:</p>
<pre><code>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=...)
</code></pre>
<p>It's very clumsy, but at least it is working.</p>
<p>But that is not it. The following code just gives rubbish output using more or less the same logic</p>
<pre><code>var('m')
exm = function('exam')(x,y)
diffequ= diff(exm,x)
diffexp= function('probe')(m+y^2,y/x)
diffequ.substitute_function(exam,diffexp)
</code></pre>
<p>output:
D_0(probe)(y^2+x,1)</p>
<p>Which is just plain wrong!</p>
<p>Is there a way to work around those problems?</p>
https://ask.sagemath.org/question/58133/how-to-change-variables-in-differential-equation/?comment=60852#post-id-60852Which 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
and I want to test on different cases (has been working for me, so far). If it works, I'll post as an answerFri, 28 Jan 2022 14:45:44 +0100https://ask.sagemath.org/question/58133/how-to-change-variables-in-differential-equation/?comment=60852#post-id-60852