AI Knowledge Tree

Diagonalization & the spectral theorem

Prove that real symmetric matrices have real eigenvalues and an orthonormal eigenbasis, giving A = QΛQᵀ.

Diagonalization turns nn coupled equations into nn 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 A∈Rn×nA \in \mathbb{R}^{n \times n} is diagonalizable if there exist an invertible matrix PP and a diagonal matrix Λ\Lambda such that

A=PΛP−1,equivalently, AP=PΛ.A = P\Lambda P^{-1}, \qquad \text{equivalently, } AP = P\Lambda.

The columns of PP are eigenvectors of AA (column jj of AP=PΛAP = P\Lambda says Apj=λjpjAp_j = \lambda_j p_j), and the diagonal entries of Λ\Lambda are the corresponding eigenvalues.

A matrix is diagonalizable if and only if it has nn linearly independent eigenvectors. Eigenvectors from distinct eigenvalues are automatically independent (proof below), so a matrix with nn distinct eigenvalues is diagonalizable.

Independence of eigenvectors for distinct eigenvalues. Suppose Avi=λiviA v_i = \lambda_i v_i for i=1,…,ki = 1, \dots, k with λi\lambda_i all different, and suppose ∑civi=0\sum c_i v_i = 0. Apply A−λ1IA - \lambda_1 I to both sides: ∑i=2kci(λi−λ1)vi=0\sum_{i=2}^k c_i(\lambda_i - \lambda_1) v_i = 0. Repeat with A−λ2IA - \lambda_2 I, and so on, until you isolate each cic_i multiplying a nonzero vector; each must be zero. By induction, ci=0c_i = 0 for all ii.

The spectral theorem for real symmetric matrices

Theorem. If A∈Rn×nA \in \mathbb{R}^{n \times n} is symmetric (A=A⊤A = A^\top), then[1, 2]:

  1. All eigenvalues of AA are real.
  2. Eigenvectors for distinct eigenvalues are orthogonal.
  3. There exists an orthonormal basis of Rn\mathbb{R}^n consisting of eigenvectors of AA.

Proof of (1): eigenvalues are real. Let λ\lambda be an eigenvalue (possibly complex) with eigenvector v∈Cnv \in \mathbb{C}^n (possibly complex). Using the conjugate transpose vˉ⊤\bar{v}^\top:

λ vˉ⊤v=vˉ⊤(Av)=vˉ⊤Av=(A⊤vˉ)⊤v=(Avˉ)⊤v=(Av)‾⊤v=λv‾⊤v=λˉ vˉ⊤v.\lambda\,\bar{v}^\top v = \bar{v}^\top(Av) = \bar{v}^\top A v = (A^\top\bar{v})^\top v = (A\bar{v})^\top v = \overline{(Av)}^\top v = \overline{\lambda v}^\top v = \bar\lambda\,\bar{v}^\top v.

Since v≠0v \neq 0, vˉ⊤v=∥v∥2>0\bar{v}^\top v = \lVert v\rVert^2 > 0, so λ=λˉ\lambda = \bar\lambda, meaning λ\lambda is real.

Proof of (2): eigenvectors for distinct eigenvalues are orthogonal. Let Av1=λ1v1Av_1 = \lambda_1 v_1 and Av2=λ2v2Av_2 = \lambda_2 v_2 with λ1≠λ2\lambda_1 \neq \lambda_2. Then:

λ1⟨v1,v2⟩=⟨Av1,v2⟩=v1⊤A⊤v2=v1⊤Av2=⟨v1,Av2⟩=λ2⟨v1,v2⟩.\lambda_1\langle v_1, v_2\rangle = \langle Av_1, v_2\rangle = v_1^\top A^\top v_2 = v_1^\top A v_2 = \langle v_1, Av_2\rangle = \lambda_2\langle v_1, v_2\rangle.

So (λ1−λ2)⟨v1,v2⟩=0(\lambda_1 - \lambda_2)\langle v_1, v_2\rangle = 0; since λ1≠λ2\lambda_1 \neq \lambda_2, the inner product is zero.

Proof of (3) (sketch): induct on nn. For n=1n=1 it is trivial. For n>1n > 1: pick any real eigenvalue λ1\lambda_1 (guaranteed by (1)) with eigenvector q1q_1 (normalized). The subspace W=q1⊥W = q_1^\perp is invariant under AA: if w⊥q1w \perp q_1 then ⟨Aw,q1⟩=⟨w,Aq1⟩=λ1⟨w,q1⟩=0\langle Aw, q_1\rangle = \langle w, Aq_1\rangle = \lambda_1\langle w, q_1\rangle = 0. Restrict AA to WW (an (n−1)(n-1)-dimensional symmetric operator), apply the induction hypothesis, and concatenate. ■\qquad\blacksquare

The spectral decomposition

Collecting the orthonormal eigenbasis into columns of QQ:

A=QΛQ⊤,A = Q\Lambda Q^\top,

where Q⊤Q=IQ^\top Q = I and Λ=diag⁡(λ1,…,λn)\Lambda = \operatorname{diag}(\lambda_1, \dots, \lambda_n).

Expanding:

A=∑i=1nλiqiqi⊤.A = \sum_{i=1}^n \lambda_i q_i q_i^\top.

Each term qiqi⊤q_i q_i^\top is the projection matrix onto the ii-th eigenvector direction. The matrix AA is a weighted sum of rank-1 projections, with weights given by the eigenvalues.

A symmetric matrix has orthogonal eigenvectors: A = QΛQᵀ maps the unit circle to an ellipse whose perpendicular axes lie along the eigenvectors, with lengths equal to the eigenvalues λ = 3 and 1.
A symmetric matrix has orthogonal eigenvectors: A = QΛQᵀ maps the unit circle to an ellipse whose perpendicular axes lie along the eigenvectors, with lengths equal to the eigenvalues λ = 3 and 1.

Check it on arrays

python · numpy
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-15

The reconstruction from the spectral decomposition recovers AA to machine precision.

Exercises

Exercise 1. Diagonalize A=[2112]A = \begin{bmatrix} 2 & 1 \\ 1 & 2 \end{bmatrix} by hand: find its eigenvalues and an orthonormal eigenbasis, and write A=QΛQ⊤A = Q\Lambda Q^\top.

Solution

Step 1. Eigenvalues from det⁡(A−λI)=0\det(A - \lambda I) = 0: (2−λ)2−1=0(2 - \lambda)^2 - 1 = 0, so 2−λ=±12 - \lambda = \pm 1, giving λ1=3\lambda_1 = 3 and λ2=1\lambda_2 = 1. Both are real, as the spectral theorem guarantees for a symmetric matrix.

Step 2. Eigenvector for λ1=3\lambda_1 = 3: solve (A−3I)v=0(A - 3I)v = 0, i.e. [−111−1]v=0\begin{bmatrix} -1 & 1 \\ 1 & -1 \end{bmatrix} v = 0, giving v1∝(1,1)v_1 \propto (1, 1). Normalized: q1=12(1,1)q_1 = \tfrac{1}{\sqrt 2}(1, 1).

Step 3. Eigenvector for λ2=1\lambda_2 = 1: solve (A−I)v=0(A - I)v = 0, i.e. [1111]v=0\begin{bmatrix} 1 & 1 \\ 1 & 1 \end{bmatrix} v = 0, giving v2∝(1,−1)v_2 \propto (1, -1). Normalized: q2=12(1,−1)q_2 = \tfrac{1}{\sqrt 2}(1, -1). The two are orthogonal, as required for distinct eigenvalues.

Step 4. Assemble:

Q=12[111−1],Λ=[3001],A=QΛQ⊤.Q = \frac{1}{\sqrt 2}\begin{bmatrix} 1 & 1 \\ 1 & -1 \end{bmatrix}, \qquad \Lambda = \begin{bmatrix} 3 & 0 \\ 0 & 1 \end{bmatrix}, \qquad A = Q\Lambda Q^\top.

Exercise 2. Using the spectral decomposition A=∑iλiqiqi⊤A = \sum_i \lambda_i q_i q_i^\top, prove that tr⁡(A)=∑iλi\operatorname{tr}(A) = \sum_i \lambda_i for a symmetric AA.

Solution

Step 1. Take the trace of the decomposition and use linearity: tr⁡(A)=∑iλitr⁡(qiqi⊤)\operatorname{tr}(A) = \sum_i \lambda_i \operatorname{tr}(q_i q_i^\top).

Step 2. Evaluate each rank-1 trace with the cyclic property tr⁡(qiqi⊤)=tr⁡(qi⊤qi)=qi⊤qi=∥qi∥2=1\operatorname{tr}(q_i q_i^\top) = \operatorname{tr}(q_i^\top q_i) = q_i^\top q_i = \lVert q_i \rVert^2 = 1, since the qiq_i are unit vectors.

Step 3. Therefore tr⁡(A)=∑iλi⋅1=∑iλi\operatorname{tr}(A) = \sum_i \lambda_i \cdot 1 = \sum_i \lambda_i. The trace equals the sum of eigenvalues.

Exercise 3 (code). For a random symmetric 4×44 \times 4 matrix, verify with np.linalg.eigh that (i) the eigenvalues are real, (ii) the eigenvector matrix QQ is orthogonal, and (iii) eigenvectors for distinct eigenvalues are orthogonal.

Solution

Symmetrizing 12(M+M⊤)\tfrac12(M + M^\top) produces a symmetric matrix, so the spectral theorem applies: real eigenvalues and an orthonormal eigenbasis, hence Q⊤Q=IQ^\top Q = I.

python · numpy
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, Q⊤QQ^\top Q is the identity, and the zero off-diagonals of Q⊤QQ^\top Q 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. [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. [2]Horn, R. A., & Johnson, C. R. (2012). Matrix Analysis (2nd ed.). Cambridge University Press. Diagonalization and the spectral decomposition of symmetric matrices.↩