Dynamical Systems and the Matrix Exponential

Continuing the constant-coefficient and diagonalization notebooks

So far, our differential equations have had a single unknown function. In many models, though, several quantities change at once, and the rate of change of each one depends on the others: predators and prey, the angle and angular velocity of a pendulum, the currents in a circuit. These are systems of differential equations, also known as \textbf{dynamical systems}. In this notebook we look at them in two ways: geometrically, as curves following a vector field, and algebraically, through the \textbf{matrix exponential}, which ties them back to the linear algebra we have seen.
Background: parametric curves
A \textbf{parametric curve} is a pair of functions $x(t)$ and $y(t)$, which we bundle into a single vector-valued function $$\mathbf{x}(t) = \begin{bmatrix} x(t) \\ y(t) \end{bmatrix}.$$ It is best to think of $t$ as time and $\mathbf{x}(t)$ as the position of a particle in the plane, which traces out a curve as $t$ runs. Differentiating each component gives the \textbf{velocity} $$\mathbf{x}'(t) = \begin{bmatrix} x'(t) \\ y'(t) \end{bmatrix},$$ which points in the direction of motion and is tangent to the curve at $\mathbf{x}(t)$. Its length $\|\mathbf{x}'(t)\|$ is the speed. Note that a parametric curve is more than the shape it traces. The curves $(2\cos t, \sin t)$ and $(2\cos 2t, \sin 2t)$ both trace the ellipse $\frac{x^2}{4} + y^2 = 1$, but the second one goes around twice as fast. Compare their velocity arrows below: the arrow always has the same length, and its shade shows the speed, so the faster curve's arrow is darker. For differential equations this matters, since a solution has to be in the right place at the right time.
Curve

Time \(t\)0

Figure 1. A parametric curve and its velocity.

Computation

Systems of differential equations

Typically the independent variable is $t$ (as it usually models time) and the unknown functions are $x(t), y(t), \dots$ (or $x_1(t), x_2(t), \dots$). A first-order, two-dimensional \textbf{dynamical system} (DS) with \textbf{initial conditions} (IC) has the form $$\text{DS: } \begin{cases} x' = f_1(t, x, y) \\ y' = f_2(t, x, y) \end{cases} \qquad \text{IC: } \begin{cases} x(0) = x_0 \\ y(0) = y_0 \end{cases}$$ and together they form an initial value problem, DS $+$ IC $=$ IVP. A solution is a pair of functions $(x(t), y(t))$, i.e. a parametric curve, that satisfies both equations for all $t$ and passes through $(x_0, y_0)$ at $t = 0$. The system is \textbf{autonomous} if $f_1$ and $f_2$ do not depend on $t$. We will mostly look at the \textbf{linear, homogeneous, constant-coefficient} case $$x' = ax + by, \qquad y' = cx + dy,$$ which is autonomous as well. \begin{example} Consider $x' = -2y$ and $y' = \tfrac{1}{2}x$, with $x(0) = 2$ and $y(0) = 0$. The two unknowns are tangled together, but we can untangle them by differentiating the first equation and substituting the second: $x'' = -2y' = -x$. So $x'' + x = 0$, whose characteristic polynomial $r^2 + 1$ has roots $\pm i$, and $x(t) = C_1\cos t + C_2\sin t$. The first equation then gives $y = -\tfrac{1}{2}x' = \tfrac{C_1}{2}\sin t - \tfrac{C_2}{2}\cos t$, and the initial conditions force $C_1 = 2$ and $C_2 = 0$. Thus, $$x(t) = 2\cos t, \qquad y(t) = \sin t,$$ which is exactly the ellipse from the background above! \end{example} The same trick works in general. Differentiating $x' = ax + by$, substituting $y' = cx + dy$, and then using $by = x' - ax$ to remove $y$ altogether gives $$x'' - (a + d)x' + (ad - bc)x = 0,$$ a constant-coefficient equation we already know how to solve. Then $y = \tfrac{1}{b}\left(x' - ax\right)$ when $b \neq 0$, and the initial conditions pin down the constants. (If $b = 0$, the first equation is just $x' = ax$, so $x(t) = x_0e^{at}$, and the second can be solved with an integrating factor.) \begin{remark} The numbers $a + d$ and $ad - bc$ should look familiar. Writing the system as $\mathbf{x}' = A\mathbf{x}$, with the \textbf{matrix of the dynamical system} $$\begin{bmatrix} x' \\ y' \end{bmatrix} = \begin{bmatrix} a & b \\ c & d \end{bmatrix}\begin{bmatrix} x \\ y \end{bmatrix}, \qquad A = \begin{bmatrix} a & b \\ c & d \end{bmatrix},$$ they are the trace and determinant of $A$, and the equation reads $x'' - \tr(A)x' + \det(A)x = 0$. Notably, its characteristic polynomial $r^2 - \tr(A)r + \det(A)$ is exactly $\det(A - rI)$, so its roots are the eigenvalues of $A$. This is our first hint that linear algebra is running the show. \end{remark}

Vector fields and flow lines

For an autonomous system $x' = f_1(x, y)$, $y' = f_2(x, y)$, we can read the right-hand side as a \textbf{vector field} $$\mathbf{F}(x, y) = \begin{bmatrix} f_1(x, y) \\ f_2(x, y) \end{bmatrix},$$ which attaches to each point $(x, y)$ an arrow $\mathbf{F}(x, y)$, with its tail at that point. The system then says $$\mathbf{x}'(t) = \mathbf{F}(\mathbf{x}(t)).$$ That is, a solution is a parametric curve whose velocity at every point is given by the vector field at that point. Such a curve is called a \textbf{flow line} of $\mathbf{F}$. In a sense, the vector field is a current, and the solution is something floating along in it, set down at the initial condition at time $t = 0$. In the figure below, the arrows show the direction of $\mathbf{F}$, colored by length (blue is slow, red is fast). The green curve is the flow line through the black initial condition, which you can drag. Move the time slider to watch the point $\mathbf{x}(t)$ ride along the flow line, with its velocity $\mathbf{x}'(t) = \mathbf{F}(\mathbf{x}(t))$ always tangent to it (the velocity arrow is shortened when it gets long).
System

Time \(t\)0
Drag the black point to change the initial condition.

Figure 2. A vector field and one of its flow lines.

Computation
The first five systems are the linear examples from Lectures 36 and 37, and for each, the \emph{Computation} dropdown gives the solution formula, which updates as you drag the initial condition. I invite you to play around with a few. In the \emph{Diagonalizable} example, try dragging the initial condition onto the line through $(2, 1)$ or through $(1, 1)$, the eigenvectors of $A$. The flow line never leaves that line (why?). The last system is a damped pendulum, where $x$ is the angle and $y$ the angular velocity. Because of the $\sin x$, it is not linear, and none of our methods give a formula for its solution. However, the picture still makes perfect sense, and we can still follow the arrows numerically, for instance with Euler's method, one small step at a time.

The matrix exponential

Solving by hand (differentiate, substitute, solve a second order equation, then fit the constants) works, but it is cumbersome, and only gets worse in higher dimensions. Recall that the scalar equation $x' = ax$ with $x(0) = x_0$ has the solution $x(t) = x_0e^{at}$. Is there a version of this for $\mathbf{x}' = A\mathbf{x}$? The answer is yes, and the trick is to define the exponential through its Taylor series, $$e^x = 1 + x + \frac{1}{2!}x^2 + \frac{1}{3!}x^3 + \cdots = \sum_{k=0}^{\infty}\frac{1}{k!}x^k,$$ which only uses sums, scalar multiples, and powers, all of which make sense for square matrices. \begin{definition} Let $B$ be an $n \times n$ matrix. The \textbf{matrix exponential} of $B$ is the $n \times n$ matrix $$e^B = I_n + B + \frac{1}{2!}B^2 + \frac{1}{3!}B^3 + \cdots = \sum_{k=0}^{\infty}\frac{1}{k!}B^k.$$ \end{definition} One can show that this series always converges (each entry of $e^B$ is a convergent series), and plugging in the zero matrix gives $e^O = I_n$. \begin{theorem} For any $n \times n$ matrix $A$, the solution to the initial value problem $\mathbf{x}' = A\mathbf{x}$, $\mathbf{x}(0) = \mathbf{x}_0$ is $$\mathbf{x}(t) = e^{At}\mathbf{x}_0, \qquad \text{where} \qquad e^{At} = I_n + At + \frac{A^2t^2}{2!} + \frac{A^3t^3}{3!} + \cdots.$$ \end{theorem} \begin{proof} Differentiating the series term by term (treating $I_n, A, A^2, \dots$ as constants), $$\frac{d}{dt}e^{At} = A + A^2t + \frac{A^3t^2}{2!} + \cdots = A\left(I_n + At + \frac{A^2t^2}{2!} + \cdots\right) = Ae^{At}.$$ So $\mathbf{x}'(t) = Ae^{At}\mathbf{x}_0 = A\mathbf{x}(t)$, and $\mathbf{x}(0) = e^{O}\mathbf{x}_0 = \mathbf{x}_0$. (The solution is also unique, though we won't prove it.) \end{proof} This is a direct analogue of $x_0e^{at}$. All of the work is now in computing $e^{At}$, which can be challenging, but there are a few techniques when $A$ is nice. \begin{itemize} \item \textbf{Diagonal.} If $A = \diag(d_1, \dots, d_n)$, then $A^k = \diag(d_1^k, \dots, d_n^k)$, and summing the series along the diagonal gives $e^{At} = \diag(e^{d_1t}, \dots, e^{d_nt})$. \item \textbf{Commuting pieces.} If $BC = CB$, then $e^{B + C} = e^Be^C$, just like $e^{a + b} = e^ae^b$ (commuting is what lets us expand $(B + C)^k$ with the binomial theorem). A triangular $A$ with equal diagonal entries splits as a multiple of the identity plus a strictly triangular $C$, and these commute. Moreover, $C$ is \textbf{nilpotent}, so the series for $e^{Ct}$ stops after finitely many terms. \item \textbf{Diagonalizable.} Since $(SBS^{-1})^k = SB^kS^{-1}$, we get $e^{SBS^{-1}} = Se^BS^{-1}$. So if $A = SDS^{-1}$ (see the diagonalization notebook), then $e^{At} = Se^{Dt}S^{-1}$, two matrix products away from the easy diagonal case. \end{itemize} \begin{remark} The ellipse fits none of these (at least over the real numbers), but its series is easy to sum directly. For $$A = \begin{bmatrix} 0 & -2 \\ \tfrac{1}{2} & \phantom{-}0 \end{bmatrix}, \qquad A^2 = -I,$$ so the powers of $A$ cycle through $I, A, -I, -A, I, \dots$, and grouping the even and odd terms, $$e^{At} = \left(1 - \frac{t^2}{2!} + \frac{t^4}{4!} - \cdots\right)I + \left(t - \frac{t^3}{3!} + \cdots\right)A = I\cos t + A\sin t.$$ This is Euler's formula $e^{it} = \cos t + i\sin t$, with $A$ playing the role of $i$! Applying it to $\mathbf{x}_0 = (2, 0)$ recovers the ellipse once more. \end{remark} To see the definition at work, the figure below draws the partial sums $$S_N(t) = \sum_{k=0}^{N}\frac{t^k}{k!}A^k\mathbf{x}_0$$ in orange, against the true flow line in green. With $N = 0$ the partial sum is just the point $\mathbf{x}_0$, with $N = 1$ it is the tangent line $\mathbf{x}_0 + tA\mathbf{x}_0$, and each additional term bends it further toward the flow line. Notice that near $t = 0$ only a few terms are needed, while for larger $t$ the factor $t^k$ makes the later terms matter, and more of them are needed. For the \emph{Nilpotent} example, the sum is exact as soon as $N = 1$ (why?).
System

Partial sum \(N\)1
Time \(t\)0

Figure 3. Partial sums of \(e^{At}\mathbf{x}_0\).

Computation
\begin{remark} The first partial sum $$S_1(t) = \mathbf{x}_0 + tA\mathbf{x}_0$$ is exactly the line through $\mathbf{x}_0$ along the dark blue arrow, the velocity $\mathbf{x}'(0) = A\mathbf{x}_0$. In other words, $S_1$ pretends that the velocity never changes from its value at $t = 0$, which is precisely one step of Euler's method. The higher terms correct for the velocity changing as the solution moves along. \end{remark}
Stability
Every linear system $\mathbf{x}' = A\mathbf{x}$ has the constant solution $\mathbf{x}(t) = \mathbf{0}$: start at the origin, and you stay there forever. Such a solution is called an \textbf{equilibrium}. A ball resting at the bottom of a bowl and a ball balanced on top of a hill are both at equilibrium, but give them a nudge, and they behave very differently: the first rolls back, while the second rolls away. We call the origin \textbf{stable} if every solution tends to $\mathbf{0}$ as $t \to \infty$, and \textbf{unstable} if solutions starting arbitrarily close to it can run off. The eigenvalues of $A$ decide which. If $A\mathbf{v} = \lambda\mathbf{v}$, then $A^k\mathbf{v} = \lambda^k\mathbf{v}$, so the series for $e^{At}$ acts on $\mathbf{v}$ just like the series for $e^{\lambda t}$, and $e^{At}\mathbf{v} = e^{\lambda t}\mathbf{v}$. So if $A$ is diagonalizable, with eigenvalues $\lambda_1, \lambda_2$ and eigenvectors $\mathbf{v}_1, \mathbf{v}_2$, writing $\mathbf{x}_0 = c_1\mathbf{v}_1 + c_2\mathbf{v}_2$ gives $$\mathbf{x}(t) = c_1e^{\lambda_1t}\mathbf{v}_1 + c_2e^{\lambda_2t}\mathbf{v}_2.$$ Each piece shrinks along its eigenline if its eigenvalue is negative, and grows if it is positive. If both are negative, every solution comes in. If both are positive, every solution runs off. With one of each, we get a \textbf{saddle}: only the solutions starting on the stable eigenline come in, and every other one eventually runs off along the unstable one. The other cases follow the same idea. For complex eigenvalues $\lambda = \alpha \pm \beta i$, the solutions involve $e^{\alpha t}\cos\beta t$ and $e^{\alpha t}\sin\beta t$, so they rotate, and the factor $e^{\alpha t}$ makes them spiral in when $\alpha < 0$, spiral out when $\alpha > 0$, and close up into ellipses when $\alpha = 0$, as in our very first example. For a repeated eigenvalue $\lambda$ that is not diagonalizable, $A = \lambda I + N$ with $N$ nilpotent, and $e^{At} = e^{\lambda t}(I + tN)$. The extra factor of $t$ is no match for $e^{\lambda t}$, so the sign of $\lambda$ still decides. \begin{theorem} The origin is a stable equilibrium of $\mathbf{x}' = A\mathbf{x}$ exactly when every eigenvalue of $A$ has negative real part. \end{theorem} Pick an example in the figure below and drag the initial condition around. The dashed purple lines are the eigenlines, whenever the eigenvalues are real.

Time \(t\)0
Drag the black point to change the initial condition.

Figure 4. Stability of the origin.

Eigenvalues
The last option lets you choose the eigenvalues yourself. Try sliding $\beta$ down through $0$: the two real eigenvalues merge, and then split apart into a complex pair, and the eigenlines give way to a spiral. Then slide $\alpha$ through $0$, and watch the origin flip from stable to unstable.