32. Symmetric matrices and the Spectral Theorem

📖 Reading · 9 min
💡 Every code box below is live — edit it and hit Run.

Module 19's diagonalization worked only sometimes — repeated eigenvalues could be defective (§19.2), and even when diagonalizable, nothing guaranteed the eigenvector basis was orthogonal. This lesson identifies the one broad class of matrices where every obstruction vanishes at once: symmetric matrices, A^T=A (§16.2), are always diagonalizable, with an eigenbasis that's automatically orthogonal.

The Spectral Theorem

Theorem. If A is a real symmetric matrix, then A has n real eigenvalues (counted with multiplicity) and an orthonormal eigenbasis. Consequently A=Q\Lambda Q^T, where Q's columns are orthonormal eigenvectors and \Lambda=\operatorname{diag}(\lambda_1, > \dots,\lambda_n).

This is strictly stronger than §19.1's diagonalization A=PDP^{-1} in two ways at once: P can always be taken orthogonal (Q^{-1}=Q^T, §20.4), and this works for every symmetric matrix, with no exceptions for repeated eigenvalues — symmetric matrices are never defective (§19.2).

Two supporting facts, both worth seeing proved

Eigenvalues of a real symmetric matrix are real (not obvious — Modules 16-19 never ruled out complex eigenvalues, and §18.2's rotation matrix is an example with complex ones, but it isn't symmetric). Sketch: for A\vec v=\lambda\vec v with \vec v possibly complex, \bar{\vec v}^TA\vec v=\lambda\bar{\vec v}^T\vec v; taking the complex conjugate of both sides and using A^T=A (real, symmetric) shows \lambda=\bar\lambda, forcing \lambda real.

Eigenvectors for distinct eigenvalues of a symmetric matrix are automatically orthogonal. Let A\vec v_1=\lambda_1\vec v_1, A\vec v_2=\lambda_2\vec v_2, \lambda_1\neq\lambda_2. Then

\lambda_1(\vec v_1\cdot\vec v_2)=(A\vec v_1)\cdot\vec v_2=\vec v_1\cdot(A^T\vec v_2)=\vec v_1\cdot(A\vec v_2)=\lambda_2(\vec v_1\cdot\vec v_2)

using \vec u\cdot(A\vec w)=(A^T\vec u)\cdot\vec w (§20.0's dot product written as \vec u^TA\vec w, then A^T moved across via transpose rules, §16.2) and A^T=A in the middle step. So (\lambda_1-\lambda_2)(\vec v_1\cdot\vec v_2)=0; since \lambda_1\neq\lambda_2, \vec v_1\cdot\vec v_2=0forced, not just possible. (For a repeated eigenvalue, eigenvectors within the same eigenspace aren't automatically orthogonal, but §20.3's Gram-Schmidt can always be run inside that eigenspace to make them so — this is the remaining piece the full theorem needs, not shown here.)

Building the orthogonal diagonalization

  1. Find all eigenvalues (§19.0) — guaranteed real.
  2. For each eigenvalue, find a basis of its eigenspace (§19.2) — guaranteed enough vectors, since symmetric matrices are never defective.
  3. Within each eigenspace, Gram-Schmidt (§20.3) and normalize (§20.4) if the eigenspace has dimension >1.
  4. Eigenvectors from different eigenspaces are already orthogonal (proved above) — no cross-eigenspace work needed.
  5. Stack every resulting unit eigenvector as a column of Q.

Doing it in Python

import numpy as np

A = np.array([[2., 1.], [1., 2.]])   # symmetric

eigvals, eigvecs = np.linalg.eigh(A)   # eigh: for symmetric/Hermitian matrices
print("eigenvalues:", eigvals.tolist())
print("Q =")
for row in eigvecs.tolist():
    print([round(v, 4) for v in row])

print("\nQ^T Q == I:", bool(np.allclose(eigvecs.T @ eigvecs, np.eye(2))))
reconstructed = eigvecs @ np.diag(eigvals) @ eigvecs.T
print("Q Lambda Q^T == A:", bool(np.allclose(reconstructed, A)))
eigenvalues: [1.0, 3.0]
Q =
[-0.7071, 0.7071]
[0.7071, 0.7071]

Q^T Q == I: True
Q Lambda Q^T == A: True

Confirming eigenvectors from distinct eigenvalues are orthogonal, for a 3\times3 example:

import numpy as np

A = np.array([[4., 1., 0.], [1., 4., 1.], [0., 1., 4.]])
eigvals, eigvecs = np.linalg.eigh(A)

print("eigenvalues:", [round(v, 4) for v in eigvals.tolist()])
for i in range(3):
    for j in range(i + 1, 3):
        dot = eigvecs[:, i] @ eigvecs[:, j]
        print(f"v{i} . v{j} = {round(float(dot), 10) or 0.0}")
eigenvalues: [2.5858, 4.0, 5.4142]
v0 . v1 = 0.0
v0 . v2 = 0.0
v1 . v2 = 0.0

Worked example

Orthogonally diagonalize A=\begin{pmatrix}3&1\\1&3\end{pmatrix}.

\operatorname{tr}A=6, \det A=9-1=8. \lambda^2-6\lambda+8=0\Rightarrow(\lambda-2)(\lambda-4)=0\Rightarrow\lambda=2,4.

\lambda=2: (A-2I)\vec v=\vec0: \begin{pmatrix}1&1\\1&1\end{pmatrix}\vec v=\vec0\Rightarrow v_1=-v_2. \vec v_1=(1,-1), normalized: \vec q_1=\frac1{\sqrt2}(1,-1).

\lambda=4: (A-4I)\vec v=\vec0: \begin{pmatrix}-1&1\\1&-1\end{pmatrix}\vec v=\vec0\Rightarrow v_1=v_2. \vec v_2=(1,1), normalized: \vec q_2=\frac1{\sqrt2}(1,1).

\boxed{Q=\frac1{\sqrt2}\begin{pmatrix}1&1\\-1&1\end{pmatrix},\quad\Lambda=\begin{pmatrix}2&0\\0&4\end{pmatrix}}

Sanity check. \vec q_1\cdot\vec q_2=\frac12(1(1)+(-1)(1))=0 ✓ orthogonal, exactly as the distinct-eigenvalue theorem guarantees without needing to check. Q^TQ=\frac12\begin{pmatrix}1&-1\\1&1\end{pmatrix}\begin{pmatrix}1&1\\-1&1\end{pmatrix}=\frac12\begin{pmatrix}2&0\\0&2\end{pmatrix}=I ✓, confirming Q^{-1}=Q^T so A=Q\Lambda Q^T genuinely holds.

Your turn

1. Without computing anything, explain why A=\begin{pmatrix}1&2\\3&4\end{pmatrix} (not symmetric) is not guaranteed real eigenvalues by this lesson's theorem.

2. A symmetric 3\times3 matrix has eigenvalues 1,1,5. What is \dim E_1 (the eigenspace for \lambda=1)? How do you know, without computing it directly?

3. True or false: every diagonalizable matrix has an orthogonal eigenbasis.

Solutions

1. A^T=\begin{pmatrix}1&3\\2&4\end{pmatrix}\neq A — not symmetric, so the Spectral Theorem's hypothesis fails and its conclusion isn't guaranteed (this particular A does happen to have real eigenvalues, but that's not something the theorem promises for non-symmetric matrices in general — §18.2's rotation matrix is the standard counterexample where it fails outright).

2. \dim E_1=2. Symmetric matrices are never defective (stated in this lesson), so geometric multiplicity always equals algebraic multiplicity for every eigenvalue — and \lambda=1 has algebraic multiplicity 2 (it's a repeated root), so its geometric multiplicity must also be 2, guaranteed without ever computing \operatorname{Null}(A-I) directly.

3. False. Diagonalizability alone only guarantees some independent eigenbasis (§19.1) — nothing about orthogonality. A non-symmetric matrix can be diagonalizable with a skewed (non-orthogonal) eigenbasis; symmetry is what upgrades "some eigenbasis" to "an orthogonal one," and it's a genuinely extra condition, not automatic from diagonalizability alone.

Check yourself in code

Orthogonally diagonalize A=\begin{pmatrix}5&2\\2&5\end{pmatrix}: find the eigenvalues and confirm the eigenvectors are orthogonal.

Print exactly this:

eigenvalues: [3.0, 7.0]
v0 . v1 = 0.0
import numpy as np

A = np.array([[5., 2.], [2., 5.]])
eigvals, eigvecs = np.linalg.eigh(A)

print("eigenvalues:", eigvals.tolist())
# print the dot product of the two eigenvectors (columns of eigvecs), rounded
import numpy as np

A = np.array([[5., 2.], [2., 5.]])
eigvals, eigvecs = np.linalg.eigh(A)

print("eigenvalues:", eigvals.tolist())
dot = eigvecs[:, 0] @ eigvecs[:, 1]
print("v0 . v1 =", round(float(dot), 10))

The Spectral Theorem says every real symmetric matrix has real eigenvalues and an orthonormal eigenbasis, giving A=Q\Lambda Q^T — never defective, and always orthogonally diagonalizable, strictly stronger than §19.1's general diagonalization. Eigenvectors for distinct eigenvalues are automatically orthogonal; within a repeated eigenspace, Gram-Schmidt finishes the job.

Next, extending this same theorem to the natural complex analogue — Hermitian and unitary matrices — where transpose is replaced by conjugate transpose throughout.