import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import odeint
%matplotlib inline
A = np.array([[2, 3],
[1, 4]])
x_ = np.linspace(-3, 3, 20)
y_ = np.linspace(-3, 3, 20)
x, y = np.meshgrid(x_, y_)
plt.quiver(x, y, A[0, 0] * x + A[0, 1] * y,
A[1, 0] * x + A[1, 1] * y)
<matplotlib.quiver.Quiver at 0x7fba2c234cc0>
def plot_linear_system(A):
x_ = np.linspace(-3, 3, 300)
y_ = np.linspace(-3, 3, 300)
x, y = np.meshgrid(x_, y_)
plt.streamplot(x, y, A[0, 0] * x + A[0, 1] * y,
A[1, 0] * x + A[1, 1] * y)
eigvalues, eigvectors = np.linalg.eig(A)
plt.plot([0], [0], 'o')
plt.plot([0, eigvectors[0, 0]],
[0, eigvectors[1, 0]], '-o',
label=f'$\\lambda={eigvalues[0]:0.3f}$')
plt.plot([0, eigvectors[0, 1]],
[0, eigvectors[1, 1]], '-o',
label=f'$\\mu={eigvalues[1]:0.3f}$')
plt.legend()
np.linalg.eig(A)
(array([1., 5.]), array([[-0.9486833 , -0.70710678], [ 0.31622777, -0.70710678]]))
np.linalg.eig(np.array([[3, 8],
[4, 1]]))
(array([ 7.74456265, -3.74456265]), array([[ 0.86011126, -0.76454754], [ 0.51010647, 0.64456735]]))
plot_linear_system(np.array([[3, 8],
[4, 1]]))
plot_linear_system(np.array([[7.745, 0],
[0, -3.745]]))
plot_linear_system(np.array([[0, 0],
[0, 1]]))
plot_linear_system(np.array([[1, 2],
[2, 4]]))
plot_linear_system(np.array([[1, 1],
[0, 1]]))