Linear algebra · decomposition
Singular Value Decomposition: Rank, Condition and Approximation
The singular value decomposition, or SVD, writes any m × n matrix as A = UΣVᵀ. U and V are orthogonal matrices, and Σ is diagonal with non-negative entries σ₁ ≥ σ₂ ≥ … called singular values. Geometrically, A first rotates the input, then stretches each coordinate axis by a singular value, then rotates again. Unlike eigenvalues, singular values exist for every matrix, square or not, and they are always real.
How to compute it by hand
The singular values are the square roots of the eigenvalues of AᵀA, and the columns of V are its eigenvectors. Once a pair σᵢ and vᵢ is known, the matching column of U is uᵢ = Avᵢ/σᵢ.
Take A = [3 0; 4 5]. Then AᵀA = [25 20; 20 25], whose eigenvalues are 25 ± 20, that is 45 and 5. The singular values are σ₁ = √45 = 3√5 ≈ 6.708 and σ₂ = √5 ≈ 2.236. The eigenvectors are v₁ = (1, 1)/√2 and v₂ = (1, −1)/√2.
Now Av₁ = (3, 9)/√2, so u₁ = (3, 9)/(√2 · 3√5) = (1, 3)/√10. And Av₂ = (3, −1)/√2, so u₂ = (3, −1)/(√2 · √5) = (3, −1)/√10. These are orthogonal, since 1·3 + 3·(−1) = 0. As a check on the scale, |det A| = 15 and σ₁σ₂ = 3√5 · √5 = 15. In practice software uses stable iterative algorithms and never forms AᵀA, which would square the condition number.
Rank and condition number
The rank of A is the number of nonzero singular values. In floating point, a value that is zero in theory shows up as a tiny number, so codes count singular values above a tolerance, commonly the largest value times the matrix size times machine epsilon. This makes the SVD the most trustworthy rank test, and the columns of U belonging to nonzero values give an orthonormal basis for the range, a sibling of the orthonormal basis page.
The ratio σ₁/σₙ is the 2-norm condition number, the factor by which relative errors in the data can grow in the solution of a linear system. For the example it is 3√5/√5 = 3, which is excellent. A matrix with σₙ = 0 is singular, and a ratio near 10¹⁶ means that double precision carries no correct digits. The glossary entry on condition number explains the consequence in more detail.
Best low-rank approximation
Truncating the sum A = σ₁u₁v₁ᵀ + σ₂u₂v₂ᵀ + … after k terms gives the best rank-k approximation of A, in both the 2-norm and the Frobenius norm. For the example, keeping one term gives σ₁u₁v₁ᵀ = 3√5 · (1, 3)ᵀ(1, 1)/(√10 · √2). Since √10 · √2 = 2√5, the scalar in front is 3/2, and the approximation is [1.5 1.5; 4.5 4.5].
The error matrix is A minus that, [1.5 -1.5; -0.5 0.5]. Its squared Frobenius norm is 2.25 + 2.25 + 0.25 + 0.25 = 5, which is exactly σ₂². The discarded singular values measure the loss, so choosing k from a plot of singular values is a sound way to compress an image, denoise data, or reduce the number of variables in a model.
Least squares and the pseudoinverse
The pseudoinverse is A⁺ = VΣ⁺Uᵀ, where Σ⁺ inverts each nonzero singular value and leaves zeros alone. The vector x = A⁺b is the least squares solution of smallest length, and it is well defined even for rank-deficient problems where QR factorization needs extra care. It costs more than QR, which is why the SVD is chosen when rank is in doubt.
Other factorizations answer narrower questions: LU factorization for general square systems, Cholesky factorization for symmetric positive definite ones. The linear algebra section places the SVD among them.