Eigendecomposition and Diagonalization
Diagonal matrices are the easy case for everything. Their determinant is the product of the diagonal; their -th power raises each diagonal entry to the ; their inverse takes reciprocals. Nothing about a general matrix is that easy.
Diagonalization asks whether a given square matrix is a diagonal matrix in disguise — the same linear mapping, written in a better basis. When the answer is yes, every easy property of a diagonal matrix becomes available, and the basis that does it is the eigenbasis of §4.2.
What you’ll learn
Section titled “What you’ll learn”- Definition 4.19: what diagonalizable means, and why it is exactly Chapter 2’s notion of similar.
- Why forces the columns of to be eigenvectors.
- Theorem 4.20: if and only if the eigenvectors form a basis.
- Theorem 4.21: a symmetric matrix can always be diagonalized, and by an orthogonal , so .
- The geometry: then then , and what each step does to a disc.
- Equations 4.62 and 4.63: matrix powers and determinants in one line each, with a measured cost crossover.
Intuition: work in the coordinates where the map is simple
Section titled “Intuition: work in the coordinates where the map is simple”Here is the whole idea in three sentences.
A matrix does something complicated in the standard basis and something trivial in its own eigenbasis: along each eigenvector it just multiplies by a number. So if you first change coordinates into the eigenbasis, then scale each coordinate by its eigenvalue, then change back, you have applied the original matrix — by a route where the only real work is independent multiplications.
Read right to left, in the order a vector meets them. And the payoff arrives when you apply the matrix repeatedly: the two changes of basis cancel in the middle of , leaving .
flowchart TD DIAG["a diagonal matrix D
Eq 4.49"] DIAG --> EASY["det = ∏dᵢᵢ · Dᵏ = each entry to the k
D⁻¹ = reciprocals, if none are zero"] A["a square matrix A"] A --> Q["is A a diagonal matrix
in a different basis?
Def 4.19: similar to a diagonal"] Q --> AP["AP = PD
Eq 4.50"] AP --> COLS["column by column: Apᵢ = λᵢpᵢ
Eq 4.53, 4.54 — so the columns
of P ARE eigenvectors"] COLS --> NEED["P must be invertible,
so the eigenvectors must be a BASIS"] NEED --> THM["Thm 4.20: A = PDP⁻¹ ⟺ the
eigenvectors form a basis of ℝⁿ"] THM --> SYM["Thm 4.21: symmetric ⟹ always,
and P can be ORTHOGONAL
so P⁻¹ = Pᵀ"] THM --> POW["Aᵏ = PDᵏP⁻¹, Eq 4.62"] THM --> DET["det A = ∏dᵢᵢ, Eq 4.63"] THM --> NO["defective ⟹ no eigendecomposition
(Jordan normal form instead —
beyond this book)"]
The math
Section titled “The math”Diagonal matrices, and why they are the target
Section titled “Diagonal matrices, and why they are the target”Similar, and diagonalizable
Section titled “Similar, and diagonalizable”“Similar” is Chapter 2’s Definition 2.22, and §4.1 already told you what it costs: similar matrices share a determinant, a trace and — from §4.2 — a spectrum. So diagonalization does not change any of the quantities that characterise the mapping. It changes only the basis you write it in.
Why the columns of P must be eigenvectors
Section titled “Why the columns of P must be eigenvectors”Take any scalars and any vectors , and set , . Multiply out both sides of :
Equate column by column and you get , …, (Equations 4.53 and 4.54). So
The eigenvectors are not chosen for the job; they are the only vectors that can do it.
The theorem, and its hypothesis
Section titled “The theorem, and its hypothesis”The hypothesis is where §4.2 earns its keep. Definition 4.19 needs invertible, so needs full rank (§4.1, Theorem 4.3), so its columns need to be linearly independent — so there must be linearly independent eigenvectors. That is exactly the negation of defective (Definition 4.13).
So: only non-defective matrices can be diagonalized, and the columns of are the eigenvectors. A repeated eigenvalue is fine as long as its eigenspace is big enough; a repeated eigenvalue whose geometric multiplicity falls short is fatal.
This follows directly from the spectral theorem (4.15), and it comes with a bonus: the spectral theorem gives an orthonormal basis of eigenvectors, so can be taken orthogonal, and then
with no inverse to compute. That substitution — — is why every covariance and kernel matrix in the applied chapters is handled without an inverse anywhere in sight.
The geometry
Section titled “The geometry”The book’s Figure 4.7 reads as a loop, and it is worth walking round it.
| step | what it does |
|---|---|
| a change of basis from the standard basis into the eigenbasis: it maps the eigenvectors onto the standard basis vectors | |
| scales along those axes by the eigenvalues — a circle becomes an axis-aligned ellipse | |
| undoes the basis change, returning the scaled vectors to the original frame, giving |
For a symmetric matrix the two outer steps are genuine rotations (or reflections), because is orthogonal. For a general non-defective matrix they are not — is invertible but need not be orthogonal, so the “change of basis” also shears. The book draws the symmetric case, which is why its Figure 4.7 looks like rotate-scale-rotate.
What it buys
Section titled “What it buys”The determinant identity is Theorem 4.16 again, arriving by a different route. The power identity is new, and it is the practical reason to diagonalize.
Worked example by hand
Section titled “Worked example by hand”Example 4.11
Section titled “Example 4.11”Step 1 — eigenvalues and eigenvectors.
so and . Solving and normalising:
Step 2 — check existence. Two distinct eigenvalues, so by Theorem 4.12 the eigenvectors are independent, so they form a basis of , so Theorem 4.20 applies.
Step 3 — assemble.
And because is symmetric, the eigenvectors are already an ONB, so and the factorisation can be written without an inverse (Equation 4.61):
Verified numerically: exactly, and reproduces to .
A closed form for the k-th power
Section titled “A closed form for the k-th power”Equation 4.62 does something a matrix multiply cannot: it gives an algebraic formula. For this ,
Read off the top-left entry: . Check against direct multiplication:
| direct , entry | ||
|---|---|---|
| 1 | ||
| 2 | ||
| 5 | ||
| 10 | ||
| 20 |
Every value integer and exact. That is what a diagonalisation gives you that repeated multiplication does not: not a faster loop, a formula.
import numpy as np
A = np.array([[2.0, 1.0], [1.0, 2.0]])
# The book's P and D (Equations 4.58 to 4.60).
P = np.array([[1.0, 1.0], [-1.0, 1.0]]) / np.sqrt(2)
D = np.diag([1.0, 3.0])
print("P^-1 A P ="); print(np.round(np.linalg.inv(P) @ A @ P, 10))
print("P^-1 equals P^T:", np.allclose(np.linalg.inv(P), P.T))
print("P D P^T - A, largest entry:", f"{float(np.abs(P @ D @ P.T - A).max()):.2e}")
print()
print("Equation 4.62, against direct multiplication:")
for k in (1, 2, 5, 10, 20):
direct = np.linalg.matrix_power(A, k)
via = P @ np.diag([1.0 ** k, 3.0 ** k]) @ P.T
closed = (1 + 3.0 ** k) / 2
print(f" k={k:3} direct[0,0] {direct[0, 0]:16.1f} PD^kP^T {via[0, 0]:16.1f} "
f"(1+3^k)/2 {closed:16.1f} gap {float(np.abs(direct - via).max()):.2e}")
print()
print("Equation 4.63: det A =", float(np.linalg.det(A)), " product of D's diagonal =", float(np.prod(np.diag(D))))P^-1 A P =
[[ 1. 0.]
[-0. 3.]]
P^-1 equals P^T: True
P D P^T - A, largest entry: 4.44e-16
Equation 4.62, against direct multiplication:
k= 1 direct[0,0] 2.0 PD^kP^T 2.0 (1+3^k)/2 2.0 gap 4.44e-16
k= 2 direct[0,0] 5.0 PD^kP^T 5.0 (1+3^k)/2 5.0 gap 8.88e-16
k= 5 direct[0,0] 122.0 PD^kP^T 122.0 (1+3^k)/2 122.0 gap 1.42e-14
k= 10 direct[0,0] 29525.0 PD^kP^T 29525.0 (1+3^k)/2 29525.0 gap 3.64e-12
k= 20 direct[0,0] 1743392201.0 PD^kP^T 1743392201.0 (1+3^k)/2 1743392201.0 gap 2.38e-07
Equation 4.63: det A = 2.9999999999999996 product of D's diagonal = 3.0Two things worth noticing. The absolute gap grows to by — but has entries around , so that is a relative error of about , which is machine precision, not degradation. And the last line: from an LU factorisation gives where the product of the eigenvalues gives exactly .
See it move
Section titled “See it move”The first sketch is the three-step loop with a slider that interpolates through it, so you can see which step does what.
The second sketch is the payoff: watch collapse onto the dominant eigendirection.
And the stepped version on Example 4.11, with the det/trace checks and the diagonalisability verdict:
Symmetric, two distinct eigenvalues, orthogonal eigenvectors — the case Theorem 4.21 guarantees. The final frame confirms the eigenspace dimensions add to 2.
From scratch
Section titled “From scratch”import numpy as np
def eigendecompose(A, tol=1e-8):
"""Theorem 4.20, with its hypothesis actually checked."""
A = np.asarray(A, dtype=float)
n = A.shape[0]
symmetric = bool(np.allclose(A, A.T))
# Theorem 4.21: for symmetric input use eigh, which returns an ONB.
vals, vecs = (np.linalg.eigh(A) if symmetric else np.linalg.eig(A))
if np.any(np.abs(np.imag(vals)) > 1e-12):
raise ValueError("complex eigenvalues: not diagonalizable over the reals")
vals = np.real(vals)
vecs = np.real(vecs)
# The hypothesis: do the eigenvectors form a basis?
independent = 0
for lam in np.unique(np.round(vals, 8)):
independent += n - np.linalg.matrix_rank(A - lam * np.eye(n), tol=tol)
if independent < n:
raise ValueError(f"defective: {independent} independent eigenvectors, {n} needed")
P, D = vecs, np.diag(vals)
Pinv = P.T if symmetric else np.linalg.inv(P)
return P, D, Pinv, symmetric
cases = {
"Ex 4.11 [[2,1],[1,2]]": [[2.0, 1], [1, 2]],
"Ex 4.5 [[4,2],[1,3]]": [[4.0, 2], [1, 3]],
"Ex 4.6 [[2,1],[0,2]]": [[2.0, 1], [0, 2]],
"Ex 4.8 3x3 symmetric": [[3.0, 2, 2], [2, 3, 2], [2, 2, 3]],
"rotation by 30 deg": [[np.cos(np.pi / 6), -np.sin(np.pi / 6)],
[np.sin(np.pi / 6), np.cos(np.pi / 6)]],
}
for name, A in cases.items():
A = np.asarray(A, dtype=float)
try:
P, D, Pinv, sym = eigendecompose(A)
gap = float(np.abs(P @ D @ Pinv - A).max())
orth = float(np.abs(P.T @ P - np.eye(A.shape[0])).max())
print(f"{name:24} OK symmetric {str(sym):5} "
f"|P D P^-1 - A| {gap:.1e} |P^T P - I| {orth:.1e} "
f"det from D {float(np.prod(np.diag(D))):+.4f}")
except ValueError as e:
print(f"{name:24} NO {e}")Ex 4.11 [[2,1],[1,2]] OK symmetric True |P D P^-1 - A| 4.4e-16 |P^T P - I| 2.2e-16 det from D +3.0000
Ex 4.5 [[4,2],[1,3]] OK symmetric False |P D P^-1 - A| 8.9e-16 |P^T P - I| 3.2e-01 det from D +10.0000
Ex 4.6 [[2,1],[0,2]] NO defective: 1 independent eigenvectors, 2 needed
Ex 4.8 3x3 symmetric OK symmetric True |P D P^-1 - A| 3.6e-15 |P^T P - I| 5.6e-16 det from D +7.0000
rotation by 30 deg NO complex eigenvalues: not diagonalizable over the realsThe column to read is . For the two symmetric matrices it is at machine precision — is orthogonal, exactly as Theorem 4.21 promises. For the non-symmetric Example 4.5 it is : is perfectly invertible and the decomposition is perfectly valid, but the change of basis is not a rotation — the two eigendirections meet at rather than , so their inner product is instead of . That is the difference between Theorem 4.20 and Theorem 4.21, visible as one number.
On real data
Section titled “On real data”Reading the plot
Section titled “Reading the plot”From the three-step figure. The eigenvector arrows are the thing to follow. In the first panel they point in two oblique directions; in the second they lie on the coordinate axes, which is what “change into the eigenbasis” means; in the third they have been stretched by and ; in the fourth they are back where they started, longer. The disc becomes an ellipse whose axes are the eigenvectors — and it becomes axis-aligned only in the middle two panels.
The measured numbers close the loop: the largest disagreement between and the three-step chain, over points, is . And , confirming the matrix is symmetric enough for to be used.
From the matrix-power figure. Two separate claims.
Accuracy. Over a thousand powers the two routes agree to relative. There is no drift: repeated multiplication accumulates rounding error and the eigen route accumulates a different rounding error, and both stay at machine precision because this matrix has spectral radius and its powers decay rather than grow.
Cost. The crossover for is , and it is worth reading the counts rather than the curves: at repeated multiplication needs multiplications against the eigen route’s ; at it is against . The eigen route pays a large fixed cost — about for the decomposition plus reassembly — and then almost nothing per power.
But the real argument for Equation 4.62 is not the flop count. It is that the eigen route gives an algebraic answer: for the worked example, valid for every at once, which no amount of matrix multiplication produces.
From the defectiveness figure. This is the figure that recalibrates the hypothesis. Textbooks introduce “non-defective” as a condition to worry about, and the measurement says:
| construction | percent defective |
|---|---|
| random Gaussian entries | ( of ) |
| small integer entries | ( of ) |
| built with a repeated eigenvalue, diagonalizable by construction | ( of ) |
| a Jordan block, defective by construction | ( of ) |
The last two denominators are smaller because those two families conjugate a diagonal matrix by a random and skip the draw when rather than test through a near-singular conjugation. Counting a skipped draw as non-defective would have shown the last bar at and made a missing sample look like a numerical effect.
Defectiveness is not something random matrices do. It requires an exactly repeated eigenvalue, which requires exact arithmetic coincidences — so it happens for small-integer matrices of the time and essentially never for continuous entries. What it is common in is structured matrices, which is where your data actually comes from.
Even so the last bar falls short of its . That residue is not a counterexample — it is the tolerance. A badly conditioned conjugation makes the deficient eigenspace look full at any fixed threshold, which is the pitfall below.
Pitfalls
Section titled “Pitfalls”Compare
Section titled “Compare”| eigendecomposition | SVD | |
|---|---|---|
| exists for | square and non-defective | every matrix |
| shape | one space to itself | domain to codomain, possibly different dimensions |
| outer factors | invertible, generally not orthogonal | both orthogonal, so both are rotations |
| are the outer factors inverse to each other? | yes, and | no — different spaces |
| middle factor | eigenvalues, possibly negative or complex | singular values, real and non-negative |
| for a symmetric positive definite matrix | the same thing | the same thing |
| gives matrix powers? | yes, | not directly |
| gives best low-rank approximation? | no | yes, §4.6 |
The last two rows are why both exist. §4.5 takes up the right-hand column.
-
Why must the columns of P be eigenvectors, rather than merely some convenient basis?
Equations 4.51 and 4.52 do the multiplication. AP has columns A p-i and PD has columns lambda-i p-i, so equating them is the eigenvalue equation n times over.
pch.quizShowAnswer
B — Because multiplying out AP = PD column by column gives A p-i = lambda-i p-i for every i — the equation itself forces it, and nothing else satisfies it — Equations 4.51 and 4.52 do the multiplication. AP has columns A p-i and PD has columns lambda-i p-i, so equating them is the eigenvalue equation n times over.
-
Theorem 4.20's hypothesis is that the eigenvectors form a basis. Where does that requirement come from?
So the hypothesis is exactly the negation of Definition 4.13's 'defective'. Distinct eigenvalues are sufficient by Theorem 4.12 but not necessary; what matters is that the eigenspace dimensions add to n.
pch.quizShowAnswer
B — From needing P to be invertible: Definition 4.19 requires an invertible P, invertible means full rank, and full rank for an n by n matrix means n linearly independent columns — which are the eigenvectors — So the hypothesis is exactly the negation of Definition 4.13's 'defective'. Distinct eigenvalues are sufficient by Theorem 4.12 but not necessary; what matters is that the eigenspace dimensions add to n.
-
For Example 4.5, [[4,2],[1,3]], the decomposition works but P-transpose P differs from the identity by 0.3162. What does that mean?
The reconstruction gap is 8.9e-16, so the factorisation is fine. Only the symmetric cases in that table have P-transpose P at machine precision, which is Theorem 4.21 being the stronger statement.
pch.quizShowAnswer
B — P is invertible, so Theorem 4.20 holds, but the matrix is not symmetric so Theorem 4.21 does not apply and P is not orthogonal — meaning P-inverse is not P-transpose and the change of basis shears as well as turns — The reconstruction gap is 8.9e-16, so the factorisation is fine. Only the symmetric cases in that table have P-transpose P at machine precision, which is Theorem 4.21 being the stronger statement.
-
Random 4x4 Gaussian matrices were never defective in 4000 trials; small-integer ones were 2.7% of the time. Why the difference?
Which recalibrates the hypothesis: defectiveness is not a hazard of random data, it is a hazard of structured data, and structured is where real matrices come from.
pch.quizShowAnswer
B — Defectiveness needs an exactly repeated eigenvalue, which needs an exact arithmetic coincidence — impossible for continuous entries and merely uncommon for a small integer range — Which recalibrates the hypothesis: defectiveness is not a hazard of random data, it is a hazard of structured data, and structured is where real matrices come from.
-
The eigen route to A-to-the-k becomes cheaper than repeated multiplication at k = 14 for n = 6. Is that the main argument for Equation 4.62?
The measured values confirm the formula: 2, 5, 122, 29525 and 1743392201 at k = 1, 2, 5, 10 and 20. The flop crossover is real but secondary.
pch.quizShowAnswer
B — No. The stronger argument is that it gives an algebraic formula — for the worked example the (1,1) entry of A-to-the-k is exactly one half of one plus three to the k, valid for every k at once, which no number of matrix multiplications produces — The measured values confirm the formula: 2, 5, 122, 29525 and 1743392201 at k = 1, 2, 5, 10 and 20. The flop crossover is real but secondary.
🧪 Try It Yourself
Section titled “🧪 Try It Yourself”Exercise 1 – Example 4.11 in three steps
Section titled “Exercise 1 – Example 4.11 in three steps”Exercise 2 – A closed form for the k-th power
Section titled “Exercise 2 – A closed form for the k-th power”Exercise 3 – Check the hypothesis before trusting the factorisation
Section titled “Exercise 3 – Check the hypothesis before trusting the factorisation”Exercise 4 – What numpy does with a defective matrix
Section titled “Exercise 4 – What numpy does with a defective matrix”Exercise 5 – Powers collapse onto the dominant eigenvector
Section titled “Exercise 5 – Powers collapse onto the dominant eigenvector”Recall card
Section titled “Recall card”- Diagonalizable means similar to a diagonal matrix: there is an invertible P with D equal to P-inverse A P, and similar matrices share their determinant, trace and spectrum.
- The columns of P must be eigenvectors, because multiplying out A P = P D column by column gives the eigenvalue equation n times over.
- Theorem 4.20 is an if and only if: the factorisation exists exactly when the eigenvectors form a basis — that is, exactly when the matrix is not defective.
- Theorem 4.21: a symmetric matrix can always be diagonalized, and the spectral theorem makes P orthogonal, so P-inverse becomes P-transpose and no inverse is ever computed.
- The geometry is three steps: P-inverse changes into the eigenbasis, D scales along those axes, P changes back. Only for a symmetric matrix are the two outer steps rotations.
- A to the k equals P D-to-the-k P-inverse, because the inner pairs cancel — and that gives an algebraic formula, not merely a faster loop.
- The determinant is the product of D’s diagonal, which is Theorem 4.16 arriving by another route.
- Defectiveness is rare in random matrices and common in structured ones: zero of four thousand Gaussian matrices, 2.675 percent of small-integer ones, and 99.37 percent of Jordan blocks — and it is not numerically decidable, since a badly conditioned conjugation makes a deficient eigenspace look full at any fixed tolerance.
- P orthogonal follows from symmetry, not from diagonalizability. For the non-symmetric Example 4.5, P-transpose P differs from the identity by 0.3162, because its two eigendirections meet at 71.6 degrees rather than 90.
- Repeated eigenvalues make P non-unique up to a rotation within the eigenspace, which is a reproducibility hazard for anything reading individual eigenvector components.
Next: Singular Value Decomposition — the same idea with both hypotheses dropped.
pch.coffeeTagline
pch.coffeeCtapch.feedbackHeading
pch.feedbackSubheading