Linear Algebra
9.88 min read

Computing SVD via Gram Matrix

Alternatively: (1) form G=AAG = A^\top A; (2) eigendecompose G=VΛGVG = V\Lambda_G V^\top; (3) set σi=(ΛG)ii\sigma_i = \sqrt{(\Lambda_G)_{ii}}; (4) compute ui=1σiAvi\mathbf{u}_i = \frac{1}{\sigma_i} A\mathbf{v}_i for nonzero σi\sigma_i; (5) extend for zero σi\sigma_i.

This path is preferred when n<mn < m (the Gram is smaller). Both paths give the same SVD. MATLAB: [U, S, V] = svd(A) chooses the optimal algorithm internally.

Formal View

Example 9.2 — SVD via Gram — Algorithm
Given AA (m×nm \times n), compute SVD via G=AAG = A^\top A: 1. Form G=AAG = A^\top A (n×nn \times n). 2. Eigendecompose: G=VΛGVG = V\Lambda_G V^\top, sort descending. 3. σi=λi\sigma_i = \sqrt{\lambda_i}; form Σ\Sigma. 4. ui=1σiAvi\mathbf{u}_i = \frac{1}{\sigma_i}A\mathbf{v}_i for σi>0\sigma_i > 0. 5. Verify: A=UΣVA = U\Sigma V^\top.

Interactive Visualization

Matrix Product — Column Perspective

Why This Matters

Choose Gram vs covariance path based on which gives the smaller matrix to decompose.

  • Wide data matrices (many features, few samples): Gram path is small.
  • Tall data matrices (many samples, few features): covariance path is small.
  • Square matrices: both paths equally sized; use bidiagonalization instead.

Quiz

Question 1

Given VV from the spectral decomposition of AAA^\top A, we compute ui=1σiAvi\mathbf{u}_i = \frac{1}{\sigma_i} A \mathbf{v}_i.

Question 2

For a 10000×5010000 \times 50 matrix, which path is more efficient?

Common Mistakes

  • Computing ui=Avi\mathbf{u}_i = A\mathbf{v}_i without dividing by σi\sigma_i — the result is not a unit vector.
  • Using the Gram path when the covariance path gives a much smaller matrix.