verifying differential equation solution with sage

636 Views Asked by At

I solved the linear ODE system of equations: \begin{equation} x' = \begin{pmatrix}3&0&4\\0&2&0\\0&0&-3\end{pmatrix}x \end{equation}

Skipping the details I got the following eigenpairs:

\begin{align} \lambda_0=3, x_0=\begin{pmatrix}1\\0\\0\end{pmatrix}&\\ \lambda_1=2, x_1=\begin{pmatrix}0\\1\\0\end{pmatrix}&\\ \lambda_2=-3, x_2=\begin{pmatrix}\frac{2}{3}\\0\\1\end{pmatrix}& \end{align} Thus the general solution is: \begin{equation} x(t) = c_1e^{3t}\begin{pmatrix}1\\0\\0\end{pmatrix} + c_2e^{2t}\begin{pmatrix}0\\1\\0\end{pmatrix}+c_3e^{-3t}\begin{pmatrix}\frac{2}{3}\\0\\1\end{pmatrix} \end{equation} Here is what I got from sage:

sage: t = var('t') 
sage: x = function('x', t)
sage: y = function('y', t)
sage: z = function('z', t)
sage: de1 = diff(x, t) -3*x -4*z == 0
sage: de2 = diff(y, t) -2*y == 0                                            
sage: de3 = diff(z, t) +3*z == 0                                            
sage: desolve_system([de1, de2, de3], [x, y, z])                            
[x(t) == 1/3*(3*x(0) + 2*z(0))*e^(3*t) - 2/3*e^(-3*t)*z(0),                 
 y(t) == e^(2*t),                                                           
 z(t) == e^(-3*t)*z(0)]

So my solution looks fine in terms of $y(t)$ and $z(t)$ but my $x(t)$ is different in the coefficient of $e^{3t}$

Why does sage give a different answer?

Specifically:

  1. Did I solve the system incorrectly?
  2. Did sage choose different eigenvectors?
  3. Is sage only giving me a nicer scaling of the eigenvectors?

All help is greatly appreciated!

1

There are 1 best solutions below

2
On BEST ANSWER

Okay, we have:

$$x' = \begin{bmatrix}3&0&4\\0&2&0\\0&0&-3\end{bmatrix}x$$

The CP is: $-\lambda^3+2 \lambda^2+9 \lambda-18 \rightarrow \lambda_1 = -3 , \lambda_2 =3 , \lambda_3 = 2$.

We have three distinct and real eigenvalues, so we form $[A-\lambda I] v_i = 0$ to find the eigenvectors and get the following eigenvalue/eigenvector pairs:

  • For $\lambda_1 = -3$, the RREF gives us:

$c = 3, b= 0 , a = -(2/3) c = -2 \rightarrow v_1 = (-2,0,3)$ (note, c is a free variable)

  • For $\lambda_2 = 3$, the RREF gives us:

$c = 0, b= 0 , a = 1 \rightarrow v_2 = (1,0,0)$ (note, a is a free variable)

  • For $\lambda_3 = 2$, the RREF gives us:

$a = 0, c = 0, b = 1 \rightarrow v_3 = (0,1,0)$ (note, b is a free variable)

Summarizing these, we have:

  • $\lambda_1 = -3, ~v_1 = (-2, 0, 3)$
  • $\lambda_2 = 3, ~v_2 = (1, 0, 0)$
  • $\lambda_3 = 2, ~v_3 = (0, 1, 0)$

The solution is then given by:

$$x(t) = c_1 e^{\lambda_1 t}v_1 + c_2 e^{\lambda_2 t}v_2 + c_3 e^{\lambda_3 t} v_3 = c_1 e^{-3t}\begin{bmatrix}-2\\0\\3\end{bmatrix} + c_2e^{3t} \begin{bmatrix}1\\0\\0\end{bmatrix} + c_3e^{2t}\begin{bmatrix}0\\1\\0\end{bmatrix}$$

If we compare this to your solution, you note that for my first vector, I chose $c=3$, where you chose $1$, hence these are actually the same (actually, you lost a negative sign - please check that)!

If we write out the solution for this, we get:

$$x(t) = \begin{bmatrix}x(t)\\y(t)\\z(t)\end{bmatrix} = \begin{bmatrix} - 2c_1 e^{-3t}+c_2e^{3t} \\ c_3 e^{2t}\\ 3c_1e^{-3t}\end{bmatrix}$$

First question, why are the variables all negated in the Sage approach? That changes things. The eigenvalues are the same, but the eigenvectors are swapped around. Can you try it with the same signs as the matrix has?

It also looks like they are using some other algorithm to find these, but if you reduce all of their constants to a single constant, it is basically the same. It is odd that they chose $c_3 = 1$, but there is likely a reason for that.

Let me clarify what I am saying here. For their solution, we can equate their constants (make sure I did not make a silly algebra error here) to the ones we used as:

  • $c_1 = \dfrac{z(0)}{3}, c_2 = \dfrac{1}{3}(3 x(0) + 2 z(0)), c_3 = 1$.

These are totally arbitrary, but with that change, you can see we are talking the same thing. Whatever internal algorithm they are using chooses things in that form.

Update

I ran the script using the online version of Sage with the same variables and signs as the matrix $A$, and the result (I MathJax'ed it) is:

  • $x(t) = \dfrac{1}{3}(3 x(0) + 2 z(0))e^{-3t} - \frac{2}{3}e^{3t}z(0)$
  • $y(t) = e^{-2t}y(0)$
  • $z(t) = e^{3t}z(0)$

Which has the wrong sign for an eigenvalue (online version), maybe for all three as it is hard to tell!

I tried the online Maxima and here is the result, just like my eigenvalues/eigenvectors (note the sign and fraction on one of them).

So, why does Sage require users to change all of the signs of the matrix? Regardless, changing the signs does produce the correct eigenvalues and the constants as shown above and through the simple transformation, it is the same result I derived.