Ask Your Question
0

Getting an error while trying to solve a third order DE

asked 2022-02-05 10:46:22 +0100

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

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2022-02-08 19:48:18 +0100

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 $x_1 = x, x_2 = x'(t), x_3 = x''(t)$, the third order ODE becomes the system of first-order ODE $x_1' = x_2, x_2' = x_3, x_3' = 2x_3 - 5x_2$.

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)
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: 2022-02-05 10:43:12 +0100

Seen: 420 times

Last updated: Feb 08 '22