Eigendecomposition and Diagonalization
The eigendecomposition writes a square matrix as : a change into the eigenbasis (), a pure scaling along each eigen-axis (, diagonal), and a change back (). In this coordinate system the matrix is diagonal — the simplest possible form. That’s what makes matrix powers trivial, PCA computable, and the geometry of a transformation obvious.
A real-life example: predicting a population years ahead
A wildlife model updates a population vector each year by multiplying by a transition matrix . To predict 50 years out you’d need — 50 matrix multiplies. But if , then , and is just each diagonal entry raised to the 50th power. The eigendecomposition turns “multiply 50 times” into “raise a few numbers to a power.” Long-term behavior is dictated by the largest eigenvalue.
Diagonal matrices are easy
A diagonal matrix has zeros off the diagonal. Everything about it is cheap: its determinant is the product of the diagonal, its power raises each diagonal entry to the , and its inverse is the reciprocal of each entry. The goal of diagonalization is to transform a general matrix into a diagonal one by choosing the right basis.
The eigendecomposition
A matrix is diagonalizable if it has linearly independent eigenvectors. Collect them as the columns of and the eigenvalues on the diagonal of ; then
If is symmetric, the spectral theorem gives an orthonormal eigenbasis, so is orthogonal and :
The geometry: rotate, scale, rotate back
For a symmetric , applying it to the unit circle produces an ellipse whose axes point along the eigenvectors and whose half-lengths are the eigenvalues. That’s the eigendecomposition made visible: rotates the eigenvectors onto the standard axes, stretches by the eigenvalues, and rotates back. Watch the circle become an ellipse aligned with the amber eigen-axes:
Matrix powers and other payoffs
Because , powers are cheap. So are:
- Determinant: .
- Matrix functions: , — apply the function to the eigenvalues.
flowchart LR X["x"] -->|"P⁻¹: to eigenbasis"| C1["eigen-coords"] C1 -->|"D: scale by λᵢ"| C2["scaled coords"] C2 -->|"P: back to standard"| Y["A x"]
Not every matrix is diagonalizable — defective matrices (too few independent eigenvectors) aren’t. But every symmetric matrix always is, which is exactly the case that matters most in ML.
NumPy
import numpy as np
A = np.array([[2.0, 1.0],
[1.0, 2.0]]) # symmetric
vals, P = np.linalg.eig(A)
D = np.diag(vals)
# reconstruct A = P D P^-1
A_rebuilt = P @ D @ np.linalg.inv(P)
print("A = P D P⁻¹:", np.allclose(A, A_rebuilt))
# matrix power the cheap way: A^5 = P D^5 P^-1
A5_fast = P @ np.diag(vals**5) @ np.linalg.inv(P)
A5_slow = np.linalg.matrix_power(A, 5)
print("A⁵ matches:", np.allclose(A5_fast, A5_slow))
# symmetric ⇒ orthogonal P, so P^-1 = P^T
w, Q = np.linalg.eigh(A)
print("A = Q D Qᵀ:", np.allclose(Q @ np.diag(w) @ Q.T, A))import numpy as np
A = np.array([[2.0, 1.0],
[1.0, 2.0]]) # symmetric
vals, P = np.linalg.eig(A)
D = np.diag(vals)
# reconstruct A = P D P^-1
A_rebuilt = P @ D @ np.linalg.inv(P)
print("A = P D P⁻¹:", np.allclose(A, A_rebuilt))
# matrix power the cheap way: A^5 = P D^5 P^-1
A5_fast = P @ np.diag(vals**5) @ np.linalg.inv(P)
A5_slow = np.linalg.matrix_power(A, 5)
print("A⁵ matches:", np.allclose(A5_fast, A5_slow))
# symmetric ⇒ orthogonal P, so P^-1 = P^T
w, Q = np.linalg.eigh(A)
print("A = Q D Qᵀ:", np.allclose(Q @ np.diag(w) @ Q.T, A))A = P D P⁻¹: True
A⁵ matches: True
A = Q D Qᵀ: TrueA = P D P⁻¹: True
A⁵ matches: True
A = Q D Qᵀ: TrueWhy this matters for ML
- PCA is the eigendecomposition of the covariance matrix; eigenvalues rank directions by variance.
- Spectral methods (clustering, embeddings) read structure from the eigendecomposition of graph Laplacians.
- Matrix powers / dynamics: the largest eigenvalue governs the long-run behavior of iterated linear systems (Markov chains, recurrent dynamics, PageRank).
🧪 Try It Yourself
Exercise 1 – Reconstruct A from P and D
Exercise 2 – Fast matrix powers
Exercise 3 – Not everything diagonalizes
Recap
- Eigendecomposition : columns of are eigenvectors, diagonal of the eigenvalues — the matrix is diagonal in its eigenbasis.
- Exists iff has independent eigenvectors; symmetric matrices always qualify with orthogonal ().
- Makes powers (), determinants, and matrix functions trivial.
- Underlies PCA, spectral methods, and linear-dynamics analysis.
Next: the decomposition that works for any matrix, square or not — Singular Value Decomposition.
If this helped you, consider buying me a coffee ☕
Buy me a coffeeWas this page helpful?
Let us know how we did
