Every matrix, of any shape, is a rotation, then a stretch along the axes, then another rotation. The stretch factors (singular values) measure how much each direction matters, which gives the best low-rank approximation of a matrix and the principal components of a data set.
Beyond the courseStrang, Introduction to Linear Algebra, 7.1 to 7.3Trefethen and Bau, Numerical Linear Algebra, Lectures 4 and 5CS 532 (Matrix Methods in Machine Learning)MATH 375 Piazza @128
The spectral theorem (3.1) is wonderful but only covers symmetric matrices. Most matrices in practice are not symmetric, and many are not even square: a data table with 10,000 rows and 50 columns, an image of 1080 by 1920 pixels, a neural-network layer mapping 768 numbers to 3072. The singular value decomposition says every one of them, without exception, is a rotation followed by a stretch along perpendicular axes followed by another rotation. The stretch factors tell you which directions matter, and throwing away the small ones is the best possible compression.
Quick checkFor any matrix A, what kind of matrix is ATA?
(ATA)T=ATA, and xTATAx=∥Ax∥2≥0 (a 3.2 problem). So the spectral theorem applies to it, which is how the SVD is built.Review: positive semidefinite
Quick checkAn orthogonal matrix Q does what to the length of a vector?
Orthogonal matrices are isometries (3.3). So in UΣVT all the stretching happens in Σ.Review: isometries
The picture
Press Next three times. Move 1 (VT) turns the circle so that two special perpendicular directions v1,v2 line up with the axes; a circle stays a circle. Move 2 (Σ) stretches along the axes by σ1 and σ2, making an ellipse. Move 3 (U) turns the ellipse into its final position. The result is exactly what A does to the circle. Try “Rank one”: σ2=0 and the ellipse collapses to a segment.
Where this came from· Discovered twice, computed a century later
Eugenio Beltrami (1873) and Camille Jordan (1874) independently found the decomposition while studying bilinear forms, which are the expressions xTAy with two different vectors. Erhard Schmidt proved the matching approximation result for integral operators in 1907. Carl Eckart and Gale Young proved it for matrices in 1936, in the journal Psychometrika, where such approximations were wanted for test-score data. Principal component analysis has a separate history: Karl Pearson (1901) fitted lines and planes to data, and Harold Hotelling (1933) named it. A practical way to compute the SVD came only in the 1960s, from Gene Golub and William Kahan. Their idea of reducing the matrix to a simpler bidiagonal form first is still the first stage of the routines behind NumPy’s svd.
Definitions and the theorem
Definition B
Singular value
The singular values of a real m×n matrix A are σi=λi, where λ1≥λ2≥⋯≥λn≥0 are the eigenvalues of the symmetric positive semidefinite matrix ATA. (Positive semidefinite was shown in 3.2: xTATAx=∥Ax∥2≥0, so no λi is negative and the square roots exist. If m<n then rankA≤m, so at most m of the σi are non-zero.)
In one lineThe singular values of A are the square roots of the eigenvalues of AᵀA, listed from largest to smallest: the stretch factors of A.
Why it existsThey measure how much A stretches each of a set of perpendicular directions, which is what 'the size of A in each direction' should mean.
Definition B
Singular value decomposition
A singular value decomposition of A is a factorisation A=UΣVT where U is an m×m orthogonal matrix, V is an n×n orthogonal matrix, and Σ is m×n with the singular values σ1≥σ2≥⋯≥0 on its diagonal and zeros elsewhere. The columns vi of V are the right singular vectors and the columns ui of U the left singular vectors, with
Avi=σiui.
In one lineA = UΣVᵀ with U (m×m) and V (n×n) orthogonal and Σ (m×n) diagonal with σ₁ ≥ σ₂ ≥ … ≥ 0.
Why it existsIt describes any matrix as rotate, stretch along axes, rotate, and exposes its rank, its four subspaces and its best approximations.
Theorem BStrang 7.2; Trefethen–Bau Thm 4.1
Every matrix has an SVD
Every real m×n matrix A has a singular value decomposition.
In one lineEvery real m×n matrix has a singular value decomposition A = UΣVᵀ.
Why it is trueDiagonalize the symmetric AᵀA to get V; then the vectors Avᵢ are automatically perpendicular, and dividing by their lengths gives U.
Why· The picture behind the proof
Look for perpendicular inputs whose outputs are also perpendicular. Those inputs are the eigenvectors of ATA: their images under A come out perpendicular “for free”, because (Avi)⋅(Avj)=vi⋅(ATAvj), and ATA only rescales vj. The lengths of the images are the singular values, and the image directions are the ui.
ProofStrang 7.2
The idea: Apply the spectral theorem to AᵀA: orthonormal eigenvectors v_i, eigenvalues λ_i = σ_i² ≥ 0. For σ_i > 0 set u_i = Av_i/σ_i; these are orthonormal. Extend to an orthonormal basis of ℝ^m. Then AV = UΣ.
Let v1,…,vn be orthonormal eigenvectors of ATA with eigenvalues λ1≥⋯≥λn≥0. Set σi=λi.
ATA is symmetric, so the spectral theorem (3.1) gives an orthonormal eigenbasis; its eigenvalues are ≥0 because it is positive semidefinite (3.2).
(Avi)⋅(Avj)=vi⋅(ATAvj)=λjvi⋅vj, which is σj2 if i=j and 0 otherwise.
Move A across the dot product with the transpose, then use the eigenvector equation and orthonormality.
Let r be the number of σi>0. For i≤r set ui=σiAvi. By the previous line these are orthonormal.
So the images are perpendicular, and ∥Avi∥=σi.
Extend u1,…,ur to an orthonormal basis u1,…,um of Rm.
Any orthonormal set in Rm extends to an orthonormal basis (extend to a basis, 2.2, then Gram–Schmidt, 2.9).
So Avi=σiui for every i≤r and Avi=O for i>r, which in matrix form is AV=UΣ.
For i≤r, Avi=σiui by definition. For i>r, ∥Avi∥=σi=0, so Avi=O. (If m<n, there is no ui for i>m, but then σi=0 and the column of Σ is zero anyway.)
A=UΣVT. ■
V is orthogonal, so V−1=VT.
Worked example
Compute an SVD of A=[3405].
Solution. The method is: form ATA, diagonalize it, then get each ui by applying A. The step-through below shows each stage.
Answer.A=UΣVT with σ1=35, σ2=5, U=101[13−31] and VT=21[1−111].
Your answerFor A=[3405], what is σ2 squared? (It is an eigenvalue of ATA=[25202025].)
The eigenvalues of [abba] are a±b.
The eigenvalues of ATA are 25±20=45 and 5. The smaller one is σ22=5, so σ2=5.
Worked example
Find the singular values and the rank of [1224], and of the symmetric matrix [200−3].
Solution.
First matrix: form ATA.ATA=[1+42+82+84+16]=[5101020]. Entry (i,j) is column i dotted with column j.
Its eigenvalues. Trace 25, determinant 100−100=0, so λ=25,0. For a 2×2 matrix the eigenvalues have sum equal to the trace and product equal to the determinant.
Singular values and rank.σ=5,0, so the rank is 1. Rank is the number of non-zero singular values. The second column is twice the first, so rank 1 agrees.
Second matrix.ATA=diag(4,9), so the singular values are 3 and 2 (largest first). Singular values are square roots, never negative. The eigenvalues of A are 2 and −3, so ∣λi∣ is what we see here.
Where did the minus sign go? The right singular vector for σ1=3 is v1=e2, and for σ2=2 it is v2=e1. Then u1=Av1/3=(0,−3)/3=(0,−1) and u2=Av2/2=(1,0). Apply A and divide by the singular value, as in the proof. The minus sign lands in u1.
Check the product.U=[0−110], Σ=diag(3,2), VT=[0110] give UΣVT=[0−320][0110]=[200−3]. Multiplying back is the check that the factorization is right.
Answer. First matrix: σ=5,0, rank 1. Second matrix: σ=3,2. For a symmetric matrix, σi=∣λi∣, and the signs of negative eigenvalues move into U.
Your answerThe singular values of [200−3]: what is σ1, the largest?
ATA=diag(4,9), so σ=3,2. Singular values are never negative: the sign of −3 goes into U (a reflection), and only the size 3 is a stretch.
Quick checkHow is rank read off the SVD?
Avi=σiui: the range is spanned by the ui with σi>0, so its dimension (the rank, 2.3) is the number of non-zero σi.
Worked example
Prove: the largest stretch of A, namely max∥x∥=1∥Ax∥, equals σ1. Test it on [3405].
Solution.
Square the length.∥Ax∥2=(Ax)T(Ax)=xT(ATA)x. This turns the question into a quadratic form of the symmetric matrix ATA (3.2).
Use the eigenbasis. Write x=∑civi with ∑ci2=1. Then xTATAx=∑λici2. The vi are orthonormal eigenvectors of ATA, so the cross terms vanish (3.1).
Bound it.∑λici2≤λ1∑ci2=λ1, with equality at x=v1. λ1 is the largest eigenvalue.
Take square roots.max∥Ax∥=λ1=σ1. Square root is increasing.
Test. For A=[3405], x=v1=21(1,1) gives Ax=21(3,9) of length 45=35≈6.71. The longest output from a unit input.
Answer.max∥x∥=1∥Ax∥=σ1, attained at v1. ■ This number is called the operator norm of A (3.5).
Worked example
Prove: for a square matrix A, ∣detA∣=σ1σ2⋯σn. Test on [3405].
Solution.
Take determinants of the SVD.detA=detU⋅detΣ⋅detVT. Product rule for determinants (2.7).
Evaluate each factor.detU=±1 and detVT=±1, and detΣ=σ1⋯σn since Σ is diagonal. Orthogonal matrices have determinant ±1 (3.3), and a diagonal determinant is the product of the diagonal.
Absolute value.∣detA∣=σ1⋯σn. The signs disappear, and the σi are non-negative.
Test.det[3405]=15 and σ1σ2=35⋅5=15. Matches the step-through above.
Answer.∣detA∣=∏σi. ■ Rotations keep area, so all the area change comes from the stretches.
Quick checkWhy is a singular value of a matrix never negative, even when A has a negative eigenvalue?
ATA is positive semidefinite, so its eigenvalues are ≥0 and so are their square roots. For diag(2,−3) the singular values are 3 and 2, and the −1 is absorbed into a singular vector.
The SVD as a sum: low-rank approximation
Multiplying out UΣVT column by row gives
A=σ1u1v1T+σ2u2v2T+⋯+σrurvrT.
Each uiviT is a rank-1 matrix (every row a multiple of viT). The SVD writes A as a sum of rank-1 pieces, in decreasing order of importance σi.
Definition B
Low-rank approximation
For k<r, the rank-k truncation of A is Ak=∑i=1kσiuiviT.
In one lineKeep the first k terms of the SVD sum: A_k = σ₁u₁v₁ᵀ + … + σ_k u_k v_kᵀ, a rank-k matrix close to A.
Why it existsIt compresses A to k(m + n + 1) numbers while keeping as much of A as any rank-k matrix can.
Theorem BEckart and Young 1936; Trefethen–Bau Thm 5.8
Eckart–Young theorem
For every matrix B of rank at most k, ∥A−B∥≥σk+1=∥A−Ak∥, where ∥M∥=max∥x∥=1∥Mx∥ is the largest stretch of M (the operator norm, 3.5). In the Frobenius norm (square root of the sum of squared entries) the same Ak is best, with error σk+12+⋯+σr2. (We prove the operator-norm version below. The Frobenius version has a longer proof, in Trefethen–Bau.)
In one lineThe truncated SVD A_k is the best rank-k approximation of A; its error is the first discarded singular value σ_{k+1} (in the operator norm).
Why it is trueAny rank-k matrix kills some direction in the span of v₁, …, v_{k+1}, and A stretches every vector of that span by at least σ_{k+1}.
ProofTrefethen–Bau 5.8
The idea: (Operator norm.) B has rank ≤ k, so its null space has dimension ≥ n − k and must meet the (k + 1)-dimensional span of v₁, …, v_{k+1}. Pick a unit vector w there: Bw = O, and ‖Aw‖ ≥ σ_{k+1}.
dimN(B)≥n−k.
Rank–nullity (2.3).
N(B) and W=span(v1,…,vk+1) have dimensions adding to at least n+1, so there is a unit vector w∈N(B)∩W.
Two subspaces of Rn with dimensions adding to more than n share a non-zero vector (the dim(U+W) formula, 2.2).
∥Aw∥2=∑i≤k+1ci2σi2≥σk+12.
Write w=∑i≤k+1civi with ∑ci2=1; then Aw=∑ciσiui and the ui are orthonormal.
∥A−B∥≥∥(A−B)w∥=∥Aw∥≥σk+1.
Bw=O, so (A−B)w=Aw.
And ∥A−Ak∥=σk+1, so Ak achieves the bound. ■
A−Ak=∑i>kσiuiviT is itself an SVD with largest singular value σk+1, and the largest stretch of a matrix is its largest singular value (the worked example above).
Proof workshopRebuild the Eckart–Young argument (operator norm)
Tap the lines in the order a proof would write them. Each line can only use what is already above it.
Rank–nullity: rank plus nullity is n.
The vi are orthonormal, hence independent.
This proof starts with the null space of B, since that is where B is weakest. Write that line first.
Dimensions n−k and k+1 add to more than n, so the subspaces cannot meet only at O.
You need both dimensions before you can compare them.
The vectors Avi=σiui are orthogonal, and σi≥σk+1 for i≤k+1.
You need the vector w first.
The largest stretch of A−B is at least its stretch of one unit vector, and Bw is zero.
This uses the bound on ∥Aw∥ from the previous line.
Worked example Strang 7.2 style
Find the SVD of the wide matrix A=[32232−2] using AAT, then give its best rank-1 approximation and the error.
Solution.
Choose the small product.A is 2×3, so AAT is 2×2 while ATA is 3×3. We work with AAT=[178817]. Its non-zero eigenvalues are the same σi2 as those of ATA: if ATAv=λv with λ=0, then Av=O and AAT(Av)=A(ATAv)=λ(Av). And it is smaller.
Eigenvalues.17±8=25,9, so σ1=5, σ2=3. Same pattern a±b as before.
Left singular vectors. Eigenvectors of AAT: u1=21(1,1) for 25 and u2=21(1,−1) for 9. The ui are the orthonormal eigenvectors of AAT.
Right singular vectors.vi=ATui/σi: v1=21(1,1,0) and v2=321(1,−1,4). From Avi=σiui we get ATui=σivi. Check: ∥(1,−1,4)∥=18=32, so v2 is a unit vector.
Best rank-1 approximation.A1=σ1u1v1T=5⋅2121[11][110]=25[111100]. Keep the term with the largest singular value.
Error.∥A−A1∥=σ2=3 in the operator norm. Eckart–Young: the error is the first discarded singular value. Check: A−A1=[0.5−0.5−0.50.52−2] equals σ2u2v2T.
Answer.σ=5,3. A1=25[111100], with error 3. There is no third u, because a 2×3 matrix has at most 2 non-zero singular values. The third right singular vector v3=31(2,−2,−1) spans the null space of A.
Your answerFor A=[32232−2], the best rank-1 approximation has operator-norm error equal to σ2. What is it?
Find the eigenvalues of AAT and take square roots.
AAT=[178817] has eigenvalues 25 and 9, so σ1=5, σ2=3, and the error is σ2=3.
Worked example
Compress a 1000 by 1000 greyscale image to rank 50. How much storage is saved, and what decides the quality?
Solution.
Count the full image.1000×1000=106 numbers. One brightness value per pixel.
Count the rank-50 version. Each term σiuiviT needs ui (1000 numbers), vi (1000) and σi (1): 2001 numbers. For 50 terms: 100,050. Store the factors, not the product.
Ratio.100,050/106≈10% of the storage. About a tenfold saving.
Quality. By Eckart–Young no rank-50 image is closer, and the error is governed by σ51,σ52,…. Many photos have quickly decaying singular values (smooth regions are nearly low rank), so rank 50 can look close to the original, though fine texture is lost first. The theorem gives the best possible; the data decides how good “best” is.
Answer. About 10% of the numbers, with the smallest possible error for that budget. (JPEG uses a fixed cosine basis instead, 2.2, because it is cheaper to compute; the SVD adapts its basis to each image.)
Python labTruncate the SVD of a small synthetic image
import numpy as npx = np.linspace(0, 1, 40)rng = np.random.default_rng(0)# a smooth 40 by 40 "image": two rank-1 patterns plus a little noiseimg = 5 * np.outer(np.sin(np.pi * x), np.cos(3 * x)) + 3 * np.outer(x, x**2)img = img + 0.05 * rng.standard_normal((40, 40))U, s, Vt = np.linalg.svd(img)print("first singular values:", np.round(s[:5], 3))for k in (1, 2, 3, 5): Ak = (U[:, :k] * s[:k]) @ Vt[:k] err = np.linalg.norm(img - Ak, 2) print(f"k={k}: error = {err:.4f} next sigma = {s[k]:.4f} numbers stored = {k*(40+40+1)} of 1600")
Try this.Run it and compare each error with the 'next sigma' printed beside it: they match, as Eckart–Young says. The picture is built from two rank-1 patterns plus noise, so the error collapses at k=2 and then barely moves. Change the noise level 0.05 to 0.5 and watch the singular values from the third onward grow: that tail is the noise, and truncation throws it away.
Your answerHow many numbers store a rank-k approximation of an m×n matrix? Give the answer for m=768, n=768, k=8 (a LoRA-style update).
k(m+n+1)=8⋅1537=12,296, against 7682=589,824 for the full matrix: about 48 times fewer. (LoRA stores the two thin factors and folds σ into them, giving k(m+n)=12,288.)
Principal component analysis
Definition B
Principal component analysis
Let X be an N×d data matrix (one row per sample, one column per feature) with each column’s mean subtracted (centered). The principal components are the right singular vectors v1,v2,… of X. The variance of the data along vi is N−1σi2, and v1 is the direction of greatest variance.
In one lineCenter the data, take the SVD of the data matrix; the right singular vectors are the directions of greatest variance, in decreasing order.
Why it existsIt finds the few directions that carry most of the variation in high-dimensional data, so the data can be seen, compressed or denoised.
Why· Why the singular vectors are the directions of greatest variance
The variance of the data along a unit vector w is N−11∑j(xj⋅w)2=N−11∥Xw∥2=N−11wT(XTX)w. That is a quadratic form in w with the symmetric matrix XTX (the covariance matrix up to the factor N−11). By the Rayleigh-quotient problem of 3.1, its maximum over unit w is the largest eigenvalue of XTX, which is σ12, at w=v1. The next direction, perpendicular to v1, is v2, and so on.
Worked example
Find the first principal component of the four points (2,1),(−2,−1),(1,2),(−1,−2).
Solution.
Center. The mean is (0,0) already. PCA measures spread around the mean, so the mean must be subtracted first.
Form XTX.XTX=[4+4+1+182+2+2+21+1+4+4]=[108810]. Entry (i,j) is the sum over points of (coordinate i) times (coordinate j).
Eigenvectors. Eigenvalues 18 and 2, with eigenvectors (1,1) and (1,−1). Same pattern as 3.1’s [2112].
Read off.v1=21(1,1) carries variance 318=6; v2 carries 32. Variance along vi is σi2/(N−1) with N=4.
Answer. The points spread mostly along the diagonal y=x: 90% of the total variance (18+218) lies along v1. Projecting onto v1 alone keeps 90% of the information in one number per point.
Your answerIn the four-point example the eigenvalues of XTX are 18 and 2. What fraction of the total variance lies along the first principal component? Give a decimal.
Divide the first eigenvalue by the sum of both.
The variance along vi is N−1σi2, so the fractions are 2018 and 202. The first is 0.9.
Quick checkThe shear [1011] has eigenvalues 1,1. What are its singular values?
ATA=[1112] has eigenvalues 23±5≈2.618,0.382, whose square roots are 1.618 and 0.618. Singular values come from ATA, not from the eigenvalues of A. Their product is 1=∣detA∣.
Quick checkWhy must you center the data before PCA?
Without centering, ∥Xw∥2 is dominated by how far the cloud is from the origin, so v1 points at the mean. The SVD always exists; it answers a different question.
Proof workshopGive the reason for each line: why the images Avᵢ are perpendicular
Each line of the proof is shown in order. Choose the reason that justifies it, then press Check.
(Avi)⋅(Avj)=vi⋅(ATAvj)
=vi⋅(λjvj)
=λj(vi⋅vj)
=0 when i=j
Where it is used
Used inside maths· Inside maths: the four subspaces, the pseudoinverse, conditioning
The SVD hands you orthonormal bases of all four fundamental subspaces (2.6): u1..ur for the column space, vr+1..vn for the null space, and so on. It gives the least squares solution even when columns are dependent (the pseudoinverse A+=VΣ+UT). And σ1/σr is the condition number of 3.5, which says how badly a system amplifies errors.
Used in the real world· Data and AI: recommendations, genes, and language models
In the Netflix Prize (2006 to 2009), the leading teams modelled the huge users-by-films ratings matrix as approximately low rank, a few “taste” directions explaining most ratings, and fitted SVD-like factorisations. In population genetics, the first two principal components of genetic data from Europeans reproduce a recognisable map of Europe (Novembre and colleagues, Nature, 2008). In language models, the LoRA paper (Hu and colleagues, 2021) hypothesised that the change in a weight matrix during fine-tuning has low rank, so it trains two thin factors B and A with ΔW=BA instead of the full matrix, and found that small ranks perform competitively.
Traps
Watch out· Singular values are not eigenvalues
For non-symmetric A, the singular values are the square roots of the eigenvalues of ATA, not the eigenvalues of A. The shear [1011] has eigenvalues 1,1 but singular values about 1.618 and 0.618.
Watch out· Computing the SVD by forming AᵀA is fine by hand, risky in floating point
Forming ATA squares the condition number (3.5), so small singular values get lost to rounding. Library routines (Golub–Kahan) work on A directly. Use np.linalg.svd(A), never np.linalg.eig(A.T @ A), for real data.
Problems
check
Find the singular values of [1010] and its rank.
Solution
ATA=[1111] with eigenvalues 2,0, so σ=2,0. Rank 1.
check
For a symmetric positive definite matrix, how are its SVD and its spectral decomposition related?
Solution
They coincide: A=QΛQT is already an SVD with U=V=Q and Σ=Λ (all λi>0). For symmetric matrices with negative eigenvalues, σi=∣λi∣ and the signs move into U.
useStrang 7.2 style
Compute an SVD of [1010].
Solution
v1=21(1,1), v2=21(1,−1); σ1=2, σ2=0. u1=Av1/σ1=(1,0); extend with u2=(0,1). A=[1001][2000]21[111−1].
use
Give the best rank-1 approximation of the [3405] from the step-through, and its error in the operator norm.
∥Ax∥2=xTATAx, a quadratic form whose maximum over unit x is the largest eigenvalue of ATA, which is σ12 (the Rayleigh problem of 3.1). Take square roots.
prove
Prove that ∣detA∣=σ1σ2⋯σn for a square A.
Solution
detA=detUdetΣdetVT=(±1)σ1⋯σn(±1), since orthogonal matrices have determinant ±1 (3.3). Taking absolute values gives the claim. Geometrically: rotations keep area, so all the area change comes from the stretches.
stretch
Show that the eigenvalues of AAT (an m×m matrix) are the same non-zero numbers σi2, with eigenvectors ui. Why might you compute the SVD of a wide data matrix this way?
Solution
AATui=AATσiAvi=σiA(ATAvi)=σiAσi2vi=σi2ui. For a matrix with few rows and many columns (say 100 by 1,000,000), AAT is 100×100 while ATA is enormous, so work with the small one and recover vi=ATui/σi.
Summary
SVD: every matrix is A=UΣVT: rotate, stretch along axes by σ1≥σ2≥⋯≥0, rotate.
Build it from the spectral theorem on ATA: vi its eigenvectors, σi=λi, ui=Avi/σi.
Rank = number of non-zero singular values; σ1 = the largest stretch.
A=∑σiuiviT; keeping k terms gives the best rank-k approximation, with error σk+1 (Eckart–Young).
PCA: center the data; the right singular vectors are the directions of greatest variance, with variance σi2/(N−1).
Applications: compression, recommendations, genetics, low-rank fine-tuning of AI models.
Watch and read
The same ideas explained by someone else. Use these when an explanation here does not land.
MATH 375: Spagnolie on Piazza (@128): the SVD is 'a critically important topic that we didn't quite get to'. This is that topic.
CS 532: The SVD is the central tool of CS 532 (Matrix Methods in ML): least squares, PCA, low-rank models and recommender systems all reduce to it.
AI: LoRA fine-tuning trains a low-rank change to each weight matrix, and embedding compression and the analysis of trained weights use the fact that the SVD gives the best low-rank approximation.