Diagonalization & the spectral theorem
Prove that real symmetric matrices have real eigenvalues and an orthonormal eigenbasis, giving A = QΛQᵀ.
Diagonalization turns coupled equations into independent ones, and symmetric matrices are the class where diagonalization is always possible with an orthonormal basis. This is the spectral theorem, the cornerstone of PCA, covariance analysis, and quadratic-form optimization.
Diagonalization
A matrix is diagonalizable if there exist an invertible matrix and a diagonal matrix such that
The columns of are eigenvectors of (column of says ), and the diagonal entries of are the corresponding eigenvalues.
A matrix is diagonalizable if and only if it has linearly independent eigenvectors. Eigenvectors from distinct eigenvalues are automatically independent (proof below), so a matrix with distinct eigenvalues is diagonalizable.
Independence of eigenvectors for distinct eigenvalues. Suppose for with all different, and suppose . Apply to both sides: . Repeat with , and so on, until you isolate each multiplying a nonzero vector; each must be zero. By induction, for all .
The spectral theorem for real symmetric matrices
Theorem. If is symmetric (), then[1, 2]:
- All eigenvalues of are real.
- Eigenvectors for distinct eigenvalues are orthogonal.
- There exists an orthonormal basis of consisting of eigenvectors of .
Proof of (1): eigenvalues are real. Let be an eigenvalue (possibly complex) with eigenvector (possibly complex). Using the conjugate transpose :
Since , , so , meaning is real.
Proof of (2): eigenvectors for distinct eigenvalues are orthogonal. Let and with . Then:
So ; since , the inner product is zero.
Proof of (3) (sketch): induct on . For it is trivial. For : pick any real eigenvalue (guaranteed by (1)) with eigenvector (normalized). The subspace is invariant under : if then . Restrict to (an -dimensional symmetric operator), apply the induction hypothesis, and concatenate.
The spectral decomposition
Collecting the orthonormal eigenbasis into columns of :
where and .
Expanding:
Each term is the projection matrix onto the -th eigenvector direction. The matrix is a weighted sum of rank-1 projections, with weights given by the eigenvalues.
Check it on arrays
import numpy as np
# A real symmetric matrix
A = np.array([[4.0, 2.0, 0.0],
[2.0, 3.0, 1.0],
[0.0, 1.0, 2.0]])
eigenvalues, Q = np.linalg.eigh(A) # eigh exploits symmetry: real output, sorted
print("eigenvalues:", np.round(eigenvalues, 6))
# Verify Q is orthogonal
print("Q^T Q:\n", np.round(Q.T @ Q, 10)) # identity
# Reconstruct: A = Q Lam Q^T
A_reconstructed = Q @ np.diag(eigenvalues) @ Q.T
print("reconstruction error:", np.max(np.abs(A - A_reconstructed))) # ~1e-15
# Spectral decomposition: sum of rank-1 projections
A_spectral = sum(lam * np.outer(Q[:, i], Q[:, i])
for i, lam in enumerate(eigenvalues))
print("spectral sum error:", np.max(np.abs(A - A_spectral))) # ~1e-15The reconstruction from the spectral decomposition recovers to machine precision.
Exercises
Exercise 1. Diagonalize by hand: find its eigenvalues and an orthonormal eigenbasis, and write .
Solution
Step 1. Eigenvalues from : , so , giving and . Both are real, as the spectral theorem guarantees for a symmetric matrix.
Step 2. Eigenvector for : solve , i.e. , giving . Normalized: .
Step 3. Eigenvector for : solve , i.e. , giving . Normalized: . The two are orthogonal, as required for distinct eigenvalues.
Step 4. Assemble:
Exercise 2. Using the spectral decomposition , prove that for a symmetric .
Solution
Step 1. Take the trace of the decomposition and use linearity: .
Step 2. Evaluate each rank-1 trace with the cyclic property , since the are unit vectors.
Step 3. Therefore . The trace equals the sum of eigenvalues.
Exercise 3 (code). For a random symmetric matrix, verify with
np.linalg.eigh that (i) the eigenvalues are real, (ii) the eigenvector matrix
is orthogonal, and (iii) eigenvectors for distinct eigenvalues are
orthogonal.
Solution
Symmetrizing produces a symmetric matrix, so the spectral theorem applies: real eigenvalues and an orthonormal eigenbasis, hence .
import numpy as np
rng = np.random.default_rng(0)
M = rng.normal(size=(4, 4))
A = 0.5 * (M + M.T) # symmetric
w, Q = np.linalg.eigh(A)
# (i) eigenvalues are real: eigh returns real arrays for symmetric input.
assert np.isrealobj(w)
# (ii) Q is orthogonal: Q^T Q = I.
assert np.allclose(Q.T @ Q, np.eye(4), atol=1e-12)
# (iii) distinct eigenvalues -> orthogonal eigenvectors (off-diagonals ~ 0).
gram = Q.T @ Q
assert np.allclose(gram - np.diag(np.diag(gram)), 0, atol=1e-12)
print("eigenvalues:", np.round(w, 6))The eigenvalues are real, is the identity, and the zero off-diagonals of confirm mutual orthogonality of the eigenvectors, all three conclusions of the spectral theorem.
The eigenvalue signs in that decomposition determine whether the associated quadratic form is positive definite, the subject of the next lesson.
References
- [1]Axler, S. (2015). Linear Algebra Done Right (3rd ed.), ch. 7. Springer. The spectral theorem for self-adjoint operators (doi:10.1007/978-3-319-11080-6).↩
- [2]Horn, R. A., & Johnson, C. R. (2012). Matrix Analysis (2nd ed.). Cambridge University Press. Diagonalization and the spectral decomposition of symmetric matrices.↩