Session 29 · Unit 3

Singular Value Decomposition


The SVD is the final and best factorization of a matrix. Any matrix whatsoever factors as orthogonal times diagonal times orthogonal, built from orthonormal bases of the row space and column space that A maps into each other. The recipe runs through the eigenvectors of A-transpose-A and A-A-transpose, and the result is exactly the right basis for all four fundamental subspaces.

The final and best factorization

This is the lecture on the singular value decomposition — “but everybody calls it the SVD.” Strang announces it as “the final and best factorization of a matrix”: the factors will be orthogonal matrix, diagonal matrix, orthogonal matrix,

A=UΣVT.A = U \Sigma V^T.

These are things we’ve seen before — the special good matrices, orthogonal and diagonal. The new point is that we need two orthogonal matrices, probably different ones. And AA can be any matrix whatsoever: every matrix has this factorization. Strang calls it “maybe the bringing together of everything in this course.”

One family we just studied fits instantly: symmetric positive definite matrices. There the eigenvectors are orthogonal, so the usual eigenvector matrix SS becomes an especially good QQ, and positive definiteness makes Λ\Lambda positive:

A=QΛQT(symmetric positive definite case).A = Q \Lambda Q^T \qquad \text{(symmetric positive definite case)}.

That is an SVD — orthogonal, diagonal, orthogonal — with the same QQ on both sides. But in general the eigenvector matrix isn’t orthogonal, so eigenvectors alone won’t do. In general we need a UU and a separate VV.

The goal: an orthogonal basis that stays orthogonal

Remember the picture of a linear transformation — the most important figure in the course. A typical vector v1\mathbf{v}_1 in the row space gets taken over to some vector u1=Av1\mathbf{u}_1 = A\mathbf{v}_1 in the column space. What the SVD looks for is very special: an orthogonal basis in the row space that gets knocked over into an orthogonal basis in the column space.

Finding some orthogonal basis of the row space is no big deal — start with any old basis and grind through Gram–Schmidt. But if you take any old orthogonal basis, there is no reason its images under AA should be orthogonal. The SVD asks for the special setup where they are.

While we’re at it, make everything orthonormal. Then Av1A\mathbf{v}_1 won’t be a unit vector, only a multiple of one — and that stretching number is no longer called λ\lambda; it’s called σ\sigma:

Av1=σ1u1,Av2=σ2u2,,Avr=σrur,A\mathbf{v}_1 = \sigma_1 \mathbf{u}_1, \quad A\mathbf{v}_2 = \sigma_2 \mathbf{u}_2, \quad \ldots, \quad A\mathbf{v}_r = \sigma_r \mathbf{u}_r,

where rr is the rank. What about the null spaces? No problem. Complete v1,,vr\mathbf{v}_1, \ldots, \mathbf{v}_r with a basis vr+1,,vn\mathbf{v}_{r+1}, \ldots, \mathbf{v}_n of the null space, and complete the u\mathbf{u}‘s to an orthonormal basis of all of Rm\mathbb{R}^m — those extra directions just produce zeroes on the diagonal of Σ\Sigma.

Now the usual step: think of what you want, then express it as a matrix multiplication. Column by column, the equations Avi=σiuiA\mathbf{v}_i = \sigma_i\mathbf{u}_i say

AV=UΣ,A V = U \Sigma,

and since VV is a square orthogonal matrix, V1=VTV^{-1} = V^T:

Making the U’s disappear: the great matrix A^T A

Here’s the problem: two orthogonal matrices, and we don’t want to find them both at once. Strang wants to “cook up some expression that will make the UU‘s disappear.” It’s the same combination that keeps showing up for a general rectangular matrix — ATAA^TA, “that’s the great matrix”: symmetric, and positive definite or at least positive semidefinite. Compute it from the factorization:

ATA=(VΣTUT)(UΣVT)=VΣTΣVT=V[σ12σ22]VT.A^TA = \left(V\Sigma^T U^T\right)\left(U \Sigma V^T\right) = V\, \Sigma^T\Sigma\, V^T = V \begin{bmatrix} \sigma_1^2 & & \\ & \sigma_2^2 & \\ & & \ddots \end{bmatrix} V^T.

The key point: UTUU^TU collapses into II, and the UU‘s are out of the picture. What’s left is a perfect QΛQTQ\Lambda Q^T for the symmetric positive (semi)definite matrix ATAA^TA. So we can read everything off:

AA itself is nothing special — but ATAA^TA is special, and its eigenvalues are positive (or zero) exactly because it’s positive (semi)definite. That’s why the square roots make sense.

Example 1: an invertible 2 by 2 — and an honest slip

Take A=[4433]A = \begin{bmatrix} 4 & 4 \\ -3 & 3 \end{bmatrix}. It’s invertible, rank two, and not symmetric — so its eigenvectors are no help; they’re not orthogonal. First step: compute ATAA^TA.

ATA=[4343][4433]=[257725].A^TA = \begin{bmatrix} 4 & -3 \\ 4 & 3 \end{bmatrix}\begin{bmatrix} 4 & 4 \\ -3 & 3 \end{bmatrix} = \begin{bmatrix} 25 & 7 \\ 7 & 25 \end{bmatrix}.

It better come out symmetric — and it does. Its eigenvectors are the familiar pair (1,1)(1,1) and (1,1)(1,-1): multiplying by (1,1)(1,1) gives (32,32)(32, 32), so λ1=32\lambda_1 = 32; multiplying by (1,1)(1,-1) gives 1818 times (1,1)(1,-1), so λ2=18\lambda_2 = 18. Normalize (divide by 2\sqrt{2}; the 3232 and 1818 don’t change), and we have

V=12[1111],Σ=[320018].V = \frac{1}{\sqrt 2}\begin{bmatrix} 1 & 1 \\ 1 & -1 \end{bmatrix}, \qquad \Sigma = \begin{bmatrix} \sqrt{32} & 0 \\ 0 & \sqrt{18} \end{bmatrix}.

For the u\mathbf{u}‘s, go the AATAA^T way:

AAT=[4433][4343]=[320018].AA^T = \begin{bmatrix} 4 & 4 \\ -3 & 3 \end{bmatrix}\begin{bmatrix} 4 & -3 \\ 4 & 3 \end{bmatrix} = \begin{bmatrix} 32 & 0 \\ 0 & 18 \end{bmatrix}.

A lucky accident — it comes out diagonal, so its eigenvectors are as nice as can be: (1,0)(1,0) and (0,1)(0,1), “the best orthogonal matrix, just the identity.” And the eigenvalues are 3232 and 1818 again. Are we surprised?

Now check the product UΣVTU\Sigma V^T against AA. The first row works perfectly: 32/2=16=4\sqrt{32}/\sqrt{2} = \sqrt{16} = 4, giving 44 and 44. The second row: 18/2=9=3\sqrt{18}/\sqrt{2} = \sqrt{9} = 3 — but it produces 3,33, -3 where AA has 3,3-3, 3. “Phooey.” Strang stops, genuinely puzzled: “It shouldn’t have happened, but it did.” The catch — which he leaves as “a very important reason to come back on Wednesday” — is that eigenvectors of AATAA^T only determine each ui\mathbf{u}_i up to sign, and the signs must be matched to the v\mathbf{v}‘s. The safe rule is to take ui=Avi/σi\mathbf{u}_i = A\mathbf{v}_i / \sigma_i: here Av2=(0,32)A\mathbf{v}_2 = (0, -3\sqrt 2), so u2=(0,1)\mathbf{u}_2 = (0, -1), not (0,1)(0, 1), and everything comes out right while Σ\Sigma keeps its positive diagonal.

Here is that whole example as a picture. AA sends the unit circle to an ellipse; the dashed input directions are v1,v2\mathbf{v}_1, \mathbf{v}_2, and their images are exactly the ellipse’s axes, σ1u1\sigma_1\mathbf{u}_1 and σ2u2\sigma_2\mathbf{u}_2:

Try it — the circle becomes an ellipse
input space: unit circle, x on it
output space: Ax traces the ellipse

A = [4 4; −3 3]. The dashed directions in the left picture are v₁, v₂ (orthonormal, from AᵀA). Their images are the ellipse's axes: σ₁u₁ and σ₂u₂ with σ₁ = √32, σ₂ = √18. Park x on a dashed line and watch Ax hit an axis.

Example 2: a singular matrix, rank one

Second example, where the matrix is singular: A=[4386]A = \begin{bmatrix} 4 & 3 \\ 8 & 6 \end{bmatrix}, rank one. Now the picture becomes easy, because the row space and column space are just lines. The row space is all multiples of (4,3)(4,3); the null space is the perpendicular line. The columns are all multiples of (4,8)(4,8) — that is, of (1,2)(1,2) — so the column space is that line, and the null space of ATA^T is perpendicular to it.

Choosing orthonormal bases here is no problem — each space is one-dimensional, so just make unit vectors:

v1=[0.80.6],u1=15[12].\mathbf{v}_1 = \begin{bmatrix} 0.8 \\ 0.6 \end{bmatrix}, \qquad \mathbf{u}_1 = \frac{1}{\sqrt 5}\begin{bmatrix} 1 \\ 2 \end{bmatrix}.

For σ1\sigma_1, go back to where the sigmas come from:

Complete the bases with the null space directions: v2=(0.6,0.8)\mathbf{v}_2 = (0.6, -0.8) perpendicular to v1\mathbf{v}_1, and u2=15(2,1)\mathbf{u}_2 = \tfrac{1}{\sqrt 5}(2, -1). Altogether,

[4386]=15[1221]U[125000]Σ[0.80.60.60.8]VT.\begin{bmatrix} 4 & 3 \\ 8 & 6 \end{bmatrix} = \underbrace{\frac{1}{\sqrt 5}\begin{bmatrix} 1 & 2 \\ 2 & -1 \end{bmatrix}}_{U} \underbrace{\begin{bmatrix} \sqrt{125} & 0 \\ 0 & 0 \end{bmatrix}}_{\Sigma} \underbrace{\begin{bmatrix} 0.8 & 0.6 \\ 0.6 & -0.8 \end{bmatrix}}_{V^T}.

Do the multiplication and pray it comes out right: 5\sqrt 5 cancels into 125\sqrt{125} leaving 25=5\sqrt{25} = 5, five multiplies the unit-vector entries into whole numbers, and out comes AA. The null space vectors v2\mathbf{v}_2 and u2\mathbf{u}_2 were multiplied by that zero — easy to deal with. The key ones are the ones in the row space and column space: columns times diagonal times rows, coming together to produce AA.

The right bases for the four subspaces

Step back and see what we’re really doing: choosing the right basis for the four subspaces of linear algebra.

  • v1,,vr\mathbf{v}_1, \ldots, \mathbf{v}_r: an orthonormal basis for the row space, dimension rr.
  • u1,,ur\mathbf{u}_1, \ldots, \mathbf{u}_r: an orthonormal basis for the column space, dimension rr.
  • vr+1,,vn\mathbf{v}_{r+1}, \ldots, \mathbf{v}_n: an orthonormal basis for the null space, dimension nrn - r.
  • ur+1,,um\mathbf{u}_{r+1}, \ldots, \mathbf{u}_m: an orthonormal basis for the null space of ATA^T, dimension mrm - r.

Strang stops there — the SVD could be developed further, and it returns in the very last lectures of the course.

Problems

Work these with the recipe from the lecture: ATAA^TA for the v\mathbf{v}‘s and σ\sigma‘s, then ui=Avi/σi\mathbf{u}_i = A\mathbf{v}_i/\sigma_i.

Problem 29.1 Full SVD, invertible case

Find the singular value decomposition of

A=[2211].A = \begin{bmatrix} 2 & 2 \\ -1 & 1 \end{bmatrix}.
Show solution

Compute ATA=[5335]A^TA = \begin{bmatrix} 5 & 3 \\ 3 & 5 \end{bmatrix}. Its eigenvectors are (1,1)(1,1) with eigenvalue 88 and (1,1)(1,-1) with eigenvalue 22. So

V=12[1111],Σ=[8002]=[22002].V = \frac{1}{\sqrt 2}\begin{bmatrix} 1 & 1 \\ 1 & -1 \end{bmatrix}, \qquad \Sigma = \begin{bmatrix} \sqrt 8 & 0 \\ 0 & \sqrt 2 \end{bmatrix} = \begin{bmatrix} 2\sqrt 2 & 0 \\ 0 & \sqrt 2 \end{bmatrix}.

Now the safe rule for the u\mathbf{u}‘s: Av1=12(4,0)=(22,0)A\mathbf{v}_1 = \tfrac{1}{\sqrt 2}(4, 0) = (2\sqrt 2, 0), so u1=Av1/σ1=(1,0)\mathbf{u}_1 = A\mathbf{v}_1/\sigma_1 = (1, 0). And Av2=12(0,2)=(0,2)A\mathbf{v}_2 = \tfrac{1}{\sqrt 2}(0, -2) = (0, -\sqrt 2), so u2=(0,1)\mathbf{u}_2 = (0, -1) — note the minus sign that the eigenvectors of AATAA^T alone would not have decided. Then

A=[1001][22002]12[1111],A = \begin{bmatrix} 1 & 0 \\ 0 & -1 \end{bmatrix} \begin{bmatrix} 2\sqrt 2 & 0 \\ 0 & \sqrt 2 \end{bmatrix} \frac{1}{\sqrt 2}\begin{bmatrix} 1 & 1 \\ 1 & -1 \end{bmatrix},

and multiplying it out recovers AA: first row 22/2=22\sqrt 2/\sqrt 2 = 2 twice; second row 2/2=1-\sqrt 2/\sqrt 2 = -1 and +1+1.

Problem 29.2 Rank-one SVD

Find the SVD of the rank-one matrix

A=[3434].A = \begin{bmatrix} 3 & 4 \\ 3 & 4 \end{bmatrix}.

Identify which columns of VV and UU are bases for the row space, column space, null space, and null space of ATA^T.

Show solution

The row space is the line of multiples of (3,4)(3,4); the column space is the line of multiples of (1,1)(1,1). Unit vectors: v1=(0.6,0.8)\mathbf{v}_1 = (0.6, 0.8) and u1=12(1,1)\mathbf{u}_1 = \tfrac{1}{\sqrt 2}(1,1).

For σ1\sigma_1: ATA=[18242432]A^TA = \begin{bmatrix} 18 & 24 \\ 24 & 32 \end{bmatrix} has rank one, so one eigenvalue is 00 and the other is the trace, 5050. Thus σ1=50=52\sigma_1 = \sqrt{50} = 5\sqrt 2. Check: Av1=(1.8+3.2, 1.8+3.2)=(5,5)=5212(1,1)A\mathbf{v}_1 = (1.8 + 3.2,\ 1.8 + 3.2) = (5, 5) = 5\sqrt 2 \cdot \tfrac{1}{\sqrt 2}(1,1). Correct.

Complete the bases with the perpendicular directions: v2=(0.8,0.6)\mathbf{v}_2 = (0.8, -0.6) spans the null space, u2=12(1,1)\mathbf{u}_2 = \tfrac{1}{\sqrt 2}(1, -1) spans the null space of ATA^T. Then

A=12[1111][52000][0.60.80.80.6].A = \frac{1}{\sqrt 2}\begin{bmatrix} 1 & 1 \\ 1 & -1 \end{bmatrix} \begin{bmatrix} 5\sqrt 2 & 0 \\ 0 & 0 \end{bmatrix} \begin{bmatrix} 0.6 & 0.8 \\ 0.8 & -0.6 \end{bmatrix}.

Column 1 of VV: row space. Column 1 of UU: column space. Column 2 of VV: null space. Column 2 of UU: left null space. The zero in Σ\Sigma wipes out the null space directions.

Problem 29.3 Symmetric positive definite case

Let A=[2112]A = \begin{bmatrix} 2 & 1 \\ 1 & 2 \end{bmatrix}. Find its SVD, and explain why in this case one orthogonal matrix serves as both UU and VV.

Show solution

AA is symmetric positive definite: its eigenvalues are 33 (eigenvector (1,1)(1,1)) and 11 (eigenvector (1,1)(1,-1)) — both positive. Because AA is symmetric, the eigenvectors are orthogonal, so the eigenvector matrix can be taken orthogonal:

Q=12[1111],A=Q[3001]QT.Q = \frac{1}{\sqrt 2}\begin{bmatrix} 1 & 1 \\ 1 & -1 \end{bmatrix}, \qquad A = Q \begin{bmatrix} 3 & 0 \\ 0 & 1 \end{bmatrix} Q^T.

This is already orthogonal times diagonal times orthogonal with a positive diagonal, so it is the SVD, with U=V=QU = V = Q and σ1=3\sigma_1 = 3, σ2=1\sigma_2 = 1. Consistency check via the recipe: ATA=A2A^TA = A^2 has eigenvalues 99 and 11, whose positive square roots are 33 and 11 — the singular values of a symmetric positive definite matrix are exactly its eigenvalues.

Problem 29.4 Shared eigenvalues, quick reasoning

(a) Without computing them, explain why ATAA^TA and AATAA^T always have the same nonzero eigenvalues. (b) What are the singular values of an orthogonal matrix QQ?

Show solution

(a) The eigenvalues of ABAB are the same as the eigenvalues of BABA — eigenvalues don’t change when the order of multiplication is switched. Take B=ATB = A^T: then ATAA^TA and AATAA^T share their nonzero eigenvalues, which are the σi2\sigma_i^2 of the SVD. (Directly: if ATAv=λvA^TA\mathbf{v} = \lambda\mathbf{v} with λ0\lambda \neq 0, multiply by AA to get AAT(Av)=λ(Av)AA^T(A\mathbf{v}) = \lambda(A\mathbf{v}), and Av0A\mathbf{v} \neq \mathbf{0} since λ0\lambda \neq 0.)

(b) For an orthogonal matrix, QTQ=IQ^TQ = I, whose eigenvalues are all 11. The singular values are the positive square roots, so every σi=1\sigma_i = 1. An orthogonal matrix stretches nothing — its SVD is Q=QIITQ = Q \cdot I \cdot I^T.