Chapter 10: The singular value decomposition

Previous: LA 09 Symmetric and Positive Definite Matrices | LA 00 Course Map | Next: LA 11 Change of Basis

The big idea

Every matrix, of any shape, can be broken into three simple steps: a rotation, a stretch along perpendicular axes, and another rotation. The stretch factors are the singular values. They tell you the rank, how much the matrix can amplify things, which directions matter most, and how to approximate the matrix with far less data. The SVD is the most useful single factorization in applied mathematics.

In this chapter you will learn to
  1. State the SVD, , and explain each factor with a picture.
  2. Compute the SVD of a small matrix by hand from .
  3. Read rank, norm, condition number and the four subspaces off the SVD.
  4. Build the best low-rank approximation of a matrix.
  5. Explain principal component analysis (PCA) and the pseudoinverse in terms of the SVD.
Before you start

This chapter leans on the spectral theorem (LA 09 Symmetric and Positive Definite Matrices), the four subspaces (LA 05 Subspaces Basis and Rank), and orthogonal matrices (LA 06 Orthogonality and Least Squares).


10.1 Why eigenvalues are not enough

Eigen-decomposition is powerful, but:

  • it only works for square matrices,
  • it can involve complex numbers (rotations),
  • it can fail entirely (defective matrices like the shear),
  • the eigenvectors are generally not perpendicular, so can be badly behaved.

Symmetric matrices had none of these problems (chapter 9). The SVD gets the same clean behaviour for every matrix, by allowing the input directions and output directions to be different sets of perpendicular axes.


10.2 The statement

Singular value decomposition

Any real matrix can be written

where

  • is an orthogonal matrix. Its columns are the right singular vectors (perpendicular input directions).
  • is an orthogonal matrix. Its columns are the left singular vectors (perpendicular output directions).
  • is , zero except on its diagonal, which holds the singular values .

One direction at a time

Multiply on the right by : . Column by column:

takes the input direction to the output direction , stretched by .

Compare with eigenvectors, , where the output had to point the same way as the input. The SVD allows the output to point somewhere else, and in exchange guarantees that everything is perpendicular, real and non-negative.

The picture: a sphere becomes an ellipsoid

Feed the unit sphere (all vectors of length 1) into . The output is an ellipsoid.

  • Its axes point along
  • Its semi-axis lengths are
  • The inputs that land on those axes are

Reading right to left as three steps:

  1. rotates the sphere. A rotated sphere is still a sphere. (It lines the up with the coordinate axes.)
  2. stretches along the coordinate axes by Now it is an axis-aligned ellipsoid. (If , it also adds or removes dimensions.)
  3. rotates the ellipsoid into its final position.

So every linear map is: rotate, stretch along axes, rotate. Nothing else is possible.


10.3 How to compute it

The connection to

is symmetric and positive semidefinite (chapter 9), so the spectral theorem applies to it. Substitute the SVD:

This is exactly a spectral decomposition. So:

  • the are the eigenvectors of ,
  • the eigenvalues of are , so .

Similarly the are eigenvectors of .

The recipe

  1. Compute .
  2. Find its eigenvalues (sorted largest first) and orthonormal eigenvectors .
  3. Singular values: .
  4. For each nonzero : .
  5. If you need a full , complete the to an orthonormal basis of .

Worked example 10.1

Step 1.

Step 2. Trace 50, determinant . So , giving and . Eigenvectors (this is the familiar pattern):

Step 3.

Step 4.

Checks.

  • ✓ (perpendicular).
  • ✓.
  • ✓. (The product of the stretches is the area scaling factor, chapter 7.)

Meaning. The input direction is stretched the most, by 6.71, and comes out along . The direction is stretched least, by 2.24, and comes out along .

Worked example 10.2: a non-square matrix

, eigenvalues and , eigenvectors and .

So , . Then .

One nonzero singular value: the rank is 1. The direction is sent to zero: it spans the null space.


10.4 What the SVD tells you

QuantityFrom the SVD
ranknumber of nonzero
largest stretch (spectral norm), so
smallest stretch (square, invertible)
condition number
volume scaling (square)

The four subspaces, with perfect bases

If the rank is :

SubspaceOrthonormal basis
row space
null space
column space
left null space

This is the complete picture from chapter 5, now with perpendicular unit-length bases for every piece, and with the exact stretch factor linking to .


10.5 Low-rank approximation

The SVD as a sum

Multiplying out gives a sum of rank-one pieces:

Each piece is a simple matrix (every row is a multiple of ). The pieces are ordered by importance: is the biggest.

Keeping the important pieces

Keep only the first terms:

Eckart-Young theorem

is the best rank- approximation to . No other matrix of rank is closer to (in the spectral norm or in the sum of squared entries). The error is controlled by the discarded singular values: .

Why this is compression

An matrix has numbers. needs only : vectors , vectors , and numbers .

Worked example 10.3. A greyscale image has numbers. Keeping singular values needs : a tenth of the storage. If the singular values decay quickly (as they do for natural images, which are smooth and repetitive), the image looks almost the same.

Worked example 10.4 (by hand). For in example 10.1, the best rank-1 approximation is

Compare with : the rough shape (bottom row larger) is kept, and the error has spectral norm .


10.6 Principal component analysis (PCA)

The goal

You have data points, each with features: a data matrix (), one point per row. You want the few directions that capture most of the variation, so you can visualize, compress or denoise the data.

The method

  1. Centre the data: subtract the mean of each column, so every feature has mean zero.
  2. Compute the SVD: .
  3. The columns of are the principal components:
    • is the direction along which the data varies most,
    • is the direction of greatest remaining variation, perpendicular to , and so on.
  4. The variance of the data along is .
  5. To reduce to dimensions, keep the coordinates (project each point onto the first components).

Why the SVD gives this

The covariance matrix of centred data is (PS 06 Joint Distributions and Covariance). From section 10.3, the eigenvectors of are the with eigenvalues . And from chapter 9, the eigenvectors of a covariance matrix are the axes of its uncertainty ellipse, with variance along each. So PCA is “find the axes of the data’s ellipse”, and the SVD finds them directly without forming (which is numerically better).

Worked example 10.5. Five points: , , , , . Mean . Centred:

Eigenvalues: trace 28, det , so : about and . The first direction carries of the variance. Its eigenvector solves , so : the direction normalized, about .

The data is almost one-dimensional: the points lie close to a line through in direction .

Two PCA mistakes
  • Forgetting to centre. Without centring, the first “component” mostly points at the mean.
  • Mixing units. If one feature is in millimetres and another in kilometres, the millimetre feature dominates purely because its numbers are bigger. Standardize features first when units differ.

10.7 The pseudoinverse

For any matrix, define

where is and holds for each nonzero , with zeros elsewhere.

Then is:

Situation gives
square, invertiblethe exact solution
tall, independent columnsthe least squares solution
rank deficientthe least squares solution with the smallest length

One formula covers every case of chapter 5.

Why it works: maps . maps , undoing it on the column space, and sends the left null space (unreachable outputs) to zero. Null space directions are never added, which is why the answer is the shortest one.

Tiny singular values

Dividing by a very small amplifies noise enormously. In practice, singular values below a threshold are treated as zero (truncated SVD), or regularization is added. np.linalg.pinv has an rcond parameter for this.


Summary

IdeaFact
SVD for every matrix
one direction
picturerotate, stretch along axes, rotate
compute, from ;
ranknumber of nonzero
norm, condition;
best rank-keep the top terms
PCAcentre, SVD, columns of
pseudoinverse

Three facts to remember:

  1. Every matrix is rotate, stretch, rotate.
  2. Singular values rank the directions by importance.
  3. Truncating the SVD is the best possible compression.

Exercises

Part A: warm-up

A1. Find the singular values of .

A2. A matrix has singular values . Give its rank and the dimension of its null space.

A3. Singular values . What is the condition number? What does the best rank-1 approximation keep?

A4. Why are singular values never negative?

Part B: core

B1. Compute the full SVD of .

B2. Compute the SVD of and verify .

B3. For the data , , , , find the first principal component and the fraction of variance it explains. Why?

B4. Use the pseudoinverse idea to find the shortest solution of .

B5. Explain why the condition number of an orthogonal matrix is 1, and why that makes orthogonal matrices numerically ideal.

Part C: explain and prove

C1. Prove that for all . (Hint: write and use orthonormality.)

C2. Show that if is symmetric positive semidefinite, its SVD and its spectral decomposition coincide.

C3. Prove that the singular values of and are the same.

C4. Explain in words why truncating the SVD removes noise in a dataset whose true signal is low-rank.

Part D: practise with code

D1. U, s, Vt = np.linalg.svd(A). Run it on example 10.1 and compare with the hand computation (signs may differ: explain why that is allowed).

D2. Load a greyscale image as a 2-D array (for example scipy.datasets.face(gray=True)). Plot its singular values on a log scale, and show reconstructions with . How many values do you need before it looks right?

D3. Generate 200 points along the line plus small noise in 2-D. Run PCA with np.linalg.svd on the centred data and draw the first component on the scatter plot.

D4. Compare np.linalg.pinv(A) @ b with np.linalg.lstsq(A, b) on a tall random matrix. They should agree.


Where this is used

  • Manipulability. The singular values of a robot’s Jacobian give the manipulability ellipsoid: how easily the hand moves in each direction. A singular value near zero means a near-singularity (02 Geometry and Kinematics).
  • Representation learning. Learned representations, embeddings and low-rank adaptation (LoRA) of large models rely on useful structure being low rank (Appendix - Representation Learning).
  • Recommendation systems, denoising, data compression and PCA throughout data science.

Next: LA 11 Change of Basis: the same vector, described from different viewpoints.