```python
from sympy import *
init_printing()
import numpy as np
%matplotlib widget
import matplotlib as mpl
import matplotlib.pyplot as plt
import ipywidgets as widgets
```

# Phase portraits of planar linear ODEs

## Saddle point
First, let us look at the phase portrait of a saddle point $\dot x=x$, $\dot y=-\lambda y$.


```python
fig, ax = plt.subplots()

Y, X = np.mgrid[-5:5:100j, -5:5:100j]

@widgets.interact(λ=(0.1, 2.0))
def saddle(λ=1):
    ax.clear()
    U, V = X, -λ*Y
    ax.streamplot(X, Y, U, V)
```


    Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous …



    interactive(children=(FloatSlider(value=1.0, description='λ', max=2.0, min=0.1), Output()), _dom_classes=('wid…


More generally, any linear ODE with one positive and one negative eigenvalue defines a saddle point.


```python
fig, ax = plt.subplots()

Y, X = np.mgrid[-5:5:100j, -5:5:100j]

@widgets.interact(b=(0.6, 3.0))
def saddle(b=1):
    ax.clear()
    A = np.array([[1, b], [2, 1]])
    λ, v = np.linalg.eig(A)
    U = X + b * Y
    V = 2 * X + Y
    ax.streamplot(X, Y, U, V)
    for i in (0, 1):
        for s in (-3, 3):
            ax.arrow(0, 0, s * v[0,i], s * v[1, i])
```


    Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous …



    interactive(children=(FloatSlider(value=1.0, description='b', max=3.0, min=0.6), Output()), _dom_classes=('wid…


## Node


```python
fig, ax = plt.subplots()

Y, X = np.mgrid[-5:5:1000j, -5:5:1000j]

@widgets.interact(λ=(0.1, 2.0))
def unstable_node(λ=1):
    ax.clear()
    U, V = X, λ*Y
    ax.streamplot(X, Y, U, V)
```


    Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous …



    interactive(children=(FloatSlider(value=1.0, description='λ', max=2.0, min=0.1), Output()), _dom_classes=('wid…


## Center


```python
fig, ax = plt.subplots()

Y, X = np.mgrid[-5:5:1000j, -5:5:1000j]

@widgets.interact(b=(0.1, 2.0))
def unstable_node(b=1):
    ax.clear()
    U, V = -Y, b ** 2 * X
    ax.streamplot(X, Y, U, V)
```


    Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous …



    interactive(children=(FloatSlider(value=1.0, description='b', max=2.0, min=0.1), Output()), _dom_classes=('wid…


## Focus


```python
fig, ax = plt.subplots()

Y, X = np.mgrid[-5:5:1000j, -5:5:1000j]

@widgets.interact(a=(0.1, 2.0))
def unstable_node(a=1):
    ax.clear()
    U, V = a * X -Y, X + a * Y
    ax.streamplot(X, Y, U, V)
```


    Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous …



    interactive(children=(FloatSlider(value=1.0, description='a', max=2.0, min=0.1), Output()), _dom_classes=('wid…


## Jordan cell


```python
fig, ax = plt.subplots()

Y, X = np.mgrid[-5:5:1000j, -5:5:1000j]
U, V = X + Y, Y
ax.streamplot(X, Y, U, V)
```


    Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous …





    <matplotlib.streamplot.StreamplotSet at 0x7fa312e2d730>



## General linear ODE

The interactive widget in the next cell allows user to create any linear ODE.


```python
fig, ax = plt.subplots()

Y, X = np.mgrid[-5:5:1000j, -5:5:1000j]

@widgets.interact(a=widgets.IntText(value=1), b=widgets.IntText(value=2), c=widgets.IntText(value=2), d=widgets.IntText(value=1))
def unstable_node(a, b, c, d):
    ax.clear()
    U, V = a * X + b * Y, c * X + d * Y
    ax.streamplot(X, Y, U, V)
```


    Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous …



    interactive(children=(IntText(value=1, description='a'), IntText(value=2, description='b'), IntText(value=2, d…


fac82048f7edd45f24586083a5a41378ddf7e024
ipynb
Jupyter Notebook
Linear_ODEs_phase_portraits.ipynb
urkud/mat332-notebooks
c334255e246bdde22b6c905b38b714b92f74c8d6
MIT
Linear_ODEs_phase_portraits.ipynb
urkud/mat332-notebooks
c334255e246bdde22b6c905b38b714b92f74c8d6
MIT
Linear_ODEs_phase_portraits.ipynb
urkud/mat332-notebooks
c334255e246bdde22b6c905b38b714b92f74c8d6
MIT
2020-12-29T22:25:25.000Z
2020-12-29T22:25:25.000Z
Qwen/Qwen-72B
1. YES
2. YES