SVD visualized

The singular value decomposition A=UΣV⊤A = U \Sigma V^\top splits every matrix into a rotation, a scaling along the axes and another rotation. Watch a 2 × 2 matrix turn the unit circle into an ellipse step by step, solve Ax=bAx = b with the pseudo-inverse, and rebuild an image from only its largest singular values.

The SVD of a 2 × 2 matrix

Ax=U Σ V⊤xA x = U\,\Sigma\,V^\top x, one step per panel v1v_1 and its images v2v_2 and its images xx, bb click the last panel to choose bb

Low-rank approximation of an image

Rank-pp approximation grayscale, 160 × 120 px, i.e. m=120m = 120, n=160n = 160
original
Singular values σk\sigma_k of the image kept, k≤pk \le p dropped (log scale)

The singular value decomposition

Every real m×nm \times n matrix AA can be written as

A=UΣV⊤,U⊤U=VV⊤=IA = U \Sigma V^\top, \qquad U^\top U = V V^\top = I

The singular values are the square roots of the eigenvalues of A⊤AA^\top A (and of AA⊤A A^\top), and the viv_i are the eigenvectors of A⊤AA^\top A. The value panel checks σi2=λi\sigma_i^2 = \lambda_i for the current matrix. The larger a singular value, the more its pair ui,viu_i, v_i contributes to AA.

Rotate, scale, rotate

Read Ax=U (Σ (V⊤x))A x = U\,(\Sigma\,(V^\top x)) from right to left. V⊤V^\top is orthogonal, so it only turns the plane: the unit circle stays a circle, and v1,v2v_1, v_2 land on the axes e1,e2e_1, e_2. Σ\Sigma stretches the axes by σ1\sigma_1 and σ2\sigma_2: the circle becomes an axis-aligned ellipse. UU turns this ellipse into place. So AA maps the unit circle to an ellipse with semi-axes σ1u1\sigma_1 u_1 and σ2u2\sigma_2 u_2, and

Avi=σiuiA v_i = \sigma_i u_i

The panels use the usual math orientation, xx right and yy up. Singular vectors are only defined up to sign: flipping viv_i and uiu_i together gives the same AA. Here VV is always chosen as a pure rotation. When det⁡A<0\det A < 0, AA flips the plane, and then UU contains a mirror: the small arrow on the circle runs clockwise in the last panel. ∣det⁡A∣=σ1σ2|\det A| = \sigma_1 \sigma_2 is the area of the ellipse divided by π\pi.

Solving Ax=bAx = b with the pseudo-inverse

Undoing the three steps in reverse order gives the solution: rotate bb back with U⊤U^\top, divide by the singular values, rotate with VV:

Ax=b  ⇒  x=VΣ−1U⊤bAx = b \;\Rightarrow\; x = V \Sigma^{-1} U^\top b

When a singular value is tiny, dividing by it blows up every error in bb along uiu_i. When it is zero, AA squashes the plane onto a line, most bb are not reachable, and the division is impossible. The pseudo-inverse replaces 1/σi1/\sigma_i by 0 for all σi≤τ\sigma_i \le \tau. The result is the least-squares solution, the xx that minimizes ∣Ax−b∣|Ax - b|, and among all of those the shortest one. In the last panel, the ring AxAx then sits at the point of the line closest to bb. This works for any shape of AA, including overdetermined systems with more equations than unknowns.

Rank-pp approximation

Written as a sum, the SVD builds AA from rank-1 layers σkukvk⊤\sigma_k u_k v_k^\top, one per singular value. Keeping only the first pp of them gives

aij≈∑k=1puik σk vjka_{ij} \approx \sum_{k=1}^{p} u_{ik} \, \sigma_k \, v_{jk}

It is the best approximation of rank pp: no other matrix of rank pp is closer to AA in the sum of squared differences, and that sum is exactly ∑k>pσk2\sum_{k > p} \sigma_k^2. A grayscale image is an m×nm \times n matrix, so it can be stored as pp columns of UU and VV plus pp singular values, p (m+n+1)p\,(m + n + 1) numbers instead of mnm n. This is the dimensionality reduction from the lecture: the first singular vectors capture the dominant structure, the last ones mostly fine detail and noise.

Where it comes back

The same decomposition solves the homogeneous problem Ax=0Ax = 0: among all unit vectors, x=vnx = v_n, the right singular vector of the smallest singular value, makes ∣Ax∣|Ax| smallest, and ∣Avn∣=σn|A v_n| = \sigma_n. This is the tool behind total least squares, estimating a homography and calibrating a camera.

Try this