# How can I solve the following (linear) differential equation?

I want Sage to solve this equation: $y'''-3y''+y'-5y=0$.

Both

y=function('y')(x)
desolve(diff(y,3)-3*diff(y,2)+diff(y,1)-5*y,y)


and

giac("desolve([y'''-3y''+y'-5y],y)").sage()


result in errors.

edit retag close merge delete

giac gives an answer, but this answer fails to be converted to sage

( 2019-01-17 09:54:02 +0200 )edit

Sort by » oldest newest most voted

[ Not really an answer, but refinements needing more than the 500 characters of a comment ]

calc314's answer is an explicit solution :

import sympy
y=function("y")(x)
E1=diff(y(x),x,3)(x)-3*diff(y(x),x,2)(x)+diff(y(x),x)(x)-5*y(x)==0
Sol=sympy.dsolve(*map(sympy.sympify, [E1,y(x)]))._sage_()
Sol
y(x) == C3*e^(x*complex_root_of(x^3 - 3*x^2 + x - 5, 2)) + C2*e^(x*complex_root_of(x^3 - 3*x^2 + x - 5, 1)) + C1*e^(x*complex_root_of(x^3 - 3*x^2 + x - 5, 0))


The function complex_root_of(P,i) is a formal function representing the ith root of the polynomial P (in a stable fashion), which can be evaluated numerically). See its help docstring, as well as sympy's CRoot's.

If symbolic solutions are needed, you can also extract the characteristic polynomial and solve it symbolically :

Sol.rhs().operands()[0].operands()[1].operands()[0].operands()[1].operands()[0].solve(x)
[x == -1/2*(1/9*sqrt(235)*sqrt(3) + 3)^(1/3)*(I*sqrt(3) + 1) + 1/3*(I*sqrt(3) - 1)/(1/9*sqrt(235)*sqrt(3) + 3)^(1/3) + 1,
x == -1/2*(1/9*sqrt(235)*sqrt(3) + 3)^(1/3)*(-I*sqrt(3) + 1) + 1/3*(-I*sqrt(3) - 1)/(1/9*sqrt(235)*sqrt(3) + 3)^(1/3) + 1,
x == (1/9*sqrt(235)*sqrt(3) + 3)^(1/3) + 2/3/(1/9*sqrt(235)*sqrt(3) + 3)^(1/3) + 1]


But I think that the "formal root" form s a better expression in a lot of situations.

more

sympy does give a solution, but it leaves you to solve the characteristic equation.

from sympy import *
y=Function('y')
dsolve(Eq(Derivative(y(x),x,x,x)-3*Derivative(y(x),x,x)+Derivative(y(x),x) -5*y(x), 0), y(x))

more