Diagonalization only works for some square matrices, and orthogonal diagonalization only for symmetric ones. The singular value decomposition (SVD) works for every matrix, of any shape. It says that any linear map, viewed in the right orthonormal bases for its input and output spaces, simply stretches along perpendicular directions. The SVD powers image compression, principal component analysis, recommendation systems, and the numerical computation of rank.
Singular values
Let A be an m×n matrix. The matrix ATA is n×n and symmetric, so it has an orthonormal eigenbasis v1,…,vn with real eigenvalues λ1,…,λn. These eigenvalues are never negative, because for a unit eigenvector vi,
The singular values of A are the square roots of the eigenvalues of ATA, listed in decreasing order:
σ1≥σ2≥⋯≥σn≥0,σi=λi.
By the computation above, σi=∥Avi∥: the singular value is the length of A applied to the unit eigenvector vi.
Two more facts follow quickly. First, for i=j, (Avi)⋅(Avj)=viTATAvj=λj(vi⋅vj)=0, so the vectors Av1,…,Avn are orthogonal. Second, the nonzero ones among them form a basis for ColA, so
rankA=the number of nonzero singular values.
The singular values also measure stretching. By the constrained extremes result from the last lesson applied to ∥Ax∥2=xT(ATA)x, the largest value of ∥Ax∥ over unit vectors x is σ1, reached at x=v1, and the smallest is σn.
The decomposition
Suppose A has rank r, so σ1,…,σr are positive and the rest are 0. Normalize the orthogonal vectors Avi:
ui=σi1Avi(i=1,…,r).
These are orthonormal vectors in Rm. If r<m, extend them to an orthonormal basis u1,…,um of Rm. Since Avi=σiui for every i (both sides are 0 when i>r), putting these equations side by side gives AV=UΣ, and multiplying on the right by VT=V−1 gives the theorem.
The singular value decomposition
Every m×n matrix A of rank r can be factored as
A=UΣVT,
where
V is an n×n orthogonal matrix whose columns vi (the right singular vectors) are an orthonormal eigenbasis of ATA;
Σ is the m×n matrix with σ1,…,σr in the first r diagonal positions and zeros everywhere else;
U is an m×m orthogonal matrix whose first r columns (the left singular vectors) are ui=σi1Avi.
Read right to left, Ax=UΣVTx says: rotate (or reflect) with VT, stretch along the coordinate axes by the singular values with Σ, then rotate (or reflect) with U. In particular, A maps the unit circle to an ellipse whose semi-axes are σ1u1 and σ2u2.
The recipe
Compute ATA and its eigenvalues. Order them from largest to smallest.
Find an orthonormal eigenvector vi for each eigenvalue. These are the columns of V.
The singular values are σi=λi. Build Σ with the same shape as A.
For each nonzero σi, compute ui=Avi/σi. If you need more columns for U, complete to an orthonormal basis of Rm.
Worked example: A square matrix
Find an SVD of A=[3405].
ATA=[3045][3405]=[25202025].
Its eigenvalues are 45 (eigenvector (1,1)) and 5 (eigenvector (−1,1)). So σ1=45=35, σ2=5, and
v1=21(1,1),v2=21(−1,1).
Next, Av1=21(3,9), so u1=351⋅21(3,9)=101(1,3). And Av2=21(−3,1), so u2=101(−3,1). Therefore
(For instance, ATA(1,2,1)=(3,6,3).) The singular values are 3, 1 and 0, so A has rank 2. Then Av1=61(3,3), which divided by 3 gives u1=21(1,1), and Av2=21(1,−1)=u2. Since A is 2×3, Σ is 2×3:
The vector v3, which has singular value 0, spans NulA.
Common mistake
Singular values are not the eigenvalues of A. They are the square roots of the eigenvalues of ATA. For example, [0010] has only the eigenvalue 0, but its singular values are 1 and 0. The one exception: for a symmetric matrix, the singular values are the absolute values of the eigenvalues.
The SVD as a sum, and low-rank approximation
Multiplying out UΣVT column-by-row gives the outer-product form
A=σ1u1v1T+σ2u2v2T+⋯+σrurvrT,
a sum of r rank-one matrices, from most important to least. Keeping only the first k terms gives a matrix Ak of rank k, and it can be proved that Ak is the closest rank-k matrix to A. This is how the SVD compresses data: a 1000×1000 image stored as k=50 terms needs about 50⋅2001≈100,000 numbers instead of 1,000,000.
Worked example: A rank-one matrix
Find the singular values of A=212212 and write A in outer-product form.
ATA=[9999] has eigenvalues 18 and 0, with v1=21(1,1). So σ1=18=32 and σ2=0; the rank is 1.
Av1=21(4,2,4), and dividing by 32 gives u1=31(2,1,2). Therefore