Why We Need the SVD#
Week 10 diagonalized a square matrix as when had a full set of independent eigenvectors. Week 12 upgraded that story for symmetric : eigenvalues are real and can be chosen orthogonal, so . Both tools are powerful — and both are picky about the matrix they accept.
Eigendecomposition requires to be square and diagonalizable. Many matrices that show up in data and geometry fail one or both tests:
- A data matrix of samples and features is , often with — eigenvalues are not even defined.
- A square but defective matrix (not enough independent eigenvectors) cannot be written .
- Even when diagonalization exists, the eigenvector matrix need not be orthogonal, so the change of basis can stretch and shear rather than pure rotate.
The SVDSingular Value Decomposition (singular value decomposition) removes those restrictions. For every real matrix — square or rectangular, full rank or rank-deficient — there exist orthogonal matrices and and a rectangular “diagonal” matrix of nonnegative numbers such that
No eigenvalue computation on itself is required. The construction uses only the spectral theorem on the symmetric Gram matrices and , which always work. That is why the SVD is the workhorse factorization of applied linear algebra: least squares, low-rank approximation, PCA, and pseudoinverses all build on it.
Constructing the SVD#
Start from any real matrix . Form the Gram matrix
This matrix is always symmetric () and positive semidefinite (). By the spectral theorem from Week 12 it has an orthonormal basis of eigenvectors and nonnegative eigenvalues :
The singular values of are the square roots of those eigenvalues:
Conventionally we order them for the positive ones (where ) and pad with zeros if needed. Pack them into an rectangular diagonal matrix with on the main diagonal and zeros elsewhere.
The columns of are the right singular vectors. The left singular vectors come from applying and normalizing. For each positive singular value,
(Equivalently, the are orthonormal eigenvectors of the other Gram matrix .) Extend to a full orthonormal basis of if , and pack the result into the orthogonal matrix . The defining identity is then
Why it works. Multiplying on the right by gives . Column of that equation is exactly . Multiplying on the left by recovers , so the squared singular values are the eigenvalues of — consistent by construction.
Worked sketch. Let
Then
The trace of is , so . The eigenvalues of are and (solve ), hence singular values and . The browser lab below recovers , , and numerically and checks that the product reconstructs .
Connection to rank. The number of positive singular values equals . Zero singular values mark the nullspace directions: when . Truncating small singular values (setting them to zero) produces the best low-rank approximation of in the Frobenius and spectral norms — the Eckart–Young theorem, which Week 14 uses for PCA.
Geometric Picture#
The factorization is a composition of three simple maps. For a vector ,
Read right to left:
- — an orthogonal change of coordinates in the input space (a rotation or reflection). The new coordinates are the components of along the right singular vectors.
- — axis-aligned stretching (and possible zeroing). Coordinate is multiplied by ; if , some coordinates are padded with zeros or dropped so the dimensions match.
- — an orthogonal change of coordinates in the output space: reassemble the stretched components along the left singular vectors.
So every linear map is a rotation, followed by stretch along the coordinate axes, followed by another rotation. That is a stronger statement than diagonalization: you no longer need to be square, and the “eigenbases” on the two sides ( and ) can live in different dimensions.
Unit circle picture. Map the unit circle through . Because preserves lengths, still traces the unit circle. turns that circle into an axis-aligned ellipse with half-axes . then rotates (or reflects) the ellipse into its final orientation. The longest stretch of the ellipse is , the operator (spectral) norm of .
When is symmetric and positive semidefinite. The SVD and the spectral theorem coincide up to signs: and , so . The SVD is the generalization that keeps working after symmetry and squareness are dropped.
Complex Matrices#
Many applications — Fourier analysis, quantum states, circuit phasors, and next week's discrete Fourier transform — live over rather than . The real notions of transpose, symmetry, and orthogonality each have a complex counterpart built from the conjugate transpose
(also written ). Conjugate every entry, then transpose. For real matrices, conjugation does nothing, so and the two stories agree.
Hermitian matrices. A square complex matrix is Hermitian when
This is the complex analogue of symmetry. Diagonal entries of a Hermitian matrix must be real (), and off-diagonal pairs satisfy . The spectral theorem upgrades cleanly: every Hermitian matrix has real eigenvalues and an orthonormal basis of eigenvectors with respect to the complex inner product . In matrix form
with unitary (defined next) and real diagonal.
Unitary matrices. A square complex matrix is unitary when
(equivalently , or ). This is the complex analogue of an orthogonal matrix's . Unitary maps preserve the complex Euclidean norm: for every . Columns of a unitary matrix form an orthonormal basis of .
SVD over . The same construction works with conjugate transposes: every complex matrix factors as with unitary , and real nonnegative singular values on . The squared singular values are the eigenvalues of the Hermitian positive-semidefinite matrix .
Why this matters next week. The discrete Fourier matrix is unitary (up to a standard normalization). PCA is built directly on the SVD of a data matrix. Both rely on the geometry you just met: orthogonal (or unitary) changes of basis that expose axis-aligned stretches.
Knowledge check#
For A = [[3,0],[4,5]], compute A^T A and find its trace (sum of diagonal entries) — this equals the sum of the squared singular values.
Browser lab#
Compute the SVD with numpy.linalg.svd and verify it reconstructs A.
import numpy as np
A = np.array([[3., 0.],
[4., 5.]])
U, S, Vt = np.linalg.svd(A)
print("U =\n", U)
print("singular values =", S)
print("V^T =\n", Vt)
A_reconstructed = U @ np.diag(S) @ Vt
print("Reconstructed A ≈ original:", np.allclose(A_reconstructed, A))
np.linalg.svd returns the factors in “thin” or “full” form depending on options; the default full form for a square gives orthogonal and with S as a 1-D array of singular values in descending order. Rebuilding and multiplying recovers up to floating-point roundoff — the check np.allclose should print True. You can also verify , matching the trace identity from the knowledge check.
Quiz#
The SVD writes any m×n matrix A as: