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, 26 Mar 2021 23:55:46 +0100How to find second order differential equation from general solution?https://ask.sagemath.org/question/56389/how-to-find-second-order-differential-equation-from-general-solution/ I've looked everywhere on Sage but I simply cannot find any command that'll help me with this.
It's essentially using desolve, but backwards, like if I'm given
y=C1*e^-x + C2*x*e^-x
how would I figure out the original second order differential equation?
Thanks!Fri, 26 Mar 2021 17:33:33 +0100https://ask.sagemath.org/question/56389/how-to-find-second-order-differential-equation-from-general-solution/Comment by slelievre for <p>I've looked everywhere on Sage but I simply cannot find any command that'll help me with this.</p>
<p>It's essentially using desolve, but backwards, like if I'm given</p>
<pre><code>y=C1*e^-x + C2*x*e^-x
</code></pre>
<p>how would I figure out the original second order differential equation?
Thanks!</p>
https://ask.sagemath.org/question/56389/how-to-find-second-order-differential-equation-from-general-solution/?comment=56392#post-id-56392Welcome to Ask Sage!
Thank you for your questions!Fri, 26 Mar 2021 18:30:39 +0100https://ask.sagemath.org/question/56389/how-to-find-second-order-differential-equation-from-general-solution/?comment=56392#post-id-56392Answer by slelievre for <p>I've looked everywhere on Sage but I simply cannot find any command that'll help me with this.</p>
<p>It's essentially using desolve, but backwards, like if I'm given</p>
<pre><code>y=C1*e^-x + C2*x*e^-x
</code></pre>
<p>how would I figure out the original second order differential equation?
Thanks!</p>
https://ask.sagemath.org/question/56389/how-to-find-second-order-differential-equation-from-general-solution/?answer=56393#post-id-56393In this case, the function in the question has two parameters,
so it describes a vector space of dimension 2 inside the
space of functions from ℝ to ℝ.
So we might look for a linear differential equation of order two.
Then for each of the functions $x \mapsto e^{-x}$ and $x \mapsto x e^{-x}$,
we can look for linear relations between the function, its derivative,
and its second derivative.
See [Ask Sage question 56390](http://ask.sagemath.org/question/56390) about that.
Then we can find a common linear dependence relation that works for both.
That will be the desired differential equation.
For another approach, use power series expansions of the functions and the
[ore-algebra package](https://www3.risc.jku.at/research/combinat/software/ore_algebra/),
see in particular the [guessing module](http://www.algebra.uni-linz.ac.at/people/mkauers/ore_algebra/generated/ore_algebra.guessing.html).Fri, 26 Mar 2021 18:39:21 +0100https://ask.sagemath.org/question/56389/how-to-find-second-order-differential-equation-from-general-solution/?answer=56393#post-id-56393Comment by Presto.creator for <p>In this case, the function in the question has two parameters,
so it describes a vector space of dimension 2 inside the
space of functions from ℝ to ℝ.</p>
<p>So we might look for a linear differential equation of order two.</p>
<p>Then for each of the functions $x \mapsto e^{-x}$ and $x \mapsto x e^{-x}$,
we can look for linear relations between the function, its derivative,
and its second derivative.</p>
<p>See <a href="http://ask.sagemath.org/question/56390">Ask Sage question 56390</a> about that.</p>
<p>Then we can find a common linear dependence relation that works for both.</p>
<p>That will be the desired differential equation.</p>
<p>For another approach, use power series expansions of the functions and the
<a href="https://www3.risc.jku.at/research/combinat/software/ore_algebra/">ore-algebra package</a>,
see in particular the <a href="http://www.algebra.uni-linz.ac.at/people/mkauers/ore_algebra/generated/ore_algebra.guessing.html">guessing module</a>.</p>
https://ask.sagemath.org/question/56389/how-to-find-second-order-differential-equation-from-general-solution/?comment=56395#post-id-56395I didn't know my questions were so similar, thank you again! You're a good personFri, 26 Mar 2021 21:36:31 +0100https://ask.sagemath.org/question/56389/how-to-find-second-order-differential-equation-from-general-solution/?comment=56395#post-id-56395Answer by Juanjo for <p>I've looked everywhere on Sage but I simply cannot find any command that'll help me with this.</p>
<p>It's essentially using desolve, but backwards, like if I'm given</p>
<pre><code>y=C1*e^-x + C2*x*e^-x
</code></pre>
<p>how would I figure out the original second order differential equation?
Thanks!</p>
https://ask.sagemath.org/question/56389/how-to-find-second-order-differential-equation-from-general-solution/?answer=56401#post-id-56401You can derive two times the identity $y=C_1e^{-x} + C_2 x e^{-x}$, take the two derivatives for solving $C_1$ and $C_2$, and then replace these constants in the initial identity, that is:
var("C1, C2")
y = function("y")(x)
f = C1*e^(-x) + C2*x*e^(-x)
sol = solve([diff(y==f,x), diff(y==f,x,2)], C1, C2)
ode = (y-f==0).subs(sol).full_simplify()
show(ode)
The output is
$$y\left(x\right) + 2 \\, \frac{\partial}{\partial x}y\left(x\right) + \frac{\partial^{2}}{(\partial x)^{2}}y\left(x\right) = 0$$
You can prettify it by using, for example, the following code inspired by @slelievre's answer to [this question](https://ask.sagemath.org/question/41644), i.e.:
y1 = function("y1", latex_name="y'")(x)
y2 = function("y2", latex_name="y''")(x)
ode_pretty = ode.subs({diff(y(x), x):y1, diff(y(x), x, x): y2})
show(ode_pretty)
which yields
$$y\left(x\right) + 2 \\, y'\left(x\right) + y''\left(x\right) = 0$$
Fri, 26 Mar 2021 23:55:46 +0100https://ask.sagemath.org/question/56389/how-to-find-second-order-differential-equation-from-general-solution/?answer=56401#post-id-56401