4.5.40Linear Algebra (Full)

Singular Value Decomposition (SVD) — full derivation

2,045 words9 min readdifficulty · medium6 backlinks

WHAT is SVD?

WHY does this differ from eigen-decomposition? Eigen-decomposition A=PDP1A = P D P^{-1} only works for square matrices, and gives an orthogonal PP only when AA is symmetric. SVD works for every matrix, square or not, with two orthogonal bases (one for input space Rn\mathbb{R}^n, one for output space Rm\mathbb{R}^m).


HOW we derive it (from first principles)

The whole derivation rests on one safe object: AAA^\top A.

Step 1 — AAA^\top A is symmetric and positive semi-definite

Symmetric: (AA)=A(A)=AA(A^\top A)^\top = A^\top (A^\top)^\top = A^\top A. ✓

PSD: for any xx, x(AA)x=(Ax)(Ax)=Ax20x^\top (A^\top A) x = (Ax)^\top(Ax) = \|Ax\|^2 \ge 0. So every eigenvalue λi0\lambda_i \ge 0. Define σi:=λi0.\sigma_i := \sqrt{\lambda_i} \ge 0.

Step 2 — Build VV from the eigenvectors of AAA^\top A

By the Spectral Theorem, choose orthonormal eigenvectors v1,,vnv_1,\dots,v_n: AAvi=λivi=σi2vi,vivj=δij.A^\top A\, v_i = \lambda_i v_i = \sigma_i^2 v_i, \qquad v_i^\top v_j = \delta_{ij}. Order them so σ1σr>0=σr+1==σn\sigma_1 \ge \dots \ge \sigma_r > 0 = \sigma_{r+1}=\dots=\sigma_n. Set V=[v1vn]V = [\,v_1 \mid \dots \mid v_n\,]. This is orthogonal: VV=InV^\top V = I_n. These are the right singular vectors.

Step 3 — Define UU so that AviAv_i lines up

For iri \le r (where σi>0\sigma_i > 0) define ui:=1σiAvi.\boxed{\,u_i := \frac{1}{\sigma_i} A v_i\,}.

WHY divide by σi\sigma_i? We want uiu_i to be a unit vector. Check: Avi2=(Avi)(Avi)=viAAvi=vi(σi2vi)=σi2.\|Av_i\|^2 = (Av_i)^\top(Av_i) = v_i^\top A^\top A\, v_i = v_i^\top(\sigma_i^2 v_i) = \sigma_i^2. So Avi=σi\|Av_i\| = \sigma_i, and dividing makes ui=1\|u_i\| = 1. ✓

Are the uiu_i orthonormal? For iji\ne j: uiuj=1σiσj(Avi)(Avj)=1σiσjviAAvj=σj2σiσjvivj=σjσiδij=0.u_i^\top u_j = \frac{1}{\sigma_i\sigma_j}(Av_i)^\top(Av_j) = \frac{1}{\sigma_i\sigma_j} v_i^\top A^\top A v_j = \frac{\sigma_j^2}{\sigma_i\sigma_j} v_i^\top v_j = \frac{\sigma_j}{\sigma_i}\delta_{ij}=0.

So {u1,,ur}\{u_1,\dots,u_r\} is an orthonormal set in Rm\mathbb{R}^m. Extend it to a full orthonormal basis u1,,umu_1,\dots,u_m (Gram–Schmidt on any completion). Set U=[u1um]U = [\,u_1\mid\dots\mid u_m\,].

Step 4 — Assemble and verify A=UΣVA = U\Sigma V^\top

We have, by construction, for all ii: Avi=σiui(with σi=0 giving Avi=0 for i>r).A v_i = \sigma_i u_i \quad(\text{with } \sigma_i = 0 \text{ giving } Av_i = 0 \text{ for } i>r). Stack these as columns: A[v1vn]=[σ1u1σnun]A[v_1\dots v_n] = [\sigma_1 u_1 \dots \sigma_n u_n], i.e. AV=UΣ.A V = U \Sigma. Right-multiply by VV^\top (legal since VV=InVV^\top = I_n): A=UΣV.\boxed{A = U\Sigma V^\top}.


Figure — Singular Value Decomposition (SVD) — full derivation

The four fundamental subspaces (free bonus)


Worked Example 1 — a 2×22\times 2 matrix

Let A=(0110)A = \begin{pmatrix} 0 & 1 \\ -1 & 0 \end{pmatrix} (a 90°90° rotation).

Step A: form AAA^\top A. Why? It's our gateway. AA=(0110)(0110)=(1001)=I.A^\top A = \begin{pmatrix}0&-1\\1&0\end{pmatrix}\begin{pmatrix}0&1\\-1&0\end{pmatrix} = \begin{pmatrix}1&0\\0&1\end{pmatrix}=I. Step B: eigenvalues. λ1=λ2=1σ1=σ2=1\lambda_1=\lambda_2=1 \Rightarrow \sigma_1=\sigma_2=1. Why? A pure rotation stretches nothing — singular values =1=1 makes physical sense. Step C: any orthonormal VV works; take V=IV=I, so v1=e1,v2=e2v_1=e_1, v_2=e_2. Step D: ui=1σiAvi=Aviu_i = \tfrac1{\sigma_i}Av_i = Av_i: u1=Ae1=(0,1)u_1 = Ae_1 = (0,-1)^\top, u2=Ae2=(1,0)u_2 = Ae_2=(1,0)^\top. So U=(0110)U = \begin{pmatrix}0&1\\-1&0\end{pmatrix}, Σ=I\Sigma=I, V=IV^\top=I, and indeed UΣV=AU\Sigma V^\top = A. ✓


Worked Example 2 — a rank-1, non-square matrix

Let A=(111100)A = \begin{pmatrix} 1 & 1 \\ 1 & 1 \\ 0 & 0 \end{pmatrix} (m=3,n=2m=3,n=2).

Step A: AA=(2222)A^\top A = \begin{pmatrix}2&2\\2&2\end{pmatrix}. Why this step? Symmetric 2×22\times2, easy eigenproblem. Step B: eigenvalues solve det(AAλI)=0\det(A^\top A - \lambda I)=0: (2λ)24=0λ(λ4)=0(2-\lambda)^2-4=0 \Rightarrow \lambda(\lambda-4)=0. So λ1=4,λ2=0\lambda_1=4,\lambda_2=0, giving σ1=2,σ2=0\sigma_1=2,\sigma_2=0. Rank r=1r=1. Why one zero? Rows are identical → rank 1. Step C: eigenvector for λ1=4\lambda_1=4: v1=12(1,1)v_1=\tfrac1{\sqrt2}(1,1)^\top. For λ2=0\lambda_2=0: v2=12(1,1)v_2=\tfrac1{\sqrt2}(1,-1)^\top. Step D: u1=1σ1Av1=12A12(1,1)=122(2,2,0)=12(1,1,0)u_1 = \tfrac1{\sigma_1}Av_1 = \tfrac12 A\cdot\tfrac1{\sqrt2}(1,1)^\top = \tfrac1{2\sqrt2}(2,2,0)^\top = \tfrac1{\sqrt2}(1,1,0)^\top. Why? Confirms u1=1\|u_1\|=1. Extend to u2=12(1,1,0)u_2 = \tfrac1{\sqrt2}(1,-1,0)^\top, u3=(0,0,1)u_3=(0,0,1)^\top to complete the basis. A=U(200000)V,U=(1212012120001).A = U\begin{pmatrix}2&0\\0&0\\0&0\end{pmatrix}V^\top,\quad U=\begin{pmatrix}\tfrac1{\sqrt2}&\tfrac1{\sqrt2}&0\\ \tfrac1{\sqrt2}&-\tfrac1{\sqrt2}&0\\0&0&1\end{pmatrix}.


Common Mistakes (Steel-manned)


Flashcards

What object do we diagonalize first to derive SVD, and why is it safe?
AAA^\top A — it's always symmetric and positive semi-definite, so the Spectral Theorem gives an orthonormal eigenbasis with real non-negative eigenvalues.
Define the singular values in terms of AAA^\top A.
σi=λi\sigma_i = \sqrt{\lambda_i} where λi0\lambda_i \ge 0 are eigenvalues of AAA^\top A.
How are the left singular vectors uiu_i defined (for σi>0\sigma_i>0)?
ui=1σiAviu_i = \frac{1}{\sigma_i}Av_i, which guarantees they are unit vectors and correctly paired with viv_i.
Prove Avi=σi\|Av_i\| = \sigma_i.
Avi2=viAAvi=viσi2vi=σi2\|Av_i\|^2 = v_i^\top A^\top A v_i = v_i^\top \sigma_i^2 v_i = \sigma_i^2, so Avi=σi\|Av_i\|=\sigma_i.
Why are uiu_i for iji\ne j orthogonal?
uiuj=1σiσjviAAvj=σjσiδij=0u_i^\top u_j = \frac{1}{\sigma_i\sigma_j}v_i^\top A^\top A v_j = \frac{\sigma_j}{\sigma_i}\delta_{ij}=0.
What are the dimensions of U,Σ,VU,\Sigma,V for ARm×nA\in\mathbb{R}^{m\times n}?
UU is m×mm\times m, Σ\Sigma is m×nm\times n, VV is n×nn\times n.
Which singular vectors span the null space of AA?
The right singular vectors viv_i with σi=0\sigma_i=0 (i.e. i>ri>r).
Final SVD identity from AV=UΣAV=U\Sigma?
A=UΣVA = U\Sigma V^\top (right-multiply by VV^\top since VV=IVV^\top=I).
Is SVD restricted to square matrices?
No — it exists for every real m×nm\times n matrix, unlike eigen-decomposition.
Geometric meaning of A=UΣVA=U\Sigma V^\top?
Rotate/reflect (by VV^\top), stretch along axes (by Σ\Sigma), rotate/reflect again (by UU).

Recall Feynman: explain to a 12-year-old

Imagine a stamp that prints a wonky stretched shape onto paper. SVD says any such stamp does its job in three simple moves: first it spins the paper to a tidy angle, then it stretches it only along straight up-down and left-right directions (by amounts σ1,σ2,\sigma_1,\sigma_2,\dots), then it spins the result again. No matter how twisted the stamp looks, it's secretly just spin–stretch–spin. The stretch amounts are the singular values, and they tell you which directions the stamp cares about most (big σ\sigma) and which it squashes to nothing (zero σ\sigma).


Connections

  • Spectral Theorem — the symmetric eigen-decomposition that powers Step 1–2.
  • Eigenvalues and Eigenvectors — singular values are eigenvalues of AA\sqrt{\text{eigenvalues of } A^\top A}.
  • Four Fundamental Subspacesui,viu_i,v_i give orthonormal bases for all four.
  • Positive Semi-Definite Matrices — guarantees λi0\lambda_i \ge 0.
  • Low-Rank Approximation / Principal Component Analysis (PCA) — truncated SVD applications.
  • Moore-Penrose PseudoinverseA+=VΣ+UA^+ = V\Sigma^+ U^\top.
  • Gram-Schmidt Process — used to extend uiu_i to a full basis.

Concept Map

form

is

Spectral Theorem gives

eigenvalues lambda >= 0

assemble

orthogonal

fill diagonal

u_i = A v_i / sigma_i

maps via A

orthogonal

generalizes

Matrix A m x n

A transpose A

Symmetric and PSD

Orthonormal eigenvectors

Singular values sigma = sqrt lambda

V right singular vectors

V transpose V = I

Sigma diagonal non-negative

U left singular vectors

U transpose U = I

A = U Sigma V transpose

Eigen-decomposition

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dekho, SVD ka core idea bahut simple hai: koi bhi matrix AA — chahe square ho ya rectangular, chahe symmetric ho ya nahi — actually sirf teen kaam karta hai: ghumao, stretch karo, phir ghumao. Mathematically A=UΣVA = U\Sigma V^\top, jahan UU aur VV orthogonal hain (matlab pure rotations/reflections, lambai change nahi karte) aur Σ\Sigma diagonal hai non-negative entries ke saath (sirf stretching). Yeh eigen-decomposition se zyada powerful hai kyunki eigen-decomposition sirf square matrices pe kaam karta hai, par SVD har matrix pe chalta hai.

Derivation ka trick ek hi safe cheez se start hota hai: AAA^\top A. Yeh hamesha symmetric aur positive semi-definite hota hai, to Spectral Theorem se humein free mein orthonormal eigenvectors mil jaate hain. Inn eigenvectors se hum VV banate hain, aur eigenvalues λi\lambda_i ka square root lekar singular values σi=λi\sigma_i = \sqrt{\lambda_i} define karte hain. Phir har ui=Avi/σiu_i = Av_i / \sigma_i define karte hain — isse uiu_i unit vector ban jaata hai (kyunki Avi=σi\|Av_i\| = \sigma_i) aur sahi sign/pairing automatically lock ho jaata hai.

Sabse important baat geometry hai: jab tum unit circle ko AA se multiply karte ho, woh ek ellipse ban jaati hai. Ellipse ke axes ki lambai σ1,σ2\sigma_1, \sigma_2 hai, aur woh axes u1,u2u_1, u_2 directions mein point karte hain. Jo viv_i ka σi=0\sigma_i = 0 hai, woh null space mein chala jaata hai — matlab AA usko zero pe squash kar deta hai. Isi liye SVD matrix ki poori "geometry" ek hi tasveer mein dikha deta hai.

Yeh kyun matter karta hai? PCA, image compression, low-rank approximation, pseudoinverse — sab SVD pe based hain. Bade singular values "important directions" batate hain aur chhote/zero wale ignore kar sakte ho. Exam mein common galti: socho mat ki singular values matrix ke eigenvalues hain — woh $

Go deeper — visual, from zero

Test yourself — Linear Algebra (Full)

Connections