---
title: The matrix exponential
heading: "One formula for every linear system: e^{At}"
eyebrow: A7 · Lesson 39 · The matrix exponential
xp: 40
---

::: hook
The scalar equation $x' = ax$ has the solution $x = e^{at}x_0$. The system $\mathbf{u}' = A\mathbf{u}$ has the same solution, $\mathbf{u} = e^{At}\mathbf{u}_0$, once you know what the exponential of a matrix means. Lesson 37 computed it from eigenvectors. Here it gets its own definition, a power series that works for every square matrix, defective ones included, and its properties: what it does to rotations and spirals, why $e^{A}e^{B}$ usually isn't $e^{A + B}$, and how simulators use it to step linear circuits exactly.
:::

::: play
- The curve is where $e^{At}$ carries the starting state $(1, 0)$, for $A = \begin{bmatrix}\sigma & -\omega\\\omega & \sigma\end{bmatrix}$. The dot is the state at time $t$.
- With $\sigma = 0$ the state goes round a circle: $e^{At}$ is a rotation by $\omega t$.
- Make $\sigma$ negative and the circle becomes a spiral inward, like a ringing LC tank with some resistance. The readouts give the distance from the origin, $e^{\sigma t}$, and the angle turned, $\omega t$.
:::

```sim plot
view: complex
range: 1.6
axes: u₁, u₂
slider: a = -0.5..0.1 step 0.05 = -0.2
slider: w = 0.5..3 step 0.1 = 1
slider: t = 0..10 step 0.1 = 2
curve: exp((a + j*w)*u) | over: u = 0..10 | label: e^(At)(1, 0)
dot: exp((a + j*w)*t) | label: at t
readout: distance from origin = exp(a*t) | digits: 4
readout: angle turned, rad = w*t | digits: 4
```

::: predict
## For $A = \begin{bmatrix}0 & -1\\1 & 0\end{bmatrix}$, what is $e^{A\pi}$?

- [ ] $\begin{bmatrix}e^{0} & e^{-\pi}\\e^{\pi} & e^{0}\end{bmatrix}$, the exponential of each entry
- [x] $-I$
- [ ] $I$
- [ ] It doesn't converge

::: reveal
$-I$. This $A$ generates rotation: $e^{At}$ rotates by $t$ radians, so $e^{A\pi}$ turns every vector halfway round, which is $-I$. It's the matrix version of $e^{j\pi} = -1$. The exponential of a matrix is never the exponential of its entries, except for diagonal matrices.
:::
:::

::: nameit
## The definition

$$e^{At} = I + At + \frac{(At)^2}{2!} + \frac{(At)^3}{3!} + \cdots$$

The series converges for every square matrix and every $t$, because $n!$ eventually beats any power. Differentiating term by term gives $\frac{d}{dt}e^{At} = Ae^{At}$, so $\mathbf{u}(t) = e^{At}\mathbf{u}_0$ solves $\mathbf{u}' = A\mathbf{u}$ with $\mathbf{u}(0) = \mathbf{u}_0$.

## Properties

- $e^{A(t + s)} = e^{At}e^{As}$ and $\left(e^{At}\right)^{-1} = e^{-At}$: it's never singular.
- $e^{A + B} = e^{A}e^{B}$ **only when $AB = BA$**.
- If $A = X\Lambda X^{-1}$, then $e^{At} = Xe^{\Lambda t}X^{-1}$, and $e^{\Lambda t}$ is diagonal with entries $e^{\lambda_it}$.
- If $N^k = 0$ (a **nilpotent** matrix), the series stops: $e^{Nt} = I + Nt + \cdots + \frac{(Nt)^{k-1}}{(k - 1)!}$.

## Spirals

For $A = \begin{bmatrix}\sigma & -\omega\\\omega & \sigma\end{bmatrix} = \sigma I + \omega R$, the parts commute, and $R$ (the 90° rotation) behaves like $j$:

$$e^{At} = e^{\sigma t}\begin{bmatrix}\cos\omega t & -\sin\omega t\\\sin\omega t & \cos\omega t\end{bmatrix}$$

Any real 2 × 2 matrix with eigenvalues $\sigma \pm j\omega$ is similar to this one, which is why a ringing circuit's state traces a spiral.

## Stepping exactly

For a linear circuit with a constant input $u$ over a time step $T$, $\mathbf{x}' = A\mathbf{x} + \mathbf{b}u$ gives exactly

$$\mathbf{x}_{k+1} = e^{AT}\mathbf{x}_k + A^{-1}\left(e^{AT} - I\right)\mathbf{b}u$$

with no truncation error, however large $T$ is. For an RC circuit, $A = -\frac1\tau$ and $b = \frac1\tau$, this is $x_{k+1} = e^{-T/\tau}x_k + (1 - e^{-T/\tau})u$. Ohmwork's own circuit simulator steps linear circuits this way.
:::

::: example
## Find $e^{At}$ for $A = \begin{bmatrix}0 & 1\\0 & 0\end{bmatrix}$, the matrix of $x' = v$, $v' = 0$.

::: solution
1. **Sum the series.** $A^2 = 0$, so the series stops after two terms:
   $$\begin{aligned} e^{At} &= I + At \\ &= \begin{bmatrix}1 & t\\0 & 1\end{bmatrix} \end{aligned}$$
2. **Apply it.** Applied to a starting position $x_0$ and velocity $v_0$, it gives $x = x_0 + v_0t$ and $v = v_0$: motion at constant velocity.
3. **Why eigenvectors won't do.** An eigenvector method would fail here, since $A$ has the eigenvalue 0 twice with only one eigenvector.

**Answer:** $e^{At} = \begin{bmatrix}1 & t\\0 & 1\end{bmatrix}$, motion at constant velocity.
:::
:::

::: example
## An LC tank's normalized state obeys $\mathbf{u}' = \begin{bmatrix}0 & -\omega\\\omega & 0\end{bmatrix}\mathbf{u}$ with $\omega$ = 1000 rad/s. Find $e^{At}$ at $t$ = 1 ms.

::: solution
1. **The angle.** $\omega t$ = 1 rad, and $e^{At}$ is the rotation by that angle:
   $$\begin{aligned} e^{At} &= \begin{bmatrix}\cos 1 & -\sin 1\\\sin 1 & \cos 1\end{bmatrix} \\ &= \begin{bmatrix}0.5403 & -0.8415\\0.8415 & 0.5403\end{bmatrix} \end{aligned}$$
2. **Apply it to $(1, 0)$.** Starting with all the energy in the capacitor, the state after 1 ms is $(0.540, 0.841)$.
3. **Energy check.**
   $$0.540^2 + 0.841^2 = 1$$
   so the energy is the same, now shared with the inductor.

**Answer:** $e^{At} = \begin{bmatrix}0.5403 & -0.8415\\0.8415 & 0.5403\end{bmatrix}$, a rotation by 1 rad.
:::
:::

::: example
## Take $A = \begin{bmatrix}0 & 1\\0 & 0\end{bmatrix}$ and $B = \begin{bmatrix}0 & 0\\1 & 0\end{bmatrix}$. Compare $e^Ae^B$ with $e^{A + B}$.

::: solution
1. **The two exponentials.** Both matrices are nilpotent, so
   $$\begin{aligned} e^A &= I + A \\ &= \begin{bmatrix}1 & 1\\0 & 1\end{bmatrix} \\ e^B &= I + B \\ &= \begin{bmatrix}1 & 0\\1 & 1\end{bmatrix} \end{aligned}$$
2. **Their product.**
   $$e^Ae^B = \begin{bmatrix}2 & 1\\1 & 1\end{bmatrix}$$
3. **The exponential of the sum.** $A + B = \begin{bmatrix}0 & 1\\1 & 0\end{bmatrix}$ has eigenvalues $\pm1$ with eigenvectors $(1, \pm1)$, giving
   $$\begin{aligned} e^{A + B} &= \begin{bmatrix}\cosh 1 & \sinh 1\\\sinh 1 & \cosh 1\end{bmatrix} \\ &= \begin{bmatrix}1.543 & 1.175\\1.175 & 1.543\end{bmatrix} \end{aligned}$$
4. **Why they differ.** $AB \ne BA$: $AB$ has a 1 in the top-left corner and $BA$ in the bottom-right.

**Answer:** $e^Ae^B = \begin{bmatrix}2 & 1\\1 & 1\end{bmatrix}$ and $e^{A + B} = \begin{bmatrix}1.543 & 1.175\\1.175 & 1.543\end{bmatrix}$; they differ because $A$ and $B$ don't commute.
:::
:::

::: check
given: w = 2 | 5; t = 0.2 | 1
answer: cos(w*t)
tolerance: 0.5%

## For $A = \begin{bmatrix}0 & -\given{w}\\\given{w} & 0\end{bmatrix}$, what is the top-left entry of $e^{At}$ at $t$ = {t}?

::: right
Right. $e^{At}$ is a rotation by $\omega t$, so the entry is $\cos\omega t$ = {answer}.
:::

::: misses
- [1] That's $e^0$, the exponential of the entry; the matrix exponential mixes entries.
- [sin(w*t)] That's the bottom-left entry.
- [any] Not yet. $e^{At}$ rotates by $\omega t$.
:::
:::

::: check
given: a = -1 | -3; b = -0.5 | -2; t = 0.5 | 2
answer: exp(b*t)
tolerance: 0.5%

## What is the bottom-right entry of $e^{At}$ for $A = \begin{bmatrix}\given{a} & 0\\0 & \given{b}\end{bmatrix}$ at $t$ = {t}?

::: right
Right. For a diagonal matrix, $e^{At}$ is diagonal with entries $e^{\lambda t}$: {answer}.
:::

::: misses
- [exp(a*t)] That's the top-left entry.
- [any] Not yet. Exponentiate each diagonal entry times $t$.
:::
:::

::: check
given: tau = 1 | 2.2; T = 0.5 | 2
answer: exp(-T/tau)
tolerance: 0.5%

## An RC circuit with $\tau$ = {tau} ms is stepped exactly with $T$ = {T} ms. What factor multiplies $x_k$?

::: right
Right. $e^{-T/\tau}$ = {answer}, with no truncation error.
:::

::: misses
- [1 - T/tau] That's Euler's method, which is only approximate.
- [1 - exp(-T/tau)] That's the factor on the input.
- [any] Not yet. The exact step is $x_{k+1} = e^{-T/\tau}x_k + (1 - e^{-T/\tau})u$.
:::
:::

::: check
given: t = 0.5 | 3 | 4
answer: t^2/2
tolerance: 0.5%

## For the nilpotent $N = \begin{bmatrix}0 & 1 & 0\\0 & 0 & 1\\0 & 0 & 0\end{bmatrix}$, what is the top-right entry of $e^{Nt}$ at $t$ = {t}?

::: right
Right. $N^2$ has a 1 in the corner and $N^3 = 0$, so the corner of $I + Nt + \frac{N^2t^2}{2}$ is $\frac{t^2}{2}$ = {answer}.
:::

::: misses
- [t] That's the entry just above the diagonal.
- [t^2] Divide by $2!$.
- [any] Not yet. The series stops after the $N^2$ term.
:::
:::

::: check
kind: parts
given: s = -0.1 | -0.5; w = 1 | 2; t = 1 | 3

## A spiral system has $A = \begin{bmatrix}\given{s} & -\given{w}\\\given{w} & \given{s}\end{bmatrix}$ and starts at $(1, 0)$.

::: part
answer: exp(s*t)*cos(w*t)
tolerance: 0.5%

### What is $u_1$ at $t$ = {t}?

::: misses
- [cos(w*t)] Include the decay $e^{\sigma t}$.
- [any] $e^{\sigma t}\cos\omega t$.
:::
:::

::: part
answer: exp(s*t)
tolerance: 0.5%

### How far is the state from the origin?

::: misses
- [any] Rotation keeps the length, so only $e^{\sigma t}$ remains.
:::
:::
:::

::: check
kind: derivation
vars: s = -1..0, w = 0.5..3, t = 0..3

## Use $e^{At} = e^{\sigma t}\left[\cos(\omega t)I + \sin(\omega t)\frac{A - \sigma I}{\omega}\right]$ for $A = \begin{bmatrix}s & -w\\w & s\end{bmatrix}$.

::: step
answer: exp(s*t)*cos(w*t)

### What is the top-left entry?
:::

::: step
answer: -exp(s*t)*sin(w*t)

### $\frac{A - \sigma I}{\omega}$ has $-1$ in its top-right entry. What is the top-right entry of $e^{At}$?
:::

::: right
Right. A decaying rotation: $e^{\sigma t}$ times the rotation matrix by $\omega t$.
:::
:::

::: explain
## A simulator steps a linear circuit with $e^{AT}$ instead of Euler's method. Why can it take large steps without losing accuracy or stability?

::: model
Euler's method replaces $e^{AT}$ with the first two terms of its series, $I + AT$. That's accurate only when $AT$ is small, and when a fast mode makes $|\lambda T| > 2$, the factor $1 + \lambda T$ has magnitude above 1 and the simulation blows up even though the circuit decays. Using $e^{AT}$ itself gives the exact solution at each step for a constant input, so the only limit on $T$ is how finely you want to see the waveform. Every mode is multiplied by its true factor $e^{\lambda T}$, which is below 1 in magnitude for every decaying mode, however large $T$ gets, so stability is never lost. The cost is computing $e^{AT}$ once per step size.
:::
:::

::: practice

::: check
given: w = 0.1..10; t = 0.01..1
answer: sin(w*t)
tolerance: 0.5%

## Bottom-left entry of $e^{At}$ for the rotation generator with $\omega$ = {w}, at $t$ = {t}?

::: misses
- [any] $\sin\omega t$.
:::
:::

::: check
given: tau = 0.1..10; T = 0.01..1
answer: 1 - exp(-T/tau)
tolerance: 0.5%

## Exact RC step with $\tau$ = {tau} and $T$ = {T}: the factor on the input?

::: misses
- [any] $1 - e^{-T/\tau}$.
:::
:::
:::
