24. Adv: Cayley-Hamilton Theorem
Every lesson so far in this module has used the characteristic polynomial p(\lambda)=\det(A-\lambda I) as a tool for finding eigenvalues — plug in a number, check if it's a root. This closing lesson plugs in something far stranger: the matrix A itself, into its own characteristic polynomial.
The theorem
p(A)=0
where p(\lambda)=\lambda^n-c_{n-1}\lambda^{n-1}+\cdots\pm\det A is A's characteristic polynomial (§19.0) and 0 means the zero matrix. Concretely, if p(\lambda)=\lambda^2-(\operatorname{tr}A)\lambda+\det A for a 2\times2 matrix (§19.0's formula), then
A^2-(\operatorname{tr}A)A+(\det A)I=0
Every square matrix satisfies its own characteristic equation — a genuinely surprising claim, since p was built purely from scalar eigenvalue information, and yet substituting the full matrix A in place of the scalar \lambda still gives exactly zero, with \det A promoted to (\det A)I to keep the equation matrix-shaped throughout.
(Sketch, for diagonalizable A=PDP^{-1}: p(A)=p(PDP^{-1})=Pp(D)P^{-1}, since every power A^k=PD^kP^{-1} — §19.1's power formula — lets P, P^{-1} factor out of each term of p. And p(D) is diagonal with p(\lambda_i) in position i, which is exactly 0 for every i since each \lambda_i is a root of p by definition. So p(A)=P\cdot0\cdot P^{-1}=0. The theorem is in fact true for every square matrix, including defective ones — proved there via Jordan form instead, not shown here.)
Why it's useful: computing A^{-1} without cofactors
Rearranging the 2\times2 case:
A^2-(\operatorname{tr}A)A+(\det A)I=0\ \Longrightarrow\ A\Big[\tfrac1{\det A}\big((\operatorname{tr}A)I-A\big)\Big]=I
(multiply through by A^{-1}, assuming \det A\neq0, and solve for I) which gives A^{-1} directly from trace and determinant alone — no cofactors, no adjugate, just the 2\times2 formula §16.3 already had, now derived rather than stated. The same idea generalizes: for any n, Cayley-Hamilton expresses A^{-1} as a polynomial in A (with coefficients from the characteristic polynomial), turning matrix inversion into ordinary polynomial algebra.
Why it's useful: reducing any power of A
Cayley-Hamilton says A^n is expressible as a combination of I,A,A^2,\dots,A^{n-1} — so every higher power A^k for k\ge n reduces to that same combination, by repeated substitution. For 2\times2: A^2=(\operatorname{tr}A)A-(\det A)I lets any power of A be rewritten using only A^1 and I, without ever diagonalizing — useful precisely when A is defective (§19.4) and diagonalization isn't available at all.
Doing it in Python
import sympy as sp
A = sp.Matrix([[4, 1], [2, 3]])
lam = sp.Symbol('lambda')
p = A.charpoly(lam).as_expr()
print("p(lambda) =", p)
# Substitute A for lambda: p(A) should be the zero matrix
pA = A**2 - A.trace()*A + A.det()*sp.eye(2)
print("p(A) =")
for row in pA.tolist():
print(row)
p(lambda) = lambda**2 - 7*lambda + 10
p(A) =
[0, 0]
[0, 0]
Deriving A^{-1} from Cayley-Hamilton alone, and checking it against
A.inv():
import sympy as sp
A = sp.Matrix([[4, 1], [2, 3]])
Ainv_ch = (A.trace()*sp.eye(2) - A) / A.det()
Ainv_direct = A.inv()
print("A^-1 via Cayley-Hamilton =")
for row in Ainv_ch.tolist():
print(row)
print("matches A.inv():", Ainv_ch == Ainv_direct)
# Reduce A^5 to c1*A + c0*I, using A^2 = tr(A) A - det(A) I repeatedly
tr, det = A.trace(), A.det()
c1, c0 = 1, 0 # A^1 = 1*A + 0*I
for _ in range(4): # advance from A^1 up to A^5
c1, c0 = c1*tr + c0, -c1*det
reduced = c1*A + c0*sp.eye(2)
print(f"\nA^5 via reduction: c1={c1}, c0={c0}")
print("reduced == A**5:", reduced == A**5)
A^-1 via Cayley-Hamilton =
[3/10, -1/10]
[-1/5, 2/5]
matches A.inv(): True
A^5 via reduction: c1=1031, c0=-2030
reduced == A**5: True
Worked example
Use Cayley-Hamilton to find A^{-1} for A=\begin{pmatrix}5&2\\1&4\end{pmatrix}.
\operatorname{tr}A=9, \det A=5(4)-2(1)=18. Cayley-Hamilton: A^2-9A+18I=0. Multiply by A^{-1}: A-9I+18A^{-1}=0\Rightarrow A^{-1}=\frac{9I-A}{18}.
A^{-1}=\frac1{18}\begin{pmatrix}9-5&0-2\\0-1&9-4\end{pmatrix}=\frac1{18}\begin{pmatrix}4&-2\\-1&5\end{pmatrix}
\boxed{A^{-1}=\begin{pmatrix}\frac29&-\frac19\\-\frac1{18}&\frac5{18}\end{pmatrix}}
Sanity check against §16.3's direct 2\times2 formula: A^{-1}=\frac1{18}\begin{pmatrix}4&-2\\-1&5\end{pmatrix} — exactly "swap the diagonal, negate the off-diagonal, divide by the determinant" ✓, confirming Cayley-Hamilton reproduces the familiar formula rather than contradicting it, just via a completely different route (a polynomial identity rather than the adjugate).
Your turn
1. For A=\begin{pmatrix}2&0\\1&3\end{pmatrix}, write down the Cayley-Hamilton identity A^2-(\operatorname{tr}A)A+(\det A)I=0 explicitly (i.e. state \operatorname{tr}A and \det A, don't verify by hand-multiplying).
2. Using Cayley-Hamilton, express A^3 in terms of A and I for a 2\times2 matrix with \operatorname{tr}A=5,\det A=6.
3. True or false: Cayley-Hamilton implies A is always invertible.
Solutions
1. \operatorname{tr}A=5, \det A=6. A^2-5A+6I=0.
2. From A^2=5A-6I: A^3=A\cdot A^2=A(5A-6I)=5A^2-6A=5(5A-6I)-6A=25A-30I-6A=19A-30I. \boxed{A^3=19A-30I}
3. False. Cayley-Hamilton is an identity satisfied by every square matrix, invertible or not — it says nothing about invertibility itself. For a singular matrix, \det A=0, and the derivation of A^{-1} above breaks exactly at the "multiply by A^{-1}" step, since no such inverse exists to multiply by — the identity A^2-(\operatorname{tr}A)A+(\det A)I=0 still holds, it just can't be rearranged to solve for an inverse that isn't there.
Check yourself in code
Verify Cayley-Hamilton for A=\begin{pmatrix}3&1\\4&2\end{pmatrix} by computing p(A)=A^2-(\operatorname{tr}A)A+(\det A)I directly.
Print exactly this:
trace = 5, det = 2
p(A) =
[0, 0]
[0, 0]
import sympy as sp
A = sp.Matrix([[3, 1], [4, 2]])
tr, det = A.trace(), A.det()
print(f"trace = {tr}, det = {det}")
# compute p(A) = A**2 - tr*A + det*eye(2) and print it row by row, labeled
import sympy as sp
A = sp.Matrix([[3, 1], [4, 2]])
tr, det = A.trace(), A.det()
print(f"trace = {tr}, det = {det}")
pA = A**2 - tr*A + det*sp.eye(2)
print("p(A) =")
for row in pA.tolist():
print(row)
Cayley-Hamilton says every square matrix satisfies its own characteristic equation, p(A)=0 — a fact provable directly via diagonalization (and holding even without it). It turns matrix inversion into polynomial algebra (A^{-1} as a combination of I and powers of A) and lets any high power of A be reduced to a combination of I,A,\dots,A^{n-1}.
This closes Module 19. Eigenvalues and eigenvectors have, so far, used only A\vec v=\lambda\vec v — no notion of length or angle anywhere. Module 20 introduces both, and Module 21 shows what happens when the two theories meet: symmetric matrices, whose eigenvectors turn out to always be orthogonal.