Loading [MathJax]/jax/output/HTML-CSS/jax.js
Ask Your Question
0

Getting an error while trying to solve a third order DE

asked 3 years ago

The question is:

Solve the follwing differential equation using sagemath:

x'''(t) − 2x''(t) + 5x(t) = 0, x(0) = 0, x'(0) = 0, x''(0) = 1

I tried using this code:

var('s, t')
x = function('x')(t)
de = diff(x, t, 3) - 2*diff(x, t, 2) + 5*diff(x, t) == 0
show(desolve(de, x, ics = [0, 0, 0, 1]))

I am getting this error:

TypeError: ECL says: Error executing code in Maxima: diff: second argument must be a variable; found _SAGE_VAR_t

What am I doing wrong?

I have also tried using desolve_laplace instead of desolve

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
1

answered 3 years ago

rburing gravatar image

First update your SageMath to the latest version, so that you get a different error, namely:

NotImplementedError: Maxima was unable to solve this ODE. Consider to set option contrib_ode to True.

Passing the option, we get:

NotImplementedError: Maxima was unable to solve this ODE.

Reading the documentation of desolve, we find:

Solve a 1st or 2nd order linear ODE, including IVP and BVP.

Since your ODE is not 1st or 2nd order, it is understandable that the attempt failed.

You can try solving a system instead. Setting x1=x,x2=x(t),x3=x(t), the third order ODE becomes the system of first-order ODE x1=x2,x2=x3,x3=2x35x2.

It can be solved with SageMath's desolve_system::

sage: var('t')
sage: x1 = function('x1')(t)
sage: x2 = function('x2')(t)
sage: x3 = function('x3')(t)
sage: sol = desolve_system([diff(x1,t) == x2, diff(x2,t) == x3, diff(x3,t) == 2*x3 - 5*x2], [x1,x2,x3], ics=[0,0,0,1]); sol
[x1(t) == -1/10*(2*cos(2*t) - sin(2*t))*e^t + 1/5,
 x2(t) == 1/2*e^t*sin(2*t),
 x3(t) == 1/2*(2*cos(2*t) + sin(2*t))*e^t]
sage: x = sol[0].rhs(); x
-1/10*(2*cos(2*t) - sin(2*t))*e^t + 1/5
sage: x.subs(t==0), diff(x,t).subs(t==0), diff(x,t,2).subs(t==0)
(0, 0, 1)
Preview: (hide)
link

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: 3 years ago

Seen: 541 times

Last updated: Feb 08 '22