```python
import loader
from sympy import *
init_printing()
from root.solver import *
```

Find the general solution of
$$
    \vec{\mathbf{x'}} = \begin{bmatrix}
        1 & 1 & 1 \\
        2 & 1 & -1 \\
        0 & -1 & 1 \\
    \end{bmatrix} \vec{\mathbf{x}}
$$


```python
_, p = system([
    [1, 1, 1],
    [2, 1, -1],
    [0, -1, 1]
])
p.display()
```


$\displaystyle \text{Characteristic equation: }$



$\displaystyle 3 \lambda - \left(\lambda - 1\right)^{3} - 5 = 0$



$\displaystyle \text{Eigenvalues and eigenvectors}$



$\displaystyle \lambda_1 = -1$



$\displaystyle \left[\begin{matrix}2 & 1 & 1 & 0\\2 & 2 & -1 & 0\\0 & -1 & 2 & 0\end{matrix}\right]\text{ ~ }\left[\begin{matrix}1 & 0 & \frac{3}{2} & 0\\0 & 1 & -2 & 0\\0 & 0 & 0 & 0\end{matrix}\right]\Rightarrow v = \left[\begin{matrix}- \frac{3}{2}\\2\\1\end{matrix}\right]$



$\displaystyle \lambda_2 = 2$



$\displaystyle \left[\begin{matrix}-1 & 1 & 1 & 0\\2 & -1 & -1 & 0\\0 & -1 & -1 & 0\end{matrix}\right]\text{ ~ }\left[\begin{matrix}1 & 0 & 0 & 0\\0 & 1 & 1 & 0\\0 & 0 & 0 & 0\end{matrix}\right]\Rightarrow v = \left[\begin{matrix}0\\-1\\1\end{matrix}\right]$



$\displaystyle \text{Find the generalized eigenvector}\left( M - \lambda I \right) w = v $



$\displaystyle \left[\begin{matrix}-1 & 1 & 1 & 0\\2 & -1 & -1 & -1\\0 & -1 & -1 & 1\end{matrix}\right]\text{ ~ }\left[\begin{matrix}1 & 0 & 0 & -1\\0 & 1 & 1 & -1\\0 & 0 & 0 & 0\end{matrix}\right]\Rightarrow w = \left[\begin{matrix}-1\\-1\\0\end{matrix}\right]$



$\displaystyle \text{General solution: }$



$\displaystyle \vec{\mathbf{x}} = C_{1}e^{- t}\left[\begin{matrix}- \frac{3}{2}\\2\\1\end{matrix}\right]+C_{2}e^{2 t}\left[\begin{matrix}0\\-1\\1\end{matrix}\right]+C_{3}e^{2 t}\left(\left[\begin{matrix}0\\-1\\1\end{matrix}\right]t + \left[\begin{matrix}-1\\-1\\0\end{matrix}\right]\right)$



```python
_, p = system([
    [3, -2],
    [4, -1]
])
p.display()
```


$\displaystyle \text{Characteristic equation: }$



$\displaystyle \left(\lambda - 3\right) \left(\lambda + 1\right) + 8 = 0$



$\displaystyle \text{Eigenvalues and eigenvectors}$



$\displaystyle \lambda_1 = 1 - 2*I$



$\displaystyle \left[\begin{matrix}2 + 2 i & -2 & 0\\4 & -2 + 2 i & 0\end{matrix}\right]\text{ ~ }\left[\begin{matrix}1 & - \frac{2 - 2 i}{4} & 0\\0 & 0 & 0\end{matrix}\right]\Rightarrow v = \left[\begin{matrix}\frac{2 - 2 i}{4}\\1\end{matrix}\right]$



$\displaystyle \text{Use Euler's formula to expand the imaginary part}$



$\displaystyle \left[\begin{matrix}\frac{2 - 2 i}{4}\\1\end{matrix}\right] e^{t - 2 i t} = e^{t} \left[\begin{matrix}\frac{1}{4} \left(2 - 2 i\right) \left(- i \sin{\left(2 t \right)} + \cos{\left(2 t \right)}\right)\\- i \sin{\left(2 t \right)} + \cos{\left(2 t \right)}\end{matrix}\right] = e^{t}\left( \left[\begin{matrix}- \frac{\sin{\left(2 t \right)}}{2} + \frac{\cos{\left(2 t \right)}}{2}\\\cos{\left(2 t \right)}\end{matrix}\right] + \left[\begin{matrix}- \frac{\sin{\left(2 t \right)}}{2} - \frac{\cos{\left(2 t \right)}}{2}\\- \sin{\left(2 t \right)}\end{matrix}\right]\right)$



$\displaystyle \text{General solution: }$



$\displaystyle \vec{\mathbf{x}} = e^{t}\left(C_{1}\left[\begin{matrix}- \frac{\sin{\left(2 t \right)}}{2} + \frac{\cos{\left(2 t \right)}}{2}\\\cos{\left(2 t \right)}\end{matrix}\right] + C_{2}\left[\begin{matrix}- \frac{\sin{\left(2 t \right)}}{2} - \frac{\cos{\left(2 t \right)}}{2}\\- \sin{\left(2 t \right)}\end{matrix}\right]\right)$


Find the solution and draw the phase portrait for the following system of ode
$$
    \vec{\mathbf{x'}} = \begin{bmatrix}
        2 & -5 \\
        1 & -2 \\
    \end{bmatrix} \vec{\mathbf{x}}
$$


```python
_, p = system([
    [2, -5],
    [1, -2]
])
p.display()

%matplotlib inline
phase_portrait([
        [2, -5],
        [1, -2]
    ],
    -4, 4, -4, 4, 15, "stream"
)
```


```python

```

c18e734e5ad85d5188e368922f4bb60d61eaa29d
ipynb
Jupyter Notebook
notebooks/system-of-ode.ipynb
kaiyingshan/ode-solver
30c6798efe9c35a088b2c6043493470701641042
MIT
2019-02-17T23:15:20.000Z
2019-02-17T23:15:27.000Z
notebooks/system-of-ode.ipynb
kaiyingshan/ode-solver
30c6798efe9c35a088b2c6043493470701641042
MIT
notebooks/system-of-ode.ipynb
kaiyingshan/ode-solver
30c6798efe9c35a088b2c6043493470701641042
MIT
Qwen/Qwen-72B
1. YES
2. YES