Ask Your Question
1

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

asked 2019-01-17 05:27:41 +0100

Thrash gravatar image

updated 2019-01-17 05:29:32 +0100

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 flag offensive close merge delete

Comments

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

FrédéricC gravatar imageFrédéricC ( 2019-01-17 09:54:02 +0100 )edit

2 Answers

Sort by » oldest newest most voted
2

answered 2019-01-17 21:21:32 +0100

Emmanuel Charpentier gravatar image

updated 2019-01-17 22:28:35 +0100

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

edit flag offensive delete link more
1

answered 2019-01-17 15:59:20 +0100

calc314 gravatar image

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))
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2019-01-17 05:27:41 +0100

Seen: 523 times

Last updated: Jan 17 '19