TExcelTAD
Home › Linear Algebra & Matrix Theory › Application: The Matrix Exponential

Application: The Matrix Exponential

The number eate^{at} solves x′=axx' = ax. The matrix exponential etAe^{tA} does the same job for a system x′=Ax\mathbf{x}' = A\mathbf{x}: x(t)=etAx0\mathbf{x}(t) = e^{tA}\mathbf{x}_0, for any square matrix AA, diagonalizable or not. It is defined by the same power series as exe^x, and computing it once gives a physics engine an exact time step for any linear system.

Definition by power series

The Taylor series ex=1+x+x2/2!+x3/3!+⋯e^x = 1 + x + x^2/2! + x^3/3! + \cdots (Taylor Series) makes sense with a square matrix in place of xx:

eA=I+A+A22!+A33!+⋯=∑kAkk!e^A = I + A + \frac{A^2}{2!} + \frac{A^3}{3!} + \cdots = \sum_k \frac{A^k}{k!}

The series always converges, because k!k! eventually outgrows any power. Differentiating etA=I+tA+t2A2/2!+⋯e^{tA} = I + tA + t^2A^2/2! + \cdots term by term gives A⋅etAA \cdot e^{tA}, so

x(t)=etAx0solvesx′=Ax, x(0)=x0\mathbf{x}(t) = e^{tA}\mathbf{x}_0 \qquad \text{solves} \qquad \mathbf{x}' = A\mathbf{x}, \ \mathbf{x}(0) = \mathbf{x}_0

Three ways to compute it

1. Diagonal matrices. Powers act entry by entry, so ediag⁡(a,b)=diag⁡(ea,eb)e^{\operatorname{diag}(a, b)} = \operatorname{diag}(e^a, e^b).

2. Diagonalizable matrices. If A=PDP−1A = PDP^{-1} then Ak=PDkP−1A^k = PD^kP^{-1} in every term of the series, and

etA=PetDP−1=P⋅diag⁡(eλ1t,…,eλnt)⋅P−1e^{tA} = Pe^{tD}P^{-1} = P \cdot \operatorname{diag}(e^{\lambda_1t}, \ldots, e^{\lambda_nt}) \cdot P^{-1}

This is exactly the eigenvector solution of Systems of Linear Differential Equations, packaged as one matrix.

3. Nilpotent matrices. If Nk=0N^k = 0 for some kk, the series stops. The shear-like N=[0100]N = \begin{bmatrix} 0 & 1 \\ 0 & 0 \end{bmatrix} has N2=0N^2 = 0, so etN=I+tN=[1t01]e^{tN} = I + tN = \begin{bmatrix} 1 & t \\ 0 & 1 \end{bmatrix}. That covers a matrix that cannot be diagonalized. In general one splits A=S+NA = S + N into commuting diagonalizable and nilpotent parts (the Jordan form idea).

python · try it yourself
from sympy import Matrix, symbols, simplify

t = symbols("t")
A = Matrix([[-2, 1], [1, -2]])
N = Matrix([[0, 1], [0, 0]])
print("e^(tA) =", simplify((t * A).exp()).tolist())
print("e^(tN) =", (t * N).exp().tolist())
x = simplify((t * A).exp() * Matrix([10, 0]))
print("e^(tA)(10, 0) =", list(x))
e^(tA) = [[(exp(2*t) + 1)*exp(-3*t)/2, (exp(2*t) - 1)*exp(-3*t)/2], [(exp(2*t) - 1)*exp(-3*t)/2, (exp(2*t) + 1)*exp(-3*t)/2]]
e^(tN) = [[1, t], [0, 1]]
e^(tA)(10, 0) = [5*exp(-t) + 5*exp(-3*t), 5*exp(-t) - 5*exp(-3*t)]

The last line reproduces the two-room solution x(t)=5e−t(1,1)+5e−3t(1,−1)\mathbf{x}(t) = 5e^{-t}(1, 1) + 5e^{-3t}(1, -1).

Rotation from an exponential

Take J=[0−110]J = \begin{bmatrix} 0 & -1 \\ 1 & 0 \end{bmatrix}, the 90∘90^\circ rotation. Its powers cycle: J2=−IJ^2 = -I, J3=−JJ^3 = -J, J4=IJ^4 = I. Grouping the even and odd terms of the series:

eθJ=(1−θ22!+θ44!−⋯ )⋅I+(θ−θ33!+⋯ )⋅J=cos⁡θ⋅I+sin⁡θ⋅J=[cos⁡θ−sin⁡θsin⁡θcos⁡θ]\begin{aligned} e^{\theta J} &= \left(1 - \frac{\theta^2}{2!} + \frac{\theta^4}{4!} - \cdots\right) \cdot I + \left(\theta - \frac{\theta^3}{3!} + \cdots\right) \cdot J = \cos\theta \cdot I + \sin\theta \cdot J \\ &= \begin{bmatrix} \cos\theta & -\sin\theta \\ \sin\theta & \cos\theta \end{bmatrix} \end{aligned}

The exponential of the "infinitesimal rotation" JJ is the rotation by θ\theta. This mirrors Euler's formula eiθ=cos⁡θ+i⋅sin⁡θe^{i\theta} = \cos\theta + i \cdot \sin\theta, with JJ playing the role of ii (Complex Eigenvalues and Eigenvectors). In 3D, the exponential of a skew-symmetric matrix is a rotation about an axis, which is how robotics and physics code turn an angular velocity into a rotation.

Rules, and one trap

Rule Holds?
e0=Ie^0 = I always
e(s+t)A=esA⋅etAe^{(s+t)A} = e^{sA} \cdot e^{tA} always (same AA)
(eA)−1=e−A(e^A)^{-1} = e^{-A} always, so eAe^A is always invertible
det⁡(eA)=etr⁡A\det(e^A) = e^{\operatorname{tr} A} always
eA+B=eA⋅eBe^{A+B} = e^A \cdot e^B only if AB=BAAB = BA

The last line is the trap. With non-commuting matrices the exponential of a sum is not the product of exponentials:

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

A = np.array([[0.0, 1.0], [0.0, 0.0]])
B = np.array([[0.0, 0.0], [1.0, 0.0]])
print("AB == BA:", np.array_equal(A @ B, B @ A))
print("e^(A+B):\n", np.round(expm(A + B), 4))
print("e^A e^B:\n", np.round(expm(A) @ expm(B), 4))
print("det e^(A+B) =", round(float(np.linalg.det(expm(A + B))), 6),
      " e^tr(A+B) =", float(np.exp(np.trace(A + B))))
AB == BA: False
e^(A+B):
 [[1.5431 1.1752]
 [1.1752 1.5431]]
e^A e^B:
 [[2. 1.]
 [1. 1.]]
det e^(A+B) = 1.0  e^tr(A+B) = 1.0

An exact integrator for a game spring

A damped spring, x′′=−kx−cvx'' = -kx - cv, is linear in the state s=(x,v)\mathbf{s} = (x, v):

s′=As,A=[01−k−c]\mathbf{s}' = A\mathbf{s}, \qquad A = \begin{bmatrix} 0 & 1 \\ -k & -c \end{bmatrix}

So one frame of length Δt\Delta t is exactly s←eAΔt⋅s\mathbf{s} \leftarrow e^{A\Delta t} \cdot \mathbf{s}. Compute the 2×22 \times 2 matrix M=eAΔtM = e^{A\Delta t} once with scipy.linalg.expm, and every frame costs one matrix-vector product, with no integration error no matter how stiff the spring. Compare it with explicit Euler at the same Δt\Delta t:

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

k, c, dt = 400.0, 2.0, 1 / 30           # stiff spring, 30 frames per second
A = np.array([[0.0, 1.0], [-k, -c]])
M = expm(A * dt)                         # exact one-frame step, computed once

exact = np.array([1.0, 0.0])
euler = np.array([1.0, 0.0])
for frame in range(1, 31):
    exact = M @ exact
    euler = euler + dt * (A @ euler)     # explicit Euler: s += dt * s'
    if frame % 10 == 0:
        print(f"frame {frame}: exact x = {exact[0]: .4f}   Euler x = {euler[0]: .4f}")
print("spectral radius of Euler step:", round(float(max(abs(np.linalg.eigvals(np.eye(2) + dt * A)))), 4))
frame 10: exact x =  0.6798   Euler x =  4.7466
frame 20: exact x =  0.3931   Euler x =  20.9997
frame 30: exact x =  0.1751   Euler x =  84.9564
spectral radius of Euler step: 1.1738

The exact step stays inside the decaying envelope e−ct/2=e−te^{-ct/2} = e^{-t}, as a damped spring should (it oscillates about 3 times per second, so frames 10, 20, 30 catch it at different phases). Euler's step matrix I+ΔtAI + \Delta tA has an eigenvalue of modulus greater than 1, so every frame amplifies the error and the spring explodes. That eigenvalue test is the standard stability analysis of integrators (Integrators).

In software

  • Physics and animation: exact steps for linear springs and dampers, and spring-based UI animation libraries that solve the spring in closed form.
  • Robotics and 3D: exponential maps convert angular velocity vectors into rotation matrices (and quaternions).
  • Continuous-time Markov chains: transition probabilities after time tt are etQe^{tQ} for a rate matrix QQ, used in queueing models and reliability analysis.
  • Neural ODEs and state-space models: modern sequence models (S4, Mamba) discretise x′=Ax+Bu\mathbf{x}' = A\mathbf{x} + B\mathbf{u} with a matrix exponential.

Exercises

Exercise 1: A diagonal exponential

Compute etAe^{tA} for A=diag⁡(1,−2)A = \operatorname{diag}(1, -2), and the solution of x′=Ax\mathbf{x}' = A\mathbf{x} with x(0)=(3,5)\mathbf{x}(0) = (3, 5).

Answer

etA=diag⁡(et,e−2t)e^{tA} = \operatorname{diag}(e^t, e^{-2t}); x(t)=(3et,5e−2t)\mathbf{x}(t) = (3e^t, 5e^{-2t}).

Solution

Every power of a diagonal matrix is diagonal, so the series acts on each diagonal entry separately: 1+t+t2/2!+⋯=et1 + t + t^2/2! + \cdots = e^t and 1−2t+(−2t)2/2!+⋯=e−2t1 - 2t + (-2t)^2/2! + \cdots = e^{-2t}.

Exercise 2: Constant velocity

For A=[0100]A = \begin{bmatrix} 0 & 1 \\ 0 & 0 \end{bmatrix} (position′=velocity\text{position}' = \text{velocity}, velocity′=0\text{velocity}' = 0), compute etAe^{tA} and apply it to (x0,v0)(x_0, v_0).

Answer

etA=[1t01]e^{tA} = \begin{bmatrix} 1 & t \\ 0 & 1 \end{bmatrix}; etA(x0,v0)=(x0+v0t,v0)e^{tA}(x_0, v_0) = (x_0 + v_0t, v_0).

Solution

A2=0A^2 = 0, so the series is I+tAI + tA. Applied to the state, it gives the familiar position x0+v0tx_0 + v_0t with unchanged velocity.

Exercise 3: A 3×33 \times 3 nilpotent matrix

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

Answer

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

Solution
N2=[001000000],N3=0etN=I+tN+t22N2\begin{aligned} N^2 &= \begin{bmatrix} 0 & 0 & 1 \\ 0 & 0 & 0 \\ 0 & 0 & 0 \end{bmatrix}, \qquad N^3 = 0 \\ e^{tN} &= I + tN + \frac{t^2}{2}N^2 \end{aligned}

This is the motion under constant acceleration: position, velocity, acceleration.

Exercise 4: Check the determinant rule

Verify det⁡(eA)=etr⁡A\det(e^A) = e^{\operatorname{tr} A} for A=[1234]A = \begin{bmatrix} 1 & 2 \\ 3 & 4 \end{bmatrix} numerically.

Answer

Both are e5≈148.4132e^5 \approx 148.4132.

Solution

tr⁡A=5\operatorname{tr} A = 5. If λ1,λ2\lambda_1, \lambda_2 are the eigenvalues of AA, eAe^A has eigenvalues eλ1,eλ2e^{\lambda_1}, e^{\lambda_2}, whose product is eλ1+λ2=etr⁡Ae^{\lambda_1+\lambda_2} = e^{\operatorname{tr} A}.

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

A = np.array([[1.0, 2.0], [3.0, 4.0]])
print(round(float(np.linalg.det(expm(A))), 4), round(float(np.exp(np.trace(A))), 4))
148.4132 148.4132

Test yourself

What is etNe^{tN} for N=[0100]N = \begin{bmatrix} 0 & 1 \\ 0 & 0 \end{bmatrix}?

  1. [et10et]\begin{bmatrix} e^t & 1 \\ 0 & e^t \end{bmatrix}
  2. [1t01]\begin{bmatrix} 1 & t \\ 0 & 1 \end{bmatrix}
  3. [1et01]\begin{bmatrix} 1 & e^t \\ 0 & 1 \end{bmatrix}
  4. [0t00]\begin{bmatrix} 0 & t \\ 0 & 0 \end{bmatrix}

When is eA+B=eA⋅eBe^{A+B} = e^A \cdot e^B guaranteed?

  1. Always
  2. When AA and BB are invertible
  3. When AB=BAAB = BA
  4. When AA and BB are symmetric

Why can a game use M=eAΔtM = e^{A\Delta t} as its step for a linear spring?

  1. It is an approximation that is only good for small Δt\Delta t
  2. It is the exact solution of s′=As\mathbf{s}' = A\mathbf{s} over one step of length Δt\Delta t
  3. It makes the spring undamped
  4. It avoids computing eigenvalues of AA