Application: The Matrix Exponential
The number solves . The matrix exponential does the same job for a system : , for any square matrix , diagonalizable or not. It is defined by the same power series as , and computing it once gives a physics engine an exact time step for any linear system.
Definition by power series
The Taylor series (Taylor Series) makes sense with a square matrix in place of :
The series always converges, because eventually outgrows any power. Differentiating term by term gives , so
Three ways to compute it
1. Diagonal matrices. Powers act entry by entry, so .
2. Diagonalizable matrices. If then in every term of the series, and
This is exactly the eigenvector solution of Systems of Linear Differential Equations, packaged as one matrix.
3. Nilpotent matrices. If for some , the series stops. The shear-like has , so . That covers a matrix that cannot be diagonalized. In general one splits into commuting diagonalizable and nilpotent parts (the Jordan form idea).
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 .
Rotation from an exponential
Take , the rotation. Its powers cycle: , , . Grouping the even and odd terms of the series:
The exponential of the "infinitesimal rotation" is the rotation by . This mirrors Euler's formula , with playing the role of (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? |
|---|---|
| always | |
| always (same ) | |
| always, so is always invertible | |
| always | |
| only if |
The last line is the trap. With non-commuting matrices the exponential of a sum is not the product of exponentials:
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, , is linear in the state :
So one frame of length is exactly . Compute the matrix 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 :
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 , 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 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 are for a rate matrix , used in queueing models and reliability analysis.
- Neural ODEs and state-space models: modern sequence models (S4, Mamba) discretise with a matrix exponential.
Exercises
Exercise 1: A diagonal exponential
Compute for , and the solution of with .
Answer
; .
Solution
Every power of a diagonal matrix is diagonal, so the series acts on each diagonal entry separately: and .
Exercise 2: Constant velocity
For (, ), compute and apply it to .
Answer
; .
Solution
, so the series is . Applied to the state, it gives the familiar position with unchanged velocity.
Exercise 3: A nilpotent matrix
. Find .
Answer
.
Solution
This is the motion under constant acceleration: position, velocity, acceleration.
Exercise 4: Check the determinant rule
Verify for numerically.
Answer
Both are .
Solution
. If are the eigenvalues of , has eigenvalues , whose product is .
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 for ?
When is guaranteed?
- Always
- When and are invertible
- When
- When and are symmetric
Why can a game use as its step for a linear spring?
- It is an approximation that is only good for small
- It is the exact solution of over one step of length
- It makes the spring undamped
- It avoids computing eigenvalues of