Search

Search papers and lessons

Singular Value Decomposition (SVD)

Level 2 · 9 min read

Every matrix, square or not, splits into a rotation, a stretch along the coordinate axes, and another rotation, so its action is easy to see and to approximate.

On this page

  • Colour = topic mix
  • Linear algebra
  • Discrete math
  • Sign in to see your progress

TL;DR

Any matrix AA with mm rows and nn columns can be written as A=UΣV⊤A = U\Sigma V^\top. Here V⊤V^\top rotates the input, Σ\Sigma stretches along the coordinate axes by non-negative amounts called singular values, and UU rotates the result. Every linear map is a rotation, a stretch and another rotation, and the stretch amounts reveal the matrix's rank and its most important directions.

Where you'll see it: in principal component analysis, in least-squares solvers that stay stable when the data is nearly degenerate, in low-rank compression of weight matrices, and in recovering camera motion from two photographs.

Intuition

Why not eigenvectors?

The eigendecomposition describes a matrix by the directions it only stretches. That works well for square matrices, and only when there are enough eigenvectors to form a basis. Many useful matrices fail one of those tests. A data table with 1000 rows and 5 columns is not square. A camera projection maps 3D points to 2D pixels. A weight matrix in a neural network is usually rectangular.

SVD asks a different question. It does not need a matrix to send a direction to itself. It asks: is there a pair of orthogonal bases, one on the input side and one on the output side, such that the matrix just scales each input basis direction into the matching output basis direction? The answer is always yes. That is the whole content of the theorem.

A rotation, a stretch, a rotation

Picture a unit circle of input vectors. A matrix maps it to an ellipse. The SVD says three things about that ellipse.

  1. Its axes point in orthogonal directions.
  2. Its semi-axis lengths are the singular values σ1≥σ2≥⋯≥0\sigma_1 \ge \sigma_2 \ge \dots \ge 0.
  3. The input directions that land on those axes are orthogonal too.

So the matrix first rotates the input so the right directions line up with the coordinate axes, then stretches each axis by its singular value, then rotates the result into place. The middle step is the only one that does real stretching, and it is just multiplication by a diagonal matrix.

flowchart LR
  A[Input vector x] --> B[V transpose: rotate into input axes]
  B --> C[Sigma: stretch each axis by sigma i]
  C --> D[U: rotate into output axes]
  D --> E[A x]

The singular values tell you how much each direction matters. A tiny singular value means the matrix nearly flattens that direction, and dropping it changes little. This is the reason SVD is used for compression and for denoising.

The math

Definition

Definition: Singular value decomposition

For a real m×nm \times n matrix AA, a singular value decomposition is a factorisation

A=UΣV⊤,A = U \Sigma V^\top,

where UU is m×mm \times m with orthonormal columns, VV is n×nn \times n with orthonormal columns, and Σ\Sigma is m×nm \times n with the singular values σ1≥σ2≥⋯≥0\sigma_1 \ge \sigma_2 \ge \dots \ge 0 on its main diagonal and zeros elsewhere.

"Orthonormal columns" means each column has length 1 and any two columns are perpendicular. Such a matrix preserves lengths and angles, which is why it is a rotation (or a reflection). The columns of UU are called left singular vectors, and the columns of VV are right singular vectors.

Where the numbers come from

Form A⊤AA^\top A from the definition, using (UΣV⊤)⊤=VΣ⊤U⊤(U\Sigma V^\top)^\top = V\Sigma^\top U^\top and U⊤U=IU^\top U = I:

A⊤A=VΣ⊤ΣV⊤.A^\top A = V \Sigma^\top \Sigma V^\top.

The matrix A⊤AA^\top A is square, symmetric and positive semidefinite, so it has an eigendecomposition with orthonormal eigenvectors. The equation above says that the eigenvectors of A⊤AA^\top A are the columns of VV, and its eigenvalues are σi2\sigma_i^2. So the singular values are the square roots of the eigenvalues of A⊤AA^\top A. The left singular vectors then follow from ui=Avi/σi\mathbf{u}_i = A\mathbf{v}_i / \sigma_i for every σi>0\sigma_i \gt 0.

This recipe is also the way to compute an SVD by hand for small matrices.

Rank and the number of nonzero singular values

The rank of AA equals the number rr of nonzero singular values. The first rr columns of UU span the column space of AA, and the first rr columns of VV span its row space. This is the connection to rank: the SVD makes the rank visible as a count.

Truncated SVD and the best low-rank approximation

Keep only the first kk terms of the sum:

Ak=∑i=1kσiuivi⊤.A_k = \sum_{i=1}^{k} \sigma_i \mathbf{u}_i \mathbf{v}_i^\top.

The Eckart-Young theorem says AkA_k is the closest matrix to AA among all matrices of rank at most kk, measured in the Frobenius norm. The error is

∥A−Ak∥F=σk+12+⋯+σr2.\|A - A_k\|_F = \sqrt{\sigma_{k+1}^2 + \dots + \sigma_r^2}.

Here ∥⋅∥F\|\cdot\|_F is the Frobenius norm, the square root of the sum of all squared entries. This is the mathematical basis for PCA, for image compression, and for LoRA-style low-rank updates.

Worked examples

Example
A 2 by 2 matrix done by hand

Take

A=(3045).A = \begin{pmatrix} 3 & 0 \\ 4 & 5 \end{pmatrix}.

Step 1. Compute A⊤A=(25202025)A^\top A = \begin{pmatrix} 25 & 20 \\ 20 & 25 \end{pmatrix}.

Step 2. Its eigenvalues solve (25−λ)2−400=0(25-\lambda)^2 - 400 = 0, so λ=45\lambda = 45 or λ=5\lambda = 5.

Step 3. The singular values are σ1=45=35≈6.708\sigma_1 = \sqrt{45} = 3\sqrt{5} \approx 6.708 and σ2=5≈2.236\sigma_2 = \sqrt{5} \approx 2.236.

Step 4. The eigenvectors are v1=(1,1)/2\mathbf{v}_1 = (1, 1)/\sqrt{2} for 45 and v2=(1,−1)/2\mathbf{v}_2 = (1, -1)/\sqrt{2} for 5. Stack them as the columns of VV.

Step 5. Compute Av1=(3,9)/2A\mathbf{v}_1 = (3, 9)/\sqrt{2}, then divide by σ1\sigma_1 to get u1=(1,3)/10\mathbf{u}_1 = (1, 3)/\sqrt{10}.

Step 6. Compute Av2=(3,−1)/2A\mathbf{v}_2 = (3, -1)/\sqrt{2}, then divide by σ2\sigma_2 to get u2=(3,−1)/10\mathbf{u}_2 = (3, -1)/\sqrt{10}.

Step 7. Check the first row of the product. The (1,1)(1,1) entry of ∑iσiuivi⊤\sum_i \sigma_i \mathbf{u}_i \mathbf{v}_i^\top is 110⋅35⋅12+310⋅5⋅12=3\frac{1}{\sqrt{10}} \cdot 3\sqrt{5} \cdot \frac{1}{\sqrt{2}} + \frac{3}{\sqrt{10}} \cdot \sqrt{5} \cdot \frac{1}{\sqrt{2}} = 3, which matches A11=3A_{11} = 3.

Interpretation: both singular values are nonzero, so the rank is 2. The matrix stretches the most along the direction (1,1)(1,1) in the input, by a factor of about 6.7.

Example
Rank-deficient matrix and the best rank-1 approximation

Take B=(1224)B = \begin{pmatrix} 1 & 2 \\ 2 & 4 \end{pmatrix}. The second row is twice the first, so the rank is 1.

Step 1. B⊤B=(5101020)B^\top B = \begin{pmatrix} 5 & 10 \\ 10 & 20 \end{pmatrix}. Its eigenvalues are 25 and 0 (the trace is 25 and the determinant is 0).

Step 2. The singular values are σ1=5\sigma_1 = 5 and σ2=0\sigma_2 = 0. One nonzero singular value means rank 1.

Step 3. The best rank-1 approximation is B1=BB_1 = B itself, with error 0.

Step 4. Now take the matrix AA from the previous example. Its best rank-1 approximation A1=σ1u1v1⊤A_1 = \sigma_1 \mathbf{u}_1 \mathbf{v}_1^\top has error ∥A−A1∥F=σ2=5≈2.236\|A - A_1\|_F = \sigma_2 = \sqrt{5} \approx 2.236. Check the total: ∥A∥F2=9+16+25=50=45+5\|A\|_F^2 = 9 + 16 + 25 = 50 = 45 + 5, which is the sum of the squared singular values.

Interpretation: when a matrix is exactly low-rank, the SVD recovers that exactly, and when it is nearly low-rank, the discarded singular value tells you the price of the approximation.

Tradeoffs and failure modes

SituationProblemBetter choice
Square matrix with a full set of eigenvectorsEigendecomposition is simplerUse eigendecomposition, or SVD if you need orthogonal factors
Rectangular data, such as a table of samplesEigendecomposition does not applyUse SVD, or eigendecomposition of A⊤AA^\top A with care
Nearly singular normal equations in least squaresForming A⊤AA^\top A squares the condition number and loses digitsSolve the least-squares problem with the SVD of AA directly
Very large sparse matrixFull SVD is too expensiveUse a truncated or randomised SVD that computes only the top kk terms
Matrix with tiny singular values that are only noiseNumerical rank can be wrongPick a threshold from the data's noise level before treating values as zero

The main failure mode is treating small singular values as exactly zero. In floating point, a matrix that is truly rank 3 can show a fourth singular value near 10−1610^{-16} that is only rounding error. Also, singular vectors are only unique when the singular values are distinct. If two values are equal, the matching vectors can rotate freely inside their shared subspace.

History

The SVD was found independently by several mathematicians in the 1870s. Eugenio Beltrami published the first derivation for bilinear forms in 1873, and Camille Jordan followed the next year with a related treatment. Their interest was in the geometry of quadratic forms, not in computation.

Its usefulness grew with numerical linear algebra. Carl Eckart and Gale Young proved the best low-rank approximation result in 1936, which gave the SVD its role in data analysis. Gene Golub and William Kahan published a practical algorithm in 1965, and a refined version by Golub and Christian Reinsch followed in 1970. These made the SVD fast and reliable enough to use on real matrices, and they are the basis of the routines in standard numerical libraries today.

Check yourself

QuestionRecall: what are the singular values of a matrix, in terms of A⊤AA^\top A?Show answer

They are the non-negative square roots of the eigenvalues of A⊤AA^\top A. Because A⊤AA^\top A is symmetric and positive semidefinite, its eigenvalues are never negative, so the square roots are always real.

QuestionComputation: find the singular values of C=(0200)C = \begin{pmatrix} 0 & 2 \\ 0 & 0 \end{pmatrix}.Show answer

Compute C⊤C=(0004)C^\top C = \begin{pmatrix} 0 & 0 \\ 0 & 4 \end{pmatrix}. Its eigenvalues are 0 and 4, so the singular values are σ1=2\sigma_1 = 2 and σ2=0\sigma_2 = 0. The rank is 1, which matches the fact that the second row is zero.

QuestionWhy: why is the rank-k truncation of the SVD the best rank-k approximation, and not just one good approximation?Show answer

The Eckart-Young theorem says no other matrix of rank at most kk is closer to AA in the Frobenius norm. The reason is that the SVD picks the orthogonal directions that capture the most of AA's energy first, and each later term can only add less. A different rank-kk matrix would have to put some of the energy in a direction that the top singular vectors already cover more efficiently.

QuestionApplied: a 512 by 512 weight matrix is replaced by its rank-8 truncated SVD, stored as factors. How many numbers are stored, and what fraction of the original 262144 entries is that?Show answer

The factors are U8U_8 with 512×8512 \times 8 entries, V8V_8 with 512×8512 \times 8 entries, and the 8 singular values. That is 8192+8192+8=163928192 + 8192 + 8 = 16392 numbers. The fraction is 16392/262144≈0.062516392 / 262144 \approx 0.0625, about 6.25 percent. The approximation is lossy, so the real question is how much the discarded singular values matter for the task.

QuestionApplied: you fit a line through noisy points by solving the normal equations, and the result jumps a lot when you add one more point. What does the SVD view suggest?Show answer

The normal equations square the condition number of the design matrix, so small noise in the data gets amplified. The SVD view says the problem is poorly conditioned: a singular value is tiny, and dividing by it blows up the noise in that direction. Solving with the SVD and truncating or regularising the tiny singular values stabilises the fit.

Sources

  • Wikipedia, "Singular value decomposition"
  • Gilbert Strang, Introduction to Linear Algebra, Wellesley-Cambridge Press
  • Sheldon Axler, Linear Algebra Done Right, Springer