Understanding the singular value decomposition calculator — concept and principle
This calculator computes the singular value decomposition (SVD) A = U·Σ·Vᵀ of any matrix. It returns the singular values, the left singular vectors U, the diagonal matrix Σ, the right singular vectors V, the rank and the shapes of the thin SVD. Use it in linear algebra courses, data compression, principal component analysis, least squares and signal processing.
How it is calculated
- The singular values σ₁ ≥ σ₂ ≥ … ≥ 0 are the square roots of the eigenvalues of AᵀA.
- The columns vᵢ of V are the matching unit eigenvectors of AᵀA.
- The columns of U are uᵢ = A·vᵢ ÷ σᵢ.
- The thin SVD keeps k = min(m, n) columns in U and V.
The page uses a one-sided Jacobi method and fixes signs so the largest entry of each vᵢ is positive; singular vectors are unique only up to such sign flips (and rotations within repeated σ).
The principle
Every linear map can be broken into three simple steps: a rotation or reflection (Vᵀ), a stretch along perpendicular axes (Σ), and another rotation or reflection (U). The SVD finds those steps. The right singular vectors are the input directions that A maps to perpendicular output directions; the singular values are the stretch factors. Keeping only the largest few singular values gives the best low-rank approximation of A, which is the idea behind image compression and PCA.
Worked example
Default: A = [1 −1 3; 3 1 1].
- AAᵀ = [11 5; 5 11], with eigenvalues 16 and 6, so σ = 4, 2.44949 (√6).
- v₁ = (1, 0, 1)/√2 ≈ (0.707107, 0, 0.707107); v₂ = (1, 1, −1)/√3 ≈ (0.57735, 0.57735, −0.57735).
- u₁ = A·v₁ ÷ 4 = (4/√2, 4/√2) ÷ 4 = (0.707107, 0.707107).
- u₂ = A·v₂ ÷ √6 = (−3/√3, 3/√3) ÷ √6 ≈ (−0.707107, 0.707107).
- Σ = [4 0; 0 2.44949]; rank 2; shapes U 2×2, Σ 2×2, V 3×2.
How to read the result
The number of non-zero singular values is the rank. The ratio σ₁ ÷ σ_k shows how close the matrix is to losing rank. Each term σᵢ·uᵢ·vᵢᵀ is a rank-one piece of A; the first terms capture most of its "energy" when the singular values drop quickly. Different software may show opposite signs for a pair uᵢ, vᵢ; both are correct.
Common mistakes
- Expecting U and V to be unique; signs can flip in matched pairs.
- Confusing the thin SVD with the full SVD, which adds extra columns multiplied by zeros.
- Using eigen decomposition instead; it exists only for some square matrices.
- Forgetting the transpose on V in A = UΣVᵀ.
Frequently asked questions
What is the difference between SVD and eigendecomposition?
SVD exists for every matrix and uses two orthonormal bases; eigendecomposition needs a square matrix and may not exist.
How is SVD used for compression?
Keeping the largest r singular values and their vectors gives the best rank-r approximation in the least-squares sense.
Why does my software show different signs?
Flipping the sign of both uᵢ and vᵢ gives the same product, so both versions are valid.
Sources: Coordinated Linear Algebra (University of Nebraska–Lincoln), §7.7 Singular Value Decomposition · J. Demmel, UC Berkeley Math 221, Lecture 3 (Fall 2011)