import numpy as np
import numpy.linalg as la
import matplotlib.pyplot as plt
A = np.array([[0.2, -1], [0.9, 0.3]])
A
eigenvalues, eigenvectors = la.eig(A)
eigenvalues
Let's make a time variable:
t = np.linspace(0, 10, 1000)
And compute a solution for each eigenvalue/eigenvector pair as sol1
and sol2
, where each is a $1000\times 2$ array (time steps $\times$ number of species):
sol1 = np.exp(eigenvalues[0] * t.reshape(-1, 1)) * eigenvectors[:, 0]
sol2 = np.exp(eigenvalues[1] * t.reshape(-1, 1)) * eigenvectors[:, 1]
And plot the time behavior of the solution for both eigenvalue/eigenvector pairs:
plt.plot(t, sol1[:, 0].imag, label="birds")
plt.plot(t, sol1[:, 1].imag, label="foxes")
plt.legend()
plt.plot(t, sol2[:, 0].imag, label="birds")
plt.plot(t, sol2[:, 1].imag, label="foxes")
plt.legend()