ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 08 Feb 2022 19:48:18 +0100Getting an error while trying to solve a third order DEhttps://ask.sagemath.org/question/60946/getting-an-error-while-trying-to-solve-a-third-order-de/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 desolveSat, 05 Feb 2022 10:43:12 +0100https://ask.sagemath.org/question/60946/getting-an-error-while-trying-to-solve-a-third-order-de/Answer by rburing for <p>The question is:</p>
<blockquote>
<p>Solve the follwing differential equation using sagemath:</p>
<p>x'''(t) − 2x''(t) + 5x(t) = 0, x(0) = 0, x'(0) = 0, x''(0) = 1</p>
</blockquote>
<p>I tried using this code:</p>
<pre><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]))
</code></pre>
<p>I am getting this error:</p>
<pre><code>TypeError: ECL says: Error executing code in Maxima: diff: second argument must be a variable; found _SAGE_VAR_t
</code></pre>
<p>What am I doing wrong?</p>
<p>I have also tried using desolve_laplace instead of desolve</p>
https://ask.sagemath.org/question/60946/getting-an-error-while-trying-to-solve-a-third-order-de/?answer=61022#post-id-61022First 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`](https://doc.sagemath.org/html/en/reference/calculus/sage/calculus/desolvers.html#sage.calculus.desolvers.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`](https://doc.sagemath.org/html/en/reference/calculus/sage/calculus/desolvers.html#sage.calculus.desolvers.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)Tue, 08 Feb 2022 19:48:18 +0100https://ask.sagemath.org/question/60946/getting-an-error-while-trying-to-solve-a-third-order-de/?answer=61022#post-id-61022