Module 1.3
Almost every real-world dynamical system involves multiple interacting quantities: voltages and currents in a circuit, concentrations of reactants in a chemical network, positions and velocities of coupled masses. A single scalar ODE cannot capture these interactions. By writing the governing equations as a system \(\mathbf{x}' = A\mathbf{x}\), we unlock the full power of linear algebra — eigenvalues reveal natural modes, eigenvectors define invariant directions, and the matrix exponential gives a closed-form solution in one stroke. Phase portraits then let us see qualitative behaviour without solving a single equation: nodes, saddles, spirals, and centers emerge directly from the spectrum of \(A\). In reinforcement learning and control, the same eigenvalue structure determines whether a policy converges, oscillates, or diverges — making this module a direct bridge between classical mathematics and modern AI.
By the end of this module you will be able to:
A first-order linear system is a set of \(n\) coupled equations
$$ \mathbf{x}'(t) = A(t)\,\mathbf{x}(t) + \mathbf{g}(t), \qquad \mathbf{x}(t)\in\mathbb{R}^n, $$where \(A(t)\) is an \(n\times n\) matrix-valued function and \(\mathbf{g}(t)\) is a vector-valued forcing. When \(A\) is constant and \(\mathbf{g}=\mathbf{0}\) we write \(\mathbf{x}'=A\mathbf{x}\) and call the system autonomous and homogeneous.
A matrix \(\Phi(t)\in\mathbb{R}^{n\times n}\) whose columns are \(n\) linearly independent solutions of \(\mathbf{x}'=A\mathbf{x}\) is called a fundamental matrix. It satisfies \(\Phi'(t)=A\,\Phi(t)\). If additionally \(\Phi(0)=I\), then \(\Phi(t)=e^{At}\).
The matrix exponential of \(A\in\mathbb{R}^{n\times n}\) is defined by the convergent power series
$$ e^{At} = \sum_{k=0}^{\infty} \frac{(At)^k}{k!} = I + At + \frac{A^2 t^2}{2!} + \cdots $$It gives the unique solution \(\mathbf{x}(t)=e^{At}\mathbf{x}_0\) to the initial-value problem \(\mathbf{x}'=A\mathbf{x},\;\mathbf{x}(0)=\mathbf{x}_0\).
The phase portrait of \(\mathbf{x}'=A\mathbf{x}\) in \(\mathbb{R}^2\) is the family of solution curves (trajectories) plotted in the \((x_1,x_2)\)-plane, together with the direction field. The origin is the unique equilibrium point when \(\det A\neq 0\).
The equilibrium \(\mathbf{x}^*=\mathbf{0}\) of \(\mathbf{x}'=A\mathbf{x}\) is:
In a coupled spring–mass system with mass matrix \(M\) and stiffness matrix \(K\), the normal modes are the eigenvectors of \(M^{-1}K\), and the corresponding natural frequencies are \(\omega_k = \sqrt{\lambda_k}\), where \(\lambda_k\) are the eigenvalues of \(M^{-1}K\).
Let \(A\in\mathbb{R}^{2\times 2}\) with eigenvalues \(\lambda_1,\lambda_2\). Then the phase portrait of \(\mathbf{x}'=A\mathbf{x}\) at the origin is classified as follows:
The origin is asymptotically stable if and only if \(\operatorname{Re}(\lambda_j)<0\) for all \(j\); it is stable (but not asymptotically) if all eigenvalues have \(\operatorname{Re}(\lambda_j)\leq 0\) and every eigenvalue with zero real part is simple.
Let \(\mathbf{x}'=\mathbf{f}(\mathbf{x})\) be a nonlinear autonomous system with a hyperbolic equilibrium at \(\mathbf{x}^*\) (i.e., the Jacobian \(D\mathbf{f}(\mathbf{x}^*)\) has no eigenvalue with zero real part). Then in a neighbourhood of \(\mathbf{x}^*\), the nonlinear flow is topologically conjugate to the linearised flow \(\mathbf{y}'=D\mathbf{f}(\mathbf{x}^*)\,\mathbf{y}\). In other words, the qualitative phase portrait of the linearisation correctly predicts the local behaviour of the nonlinear system near a hyperbolic equilibrium.
Correction: Purely imaginary eigenvalues yield a center, where trajectories are closed orbits and the origin is stable but not asymptotically stable. Asymptotic stability requires all eigenvalues to have strictly negative real parts.
Correction: The matrix exponential is defined by the power series \(\sum (At)^k/k!\). Entry-wise exponentiation gives a completely different (and generally wrong) result. The correct computation requires diagonalisation or the Cayley–Hamilton theorem.
Correction: A saddle has eigenvalues of opposite sign, so there is always an unstable manifold along which trajectories escape to infinity. The saddle is therefore always unstable, regardless of initial conditions.
Correction: Replacing \(A\) by \(cA\) (\(c>0\)) scales all eigenvalues by \(c\), which changes the speed of trajectories but preserves their geometric shape and classification. The topology of the phase portrait is invariant under positive scaling.
Correction: Repeated eigenvalues produce a star node (proper node) only when the eigenspace is two-dimensional, i.e., \(A = \lambda I\). If the geometric multiplicity is one (defective case), the portrait is an improper node (degenerate node) with a single eigenvector direction, and the general solution involves a generalised eigenvector and a \(te^{\lambda t}\) term.
Problem. Solve the system
$$ \mathbf{x}' = \begin{pmatrix} 1 & 3 \\ 1 & -1 \end{pmatrix}\mathbf{x}, \qquad \mathbf{x}(0) = \begin{pmatrix} 4 \\ 0 \end{pmatrix}. $$Step 1 — Find eigenvalues. The characteristic polynomial is
$$ \det(A - \lambda I) = (1-\lambda)(-1-\lambda) - 3 = \lambda^2 - 4 = 0, $$so \(\lambda_1 = 2\) and \(\lambda_2 = -2\). Since these are real and of opposite sign, the origin is a saddle point.
Step 2 — Find eigenvectors.
Step 3 — General solution.
$$ \mathbf{x}(t) = c_1 e^{2t}\begin{pmatrix} 3 \\ 1 \end{pmatrix} + c_2 e^{-2t}\begin{pmatrix} 1 \\ -1 \end{pmatrix}. $$Step 4 — Apply initial condition. At \(t=0\):
$$ \begin{pmatrix} 4 \\ 0 \end{pmatrix} = c_1 \begin{pmatrix} 3 \\ 1 \end{pmatrix} + c_2 \begin{pmatrix} 1 \\ -1 \end{pmatrix}. $$Solving: \(3c_1 + c_2 = 4\), \(c_1 - c_2 = 0\), so \(c_1 = c_2 = 1\).
Solution:
$$ \mathbf{x}(t) = e^{2t}\begin{pmatrix} 3 \\ 1 \end{pmatrix} + e^{-2t}\begin{pmatrix} 1 \\ -1 \end{pmatrix}. $$Problem. Classify the equilibrium and sketch the phase portrait for
$$ \mathbf{x}' = \begin{pmatrix} -1 & 2 \\ -2 & -1 \end{pmatrix}\mathbf{x}. $$Step 1 — Eigenvalues.
$$ \det(A - \lambda I) = (-1-\lambda)^2 + 4 = \lambda^2 + 2\lambda + 5 = 0 $$ $$ \lambda = \frac{-2 \pm \sqrt{4-20}}{2} = -1 \pm 2i. $$The eigenvalues are complex with \(\alpha = -1 < 0\) and \(\beta = 2\). By the Spectral Classification Theorem, the origin is a stable spiral.
Step 2 — Eigenvector for \(\lambda_1 = -1 + 2i\).
$$ (A - \lambda_1 I)\mathbf{v} = \begin{pmatrix} -2i & 2 \\ -2 & -2i \end{pmatrix}\mathbf{v} = 0. $$From the first row: \(-2iv_1 + 2v_2 = 0\), so \(v_2 = iv_1\). Taking \(v_1 = 1\): \(\mathbf{v} = \begin{pmatrix} 1 \\ i \end{pmatrix}\).
Step 3 — Real-valued solution. We write \(\mathbf{v} = \mathbf{a} + i\mathbf{b}\) where \(\mathbf{a} = \begin{pmatrix} 1 \\ 0 \end{pmatrix}\) and \(\mathbf{b} = \begin{pmatrix} 0 \\ 1 \end{pmatrix}\). The two real solutions are:
$$ \mathbf{x}_1(t) = e^{-t}\bigl(\cos 2t\,\mathbf{a} - \sin 2t\,\mathbf{b}\bigr) = e^{-t}\begin{pmatrix} \cos 2t \\ -\sin 2t \end{pmatrix}, $$ $$ \mathbf{x}_2(t) = e^{-t}\bigl(\sin 2t\,\mathbf{a} + \cos 2t\,\mathbf{b}\bigr) = e^{-t}\begin{pmatrix} \sin 2t \\ \cos 2t \end{pmatrix}. $$General solution:
$$ \mathbf{x}(t) = e^{-t}\begin{pmatrix} c_1\cos 2t + c_2\sin 2t \\ -c_1\sin 2t + c_2\cos 2t \end{pmatrix}. $$Trajectories spiral clockwise toward the origin, consistent with a stable spiral.
Problem. Compute \(e^{At}\) for \(A = \begin{pmatrix} 0 & 1 \\ -2 & -3 \end{pmatrix}\).
Step 1. Eigenvalues: \(\lambda^2 + 3\lambda + 2 = 0\), so \(\lambda_1 = -1\), \(\lambda_2 = -2\).
Step 2. Eigenvectors: \(\mathbf{v}_1 = \begin{pmatrix} 1 \\ -1 \end{pmatrix}\), \(\mathbf{v}_2 = \begin{pmatrix} 1 \\ -2 \end{pmatrix}\).
Step 3. Form \(P = \begin{pmatrix} 1 & 1 \\ -1 & -2 \end{pmatrix}\) and \(P^{-1} = \begin{pmatrix} 2 & 1 \\ -1 & -1 \end{pmatrix}\).
Step 4. Since \(A = P\,\text{diag}(-1,-2)\,P^{-1}\):
$$ e^{At} = P\begin{pmatrix} e^{-t} & 0 \\ 0 & e^{-2t} \end{pmatrix}P^{-1} = \begin{pmatrix} 2e^{-t} - e^{-2t} & e^{-t} - e^{-2t} \\ -2e^{-t} + 2e^{-2t} & -e^{-t} + 2e^{-2t} \end{pmatrix}. $$The code below computes eigenvalues of a \(2\times 2\) matrix \(A\) and plots the phase portrait with several trajectories. Modify \(A\) to explore different portrait types.
Paste into a Jupyter notebook or Python environment with NumPy and Matplotlib.
Exercises with the code:
Consider a reinforcement-learning agent whose state is a vector \(\mathbf{s} = (s_1, s_2) \in \mathbb{R}^2\). The environment dynamics are linear:
$$ \mathbf{s}_{t+1} = (I + \Delta t\, A)\,\mathbf{s}_t, $$which is simply the forward Euler discretisation of \(\mathbf{s}' = A\mathbf{s}\). The phase portrait is the agent's policy landscape: each point in state space has a prescribed direction of motion.
Key analogies:
Design insight: When tuning a linear controller \(\mathbf{u} = K\mathbf{s}\), the closed-loop matrix becomes \(A + BK\). The eigenvalue placement problem — choosing \(K\) so that all eigenvalues of \(A+BK\) have negative real part — is equivalent to designing a policy that guarantees convergence to the target state. This is the foundation of Linear Quadratic Regulator (LQR) design, a cornerstone of optimal control and model-based RL.
Exercise 1. Find the general solution of \(\mathbf{x}' = \begin{pmatrix} 3 & -2 \\ 2 & -2 \end{pmatrix}\mathbf{x}\). Classify the equilibrium at the origin.
Characteristic polynomial: \(\lambda^2 - \lambda - 2 = 0\), so \(\lambda_1 = 2\), \(\lambda_2 = -1\). Opposite signs — saddle point.
Eigenvectors: \(\lambda_1=2\): \(\mathbf{v}_1 = \begin{pmatrix} 2 \\ 1 \end{pmatrix}\); \(\lambda_2=-1\): \(\mathbf{v}_2 = \begin{pmatrix} 1 \\ 2 \end{pmatrix}\).
$$ \mathbf{x}(t) = c_1 e^{2t}\begin{pmatrix} 2 \\ 1 \end{pmatrix} + c_2 e^{-t}\begin{pmatrix} 1 \\ 2 \end{pmatrix}. $$Exercise 2. For the system \(\mathbf{x}' = \begin{pmatrix} 0 & 1 \\ -4 & 0 \end{pmatrix}\mathbf{x}\), find the eigenvalues, write the general solution in real form, and describe the phase portrait.
\(\lambda^2 + 4 = 0\), so \(\lambda = \pm 2i\). Purely imaginary — the origin is a center.
$$ \mathbf{x}(t) = c_1 \begin{pmatrix} \cos 2t \\ -2\sin 2t \end{pmatrix} + c_2 \begin{pmatrix} \sin 2t \\ 2\cos 2t \end{pmatrix}. $$Trajectories are closed ellipses centred at the origin. The system is stable but not asymptotically stable.
Exercise 3. Compute the matrix exponential \(e^{At}\) for \(A = \begin{pmatrix} -2 & 1 \\ 0 & -2 \end{pmatrix}\) (a defective matrix with a repeated eigenvalue \(\lambda = -2\)).
Since \(A = -2I + N\) where \(N = \begin{pmatrix} 0 & 1 \\ 0 & 0 \end{pmatrix}\) is nilpotent (\(N^2 = 0\)), we have:
$$ e^{At} = e^{-2t}\,e^{Nt} = e^{-2t}(I + Nt) = e^{-2t}\begin{pmatrix} 1 & t \\ 0 & 1 \end{pmatrix}. $$Exercise 4. A \(3\times 3\) system has coefficient matrix \(A = \begin{pmatrix} 0 & 1 & 0 \\ 0 & 0 & 1 \\ -6 & -11 & -6 \end{pmatrix}\). Find the eigenvalues and write the general solution.
Exercise 5. Write a Python function that takes a \(2\times 2\) matrix \(A\) and returns a string classifying the equilibrium (node, saddle, spiral, or center, along with stability). Test it on at least four different matrices.
import numpy as np
def classify_equilibrium(A):
eigs = np.linalg.eigvals(A)
re = eigs.real
im = eigs.imag
if np.allclose(im, 0):
if np.all(re < 0):
return "Stable Node"
elif np.all(re > 0):
return "Unstable Node"
elif re[0] * re[1] < 0:
return "Saddle Point"
else:
return "Degenerate Node"
else:
alpha = re[0]
if alpha < -1e-10:
return "Stable Spiral"
elif alpha > 1e-10:
return "Unstable Spiral"
else:
return "Center"
# Tests
tests = [
np.array([[-1, 0], [0, -2]]), # Stable Node
np.array([[1, 3], [1, -1]]), # Saddle
np.array([[-1, 2], [-2, -1]]), # Stable Spiral
np.array([[0, 1], [-1, 0]]), # Center
]
for M in tests:
print(M, "->", classify_equilibrium(M))
Exercise 6. Using scipy.linalg.expm, compute \(e^{At}\) for \(A = \begin{pmatrix} 0 & 1 \\ -2 & -3 \end{pmatrix}\) at \(t = 0, 0.5, 1, 2\) and verify against the closed-form expression from Worked Example 3.
import numpy as np
from scipy.linalg import expm
A = np.array([[0, 1], [-2, -3]])
def exact_expm(t):
return np.array([
[2*np.exp(-t) - np.exp(-2*t), np.exp(-t) - np.exp(-2*t)],
[-2*np.exp(-t) + 2*np.exp(-2*t), -np.exp(-t) + 2*np.exp(-2*t)]
])
for t in [0, 0.5, 1.0, 2.0]:
numerical = expm(A * t)
analytical = exact_expm(t)
error = np.max(np.abs(numerical - analytical))
print(f"t={t:.1f}, max error = {error:.2e}")
Exercise 7. Model a two-mass, three-spring system with masses \(m_1=m_2=1\) and spring constants \(k_1=k_2=k_3=1\). Write the system as \(\mathbf{x}'=A\mathbf{x}\) with \(\mathbf{x}=(x_1,x_1',x_2,x_2')^T\), compute the natural frequencies, and plot the two normal-mode motions.
Exercise 8. Generate phase portraits for the one-parameter family \(A(\mu) = \begin{pmatrix} \mu & -1 \\ 1 & \mu \end{pmatrix}\) for \(\mu = -1, -0.5, 0, 0.5, 1\). Describe the bifurcation that occurs at \(\mu = 0\).
Eigenvalues: \(\lambda = \mu \pm i\). For \(\mu < 0\): stable spiral. At \(\mu = 0\): center. For \(\mu > 0\): unstable spiral. This is a Hopf bifurcation: the equilibrium transitions from asymptotically stable to unstable as \(\mu\) crosses zero, and in nonlinear systems a limit cycle typically emerges.
Exercise 9 (Agentic). Consider an agent in a 2D environment with linear dynamics \(\mathbf{s}' = A\mathbf{s} + B\mathbf{u}\), where \(A = \begin{pmatrix} 0 & 1 \\ 2 & 0 \end{pmatrix}\), \(B = \begin{pmatrix} 0 \\ 1 \end{pmatrix}\), and the agent's policy is \(\mathbf{u} = K\mathbf{s}\) with \(K = (k_1, k_2)\). Find the values of \(k_1, k_2\) such that the closed-loop matrix \(A + BK\) has eigenvalues at \(-1\) and \(-2\). Verify by plotting the closed-loop phase portrait.
Closed-loop: \(A + BK = \begin{pmatrix} 0 & 1 \\ 2+k_1 & k_2 \end{pmatrix}\). We need \(\text{tr} = k_2 = -3\) and \(\det = -(2+k_1) = 2\), so \(k_1 = -4\), \(k_2 = -3\). The gain is \(K = (-4, -3)\).
Exercise 10 (Agentic). An agent observes the state of a coupled spring–mass system and must predict whether the system will return to rest (asymptotically stable) or oscillate forever (center). Design a simple classifier that takes the \(4\times 4\) state matrix \(A\) as input, computes eigenvalues, and outputs "converges" or "oscillates." Implement it in Python and test on three different spring configurations with varying damping coefficients.
Q1. The eigenvalues of a \(2\times 2\) matrix are \(\lambda = -3 \pm 4i\). The origin is:
(a) An unstable spiral (b) A stable spiral (c) A center (d) A saddle
Answer: (b)
Q2. If both eigenvalues of \(A\) are real and negative, trajectories approach the origin along:
(a) Spirals (b) Straight lines parallel to eigenvectors (c) Circles (d) Hyperbolas
Answer: (b)
Q3. A saddle point has eigenvalues \(\lambda_1 = 3\), \(\lambda_2 = -1\). The stable manifold is tangent to:
(a) The eigenvector for \(\lambda_1 = 3\) (b) The eigenvector for \(\lambda_2 = -1\) (c) Neither (d) Both
Answer: (b)
Q4. Which of the following is true about the matrix exponential?
(a) \(e^{A+B} = e^A e^B\) always (b) \(e^{A+B} = e^A e^B\) iff \(AB = BA\) (c) \(e^{At}\) is always symmetric (d) \(e^{At}\) can be singular
Answer: (b)
Q5. The Hartman–Grobman theorem applies when the equilibrium is:
(a) Any equilibrium (b) Hyperbolic (no eigenvalues on imaginary axis) (c) A center (d) Asymptotically stable only
Answer: (b)
Q6. A \(2\times 2\) system has \(\text{tr}(A) = 0\) and \(\det(A) > 0\). The origin is:
(a) A saddle (b) An unstable node (c) A center (d) A stable spiral
Answer: (c). Eigenvalues: \(\lambda = \pm\sqrt{-\det A}\,i\), purely imaginary.
Q7. For the defective matrix \(A = \begin{pmatrix} 2 & 1 \\ 0 & 2 \end{pmatrix}\), the solution \(\mathbf{x}(t)\) involves:
(a) Only \(e^{2t}\) terms (b) \(e^{2t}\) and \(te^{2t}\) terms (c) \(\sin\) and \(\cos\) terms (d) Polynomial terms only
Answer: (b)
Q8. In a coupled mass-spring system with no damping, the eigenvalues of the state matrix are:
(a) All real and negative (b) All real and positive (c) Purely imaginary (d) Complex with negative real part
Answer: (c)
Q9. If \(\mathbf{x}' = A\mathbf{x}\) has the solution \(\mathbf{x}(t) = e^{At}\mathbf{x}_0\), then \(e^{A \cdot 0}\) equals:
(a) \(A\) (b) \(0\) (c) \(I\) (d) \(A^{-1}\)
Answer: (c)
Q10. An agent with linear dynamics \(\mathbf{s}' = (A+BK)\mathbf{s}\) will converge to the goal state if and only if:
(a) \(A+BK\) is invertible (b) All eigenvalues of \(A+BK\) have negative real part (c) \(K = -A\) (d) \(\det(A+BK) > 0\)
Answer: (b)
Task: Build a Python program (or Jupyter notebook) that does the following:
| Criterion | Excellent (5) | Good (3–4) | Needs Work (1–2) |
|---|---|---|---|
| Eigenvalue computation & classification | Correct for all cases (real, complex, repeated); clear output | Correct for most cases; minor labelling issues | Errors in eigenvalue computation or classification |
| Phase portrait quality | Clear trajectories, direction field, eigenvector lines; correct orientation | Trajectories plotted but missing direction field or eigenvectors | Incorrect or unreadable portrait |
| Matrix exponential | Correct computation; verified against analytical formula | Correct numerical result without verification | Missing or incorrect |
| Bifurcation exploration | Smooth animation or clear multi-panel figure; bifurcation correctly identified | Static plots for a few parameter values | No parameterisation attempted |
| Code quality & documentation | Clean, well-commented, modular code; README or docstrings | Working code with some comments | Disorganised or undocumented code |