# 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!

edit retag close merge delete

Sort by » oldest newest most voted You 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, 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$$

more

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

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.

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, see in particular the guessing module.

more

I didn't know my questions were so similar, thank you again! You're a good person