TExcelTAD
Home › Differential Equations › The Matrix Exponential

The Matrix Exponential

The scalar equation x′=axx' = ax has the solution x=eatx0x = e^{at}x_0. The system x′=Ax\mathbf{x}' = A\mathbf{x} has the solution

x(t)=etA x0,\mathbf{x}(t) = e^{tA}\,\mathbf{x}_0,

once we define the exponential of a matrix. It handles distinct, complex and repeated eigenvalues with one formula, and it is how software actually solves constant-coefficient linear systems.

Definition

Use the power series of exe^x:

etA=I+tA+t2A22!+t3A33!+⋯e^{tA} = I + tA + \frac{t^2A^2}{2!} + \frac{t^3A^3}{3!} + \cdots

The series converges for every square matrix. Differentiating term by term gives ddtetA=AetA\frac{d}{dt}e^{tA} = Ae^{tA}, so etAe^{tA} is the fundamental matrix with e0A=Ie^{0A} = I (Linear Systems in Matrix Form).

Properties: e0=Ie^{0} = I; e(t+s)A=etAesAe^{(t+s)A} = e^{tA}e^{sA}; (etA)−1=e−tA(e^{tA})^{-1} = e^{-tA}. But eA+B=eAeBe^{A+B} = e^Ae^B only when AB=BAAB = BA.

Computing it

  • Diagonal: et diag⁡(λi)=diag⁡(eλit)e^{t\,\operatorname{diag}(\lambda_i)} = \operatorname{diag}(e^{\lambda_it}).
  • Diagonalizable: A=VΛV−1A = V\Lambda V^{-1} gives etA=VetΛV−1e^{tA} = Ve^{t\Lambda}V^{-1}.
  • Nilpotent part: if Nk=0N^k = 0 the series stops. For A=λI+NA = \lambda I + N (with λI\lambda I and NN commuting), etA=eλt(I+tN+… )e^{tA} = e^{\lambda t}(I + tN + \dots). For example
exp⁡(t[2102])=e2t[1t01],\exp\left(t\begin{bmatrix} 2 & 1 \\ 0 & 2 \end{bmatrix}\right) = e^{2t}\begin{bmatrix} 1 & t \\ 0 & 1 \end{bmatrix},

which contains the te2tte^{2t} of Repeated Eigenvalues automatically.

python · try it yourself
import sympy as sp

t = sp.symbols("t")
for M in (sp.Matrix([[2, 1], [0, 2]]), sp.Matrix([[0, 1], [-1, 0]]), sp.Matrix([[1, 1], [4, 1]])):
    print(sp.simplify((t * M).exp()).tolist())
[[exp(2*t), t*exp(2*t)], [0, exp(2*t)]]
[[cos(t), sin(t)], [-sin(t), cos(t)]]
[[(exp(4*t) + 1)*exp(-t)/2, (exp(4*t) - 1)*exp(-t)/4], [(exp(4*t) - 1)*exp(-t), (exp(4*t) + 1)*exp(-t)/2]]

The second matrix gives the rotation matrix [cos⁡tsin⁡t−sin⁡tcos⁡t]\begin{bmatrix} \cos t & \sin t \\ -\sin t & \cos t \end{bmatrix}: the exponential of an antisymmetric matrix is a rotation.

Numerically: scipy.linalg.expm

Summing the series naively is a bad algorithm (huge cancellations for large ∥tA∥\lVert tA\rVert). SciPy uses scaling and squaring with a Padé approximation: compute eA/2se^{A/2^s} for a small matrix, then square ss times.

python · try it yourself
import numpy as np
from scipy.linalg import expm
from scipy.integrate import solve_ivp

A = np.array([[-1.0, 2.0, 0.0], [-2.0, -1.0, 1.0], [0.0, 0.0, -0.5]])
x0 = np.array([1.0, 0.0, 2.0])
x_expm = expm(3.0 * A) @ x0
sol = solve_ivp(lambda t, x: A @ x, (0, 3), x0, rtol=1e-12, atol=1e-14)
print("expm:     ", np.round(x_expm, 8))
print("solve_ivp:", np.round(sol.y[:, -1], 8))

def expm_series(M, terms):
    S, term = np.eye(len(M)), np.eye(len(M))
    for k in range(1, terms):
        term = term @ M / k
        S = S + term
    return S
B = -20 * np.eye(2)
print("naive series for e^{-20}:", expm_series(B, 100)[0, 0], " true:", np.exp(-20))
expm:      [0.2160901  0.04207151 0.44626032]
solve_ivp: [0.2160901  0.04207151 0.44626032]
naive series for e^{-20}: 5.621884472130418e-09  true: 2.061153622438558e-09

The naive series for e−20e^{-20} adds terms as large as 2020/20!≈4×10720^{20}/20! \approx 4 \times 10^7 with alternating signs, and the rounding errors of those huge terms swamp the tiny answer: the result is wrong by a factor of almost 3.

Time stepping with a fixed step

For a constant matrix, x(t+h)=ehAx(t)\mathbf{x}(t + h) = e^{hA}\mathbf{x}(t) exactly. Precompute E=ehAE = e^{hA} once, and each step is a matrix-vector product. This "exponential integrator" is exact for linear systems at any step size.

In software

  • Continuous-time Markov chains: transition probabilities after time tt are etQe^{tQ} (used in phylogenetics software, reliability models and queueing).
  • Robotics and graphics: rotations are exponentials of antisymmetric matrices (Lie groups); scipy.spatial.transform.Rotation.from_rotvec computes one.
  • Control systems discretize x′=Ax+Bu\mathbf{x}' = A\mathbf{x} + B\mathbf{u} with expm (zero-order hold), as scipy.signal.cont2discrete does.

Exercises

Exercise 1: Diagonal

Compute etAe^{tA} for A=[−1003]A = \begin{bmatrix} -1 & 0 \\ 0 & 3 \end{bmatrix}.

Answer

[e−t00e3t]\begin{bmatrix} e^{-t} & 0 \\ 0 & e^{3t} \end{bmatrix}.

Solution

Powers of a diagonal matrix are diagonal with powered entries, so the series acts entry by entry.

Exercise 2: Nilpotent

Compute etNe^{tN} for N=[010001000]N = \begin{bmatrix} 0 & 1 & 0 \\ 0 & 0 & 1 \\ 0 & 0 & 0 \end{bmatrix}.

Answer

[1tt2/201t001]\begin{bmatrix} 1 & t & t^2/2 \\ 0 & 1 & t \\ 0 & 0 & 1 \end{bmatrix}.

Solution

N2N^2 has a single 1 in the top-right corner and N3=0N^3 = 0, so etN=I+tN+t22N2e^{tN} = I + tN + \frac{t^2}{2}N^2. This system is x3′=0x_3' = 0, x2′=x3x_2' = x_3, x1′=x2x_1' = x_2: position under constant acceleration.

Exercise 3: Exponential stepping (code)

For A=[01−40]A = \begin{bmatrix} 0 & 1 \\ -4 & 0 \end{bmatrix} and x(0)=(1,0)\mathbf{x}(0) = (1, 0), take 100 steps of x←ehAx\mathbf{x} \leftarrow e^{hA}\mathbf{x} with h=π/100h = \pi/100. Where do you end up?

Answer

Back at (1,0)(1, 0) (up to rounding): the period is π\pi.

Solution
python · try it yourself
import numpy as np
from scipy.linalg import expm
A = np.array([[0.0, 1.0], [-4.0, 0.0]])
E = expm(np.pi / 100 * A)
x = np.array([1.0, 0.0])
for _ in range(100):
    x = E @ x
print(np.round(x, 10) + 0)
[1. 0.]

Test yourself

The solution of x′=Ax\mathbf{x}' = A\mathbf{x}, x(0)=x0\mathbf{x}(0) = \mathbf{x}_0 is…

  1. etAx0e^{t}A\mathbf{x}_0
  2. etAx0e^{tA}\mathbf{x}_0
  3. Atx0A^t\mathbf{x}_0
  4. tAx0tA\mathbf{x}_0

eA+B=eAeBe^{A+B} = e^Ae^B holds…

  1. always
  2. when AB=BAAB = BA
  3. never
  4. only for 2×22 \times 2 matrices

Why does scipy.linalg.expm not just sum the power series?

  1. The series diverges
  2. Summing it can lose all precision through cancellation for large ∥A∥\lVert A\rVert
  3. It is too exact
  4. Python cannot multiply matrices