AI Wiki中文/EN

The spectral theorem

谱定理

Use symmetry to obtain a complete orthonormal eigenbasis, reconstruct a matrix, and bound its quadratic form.

On this pageIntuitionMathematics & methodImplementationLimitationsExercisesResearch connections

A coupled calculation can become independent scaling

For A=[2112]A=\begin{bmatrix}2&1\\1&2\end{bmatrix}, the two output coordinates mix both inputs. Switch to the unit directions q1=(1,1)/2q_1=(1,1)/\sqrt2 and q2=(−1,1)/2q_2=(-1,1)/\sqrt2, however, and the same map multiplies one coordinate by three and the other by one. The mixing came from the coordinate frame, not from an inability to separate these two modes.

The real symmetric spectral theorem guarantees such an orthonormal eigenbasis for every real symmetric matrix. This is stronger than saying that some eigenvectors exist. It gives a complete basis, real eigenvalues, and an inverse basis change equal to a transpose. MML, Theorem 4.15 and Section 4.4

What symmetry guarantees

For A=A⊤∈Rn×nA=A^\top\in\mathbb R^{n\times n}, there is an orthogonal Q=[q1,…,qn]Q=[q_1,\ldots,q_n] and a real diagonal Λ\Lambda such that

A=QΛQ⊤=∑i=1nλiqiqi⊤,Q⊤Q=In.A=Q\Lambda Q^\top=\sum_{i=1}^{n}\lambda_iq_iq_i^\top,\qquad Q^\top Q=I_n.

The map qiqi⊤q_iq_i^\top projects onto one unit direction. The sum says: resolve a vector into these perpendicular components, scale each by its eigenvalue, then add them back. Conversely, a real matrix written as QΛQ⊤Q\Lambda Q^\top with real diagonal Λ\Lambda must be symmetric, as transposing the product shows. Deep Learning, Section 2.7

Why are distinct modes perpendicular? If Au=λuAu=\lambda u and Av=μvAv=\mu v, symmetry gives

λu⊤v=(Au)⊤v=u⊤Av=μu⊤v.\lambda u^\top v=(Au)^\top v=u^\top Av=\mu u^\top v.

For λ≠μ\lambda\ne\mu, this forces u⊤v=0u^\top v=0. That argument alone does not yet prove a complete eigenbasis exists. A proof sketch fills the gap: the continuous function x⊤Axx^\top Ax attains a maximum on the finite-dimensional unit sphere. At a maximizing unit vector, its derivative along every perpendicular direction is zero, forcing AxAx to be parallel to xx. Symmetry then makes the perpendicular subspace invariant: for y⊥xy\perp x, x⊤Ay=(Ax)⊤y=0x^\top Ay=(Ax)^\top y=0. Repeat within that smaller space, down to dimension one.

This proof uses the ordinary finite-dimensional Euclidean setting. Within a repeated-eigenvalue subspace, arbitrary eigenvectors need not already be perpendicular; choose an orthonormal basis inside it. Even distinct eigenvalues do not fix eigenvector signs. Sorting eigenvalues and normalizing vectors still leaves that freedom.

A complete 2×2 decomposition

For A=[abbd]A=\begin{bmatrix}a&b\\b&d\end{bmatrix}, the two eigenvalues are

λ±=a+d2±(a−d2)2+b2.\lambda_\pm=\frac{a+d}{2}\pm\sqrt{\left(\frac{a-d}{2}\right)^2+b^2}.

Choose the first column of QQ as (cos⁡θ,sin⁡θ)(\cos\theta,\sin\theta) with θ=12atan2⁡(2b,a−d)\theta=\tfrac12\operatorname{atan2}(2b,a-d); its perpendicular companion is the second column. This angle cancels the off-diagonal entry of Q⊤AQQ^\top AQ. The code scales inputs before forming these expressions and handles the zero matrix separately. It solves only real symmetric 2×2 matrices, not a general eigensolver.

import math

def symmetric_eigen2(a, b, d):
    # The input represents [[a,b],[b,d]], so symmetry is explicit.
    if not all(math.isfinite(x) for x in (a,b,d)):
        raise ValueError("finite real entries required")
    scale = max(abs(a),abs(b),abs(d))
    if scale == 0:
        return [0.,0.], [[1.,0.],[0.,1.]]
    p,q,r = a/scale,b/scale,d/scale
    theta = .5*math.atan2(2*q,p-r)
    c,s = math.cos(theta),math.sin(theta)
    middle = (p+r)/2
    radius = math.hypot((p-r)/2,q)
    values = [scale*(middle+radius),scale*(middle-radius)]
    if not all(math.isfinite(x) for x in values):
        raise ArithmeticError("eigenvalue overflow")
    return values, [[c,-s],[s,c]]  # eigenvectors are columns

def reconstruct(values, q):
    return [[sum(q[i][k]*values[k]*q[j][k] for k in range(2))
             for j in range(2)] for i in range(2)]

for a,b,d in [(2.,1.,2.),(2.,0.,2.),(2.,0.,-1.),(0.,0.,0.),(-3.,0.,-2.)]:
    values,q = symmetric_eigen2(a,b,d)
    restored = reconstruct(values,q)
    target = [[a,b],[b,d]]
    assert max(abs(restored[i][j]-target[i][j]) for i in range(2) for j in range(2)) < 1e-12
    assert max(abs(sum(q[k][i]*q[k][j] for k in range(2))-float(i==j))
               for i in range(2) for j in range(2)) < 1e-12
assert symmetric_eigen2(2.,1.,2.)[0] == [3.,1.]
try:
    symmetric_eigen2(1.,float('nan'),2.)
except ValueError:
    pass
else:
    raise AssertionError("nonfinite input accepted")

With the dimension fixed at two, the operation count and working storage are constant. The tests verify reconstruction and orthonormal columns for positive, negative, repeated, and zero eigenvalues. Scaling avoids some intermediate overflow, but subtracting nearly equal numbers can still lose accuracy in a tiny eigenvalue. Larger problems should use a solver intended for symmetric or Hermitian matrices, such as eigh, and check both reconstruction and orthogonality. NumPy eigh

Which properties are invariant?

For nonzero xx, let y=Q⊤xy=Q^\top x. Then

x⊤Axx⊤x=∑iλiyi2∑iyi2∈[λmin⁡,λmax⁡].\frac{x^\top Ax}{x^\top x}=\frac{\sum_i\lambda_i y_i^2}{\sum_i y_i^2}\in[\lambda_{\min},\lambda_{\max}].

This Rayleigh quotient is a weighted average of eigenvalues. Its bounds explain why a real symmetric matrix is positive definite precisely when every eigenvalue is positive. A zero eigenvalue leaves a flat direction, and a negative eigenvalue provides a direction with negative quadratic value.

Without symmetry, a matrix may have a nonorthogonal eigenbasis, no full eigenbasis, or complex eigenvalues. The quarter-turn matrix is orthogonal but not symmetric, so a real diagonalization of this form is impossible. Do not use “orthogonal matrix” and “orthogonally diagonalizable matrix” interchangeably. In complex spaces the corresponding Hermitian statement uses conjugate transpose and a unitary basis.

Read the decomposition in both directions

  1. What are the smallest and largest unit-vector values of x⊤Axx^\top Ax for the opening example? Answer: one and three, attained on the corresponding eigenvectors.
  2. Can q1q_1 be replaced by −q1-q_1? Answer: yes; (−q1)(−q1)⊤=q1q1⊤(-q_1)(-q_1)^\top=q_1q_1^\top.
  3. For A=2I2A=2I_2, is the eigenbasis unique? Answer: no; any orthonormal basis gives the same matrix.
  4. Does symmetric imply positive definite? Answer: no. diag⁡(2,−1)\operatorname{diag}(2,-1) is symmetric but has a negative direction.

A common route into several algorithms

Covariance matrices and graph Laplacians often bring symmetry into learning problems. The theorem also constructs SVD through the symmetric matrix A⊤AA^\top A, and turns quadratic forms into sums of independent squared coordinates. These mathematical connections do not prescribe the numerically best implementation: constructing a Gram matrix can make small singular values harder to resolve.

Make a prediction, then check

Is the orthonormal eigenbasis of 2I₂ unique?

Choose one answer

Learning objectives

  • Explain orthogonality and a complete eigenbasis using symmetry.
  • Reconstruct a two-dimensional decomposition and bound a quadratic form with its Rayleigh quotient.

Prerequisites & connections

Explore related knowledge →

References

  1. Mathematics for Machine Learning — mathematical foundations (2024-01-15 draft)
    Marc Peter Deisenroth; A. Aldo Faisal; Cheng Soon Ong · 2020
  2. Deep Learning — Chapter 2: Linear Algebra
    Ian Goodfellow; Yoshua Bengio; Aaron Courville · 2016
  3. NumPy — numpy.linalg.eigh
    NumPy developers

Version1 · Editorial status: Recorded technical checks completed

View technical check record (AI)

Codex · 2026-09-05 · Codex technical check: cited-source comparison, derivation and numerical checks, bilingual argument comparison, and executed Python assertions; no independent human peer review.

  • Independently checked eigenpair residuals, trace, determinant and reconstruction on 120 real symmetric 2×2 matrices.
  • Checked the sphere-maximum and invariant-complement proof sketch, repeated-value subspaces and eigenvector signs; no uniqueness of the basis is claimed.
  • Compared claims, assumptions, examples, exercises and citations across languages; structural validation additionally compares display equations, code and source lists.

Source locations checked:

Related topics

No matches. Try a synonym or acronym.

0 results shown

Wrap the whole query in double quotes for a phrase match.