Part II — Linear Algebra & Matrix Decompositions · Chapter 7

Singular Value Decomposition (SVD)

Hook

Chapter 5 showed a matrix stretching, rotating, and flipping a vector. Every direction you dragged got bent somewhere else — except, it turns out, two of them. Are there directions a matrix leaves alone?

Intuition
v = (3.0, -1.0) → Av = (1.0, 5.0) — rotated by 97.1°

Drag vv around. Most of the time, AvAv points somewhere completely different — the angle between them swings all over the place. But two opposite directions are special: keep dragging near the diagonal and watch that rotation angle collapse toward 0°.

Formalize

A vector vv is an eigenvector of AA if AA doesn't rotate it at all — only scales it:

Av=λvAv = \lambda v
  • AA — the matrix being analyzed.
  • vv — the eigenvector: a direction AA only scales, never rotates.
  • λ\lambda — the eigenvalue: how much that direction gets stretched (or flipped, if negative).
  1. What the eigenvalue means

    λ\lambda is the corresponding eigenvalue: how much that direction gets stretched (or, if λ<0\lambda<0, stretched and flipped).

For a symmetric matrix, the eigenvectors are always perpendicular to each other, and AA can be rebuilt exactly from them:

A=QΛQA = Q\Lambda Q^\top
  • QQ — the matrix whose columns are the (unit) eigenvectors of AA.
  • Λ\Lambda — the diagonal matrix holding the eigenvalues, in the same order as QQ's columns.
  1. Naming the eigendecomposition

    Here QQ's columns are the (unit) eigenvectors and Λ\Lambda is diagonal with the eigenvalues on it — this is the eigendecomposition.

  2. Generalizing to the SVD

    The singular value decomposition (SVD), A=UΣVA = U\Sigma V^\top, is the same idea generalized to any matrix, square or not — but its diagonal Σ\Sigma is always non-negative, so a negative eigenvalue's direction gets its sign absorbed into UU instead.

Play
rotation = 97.1° | stretch = |Av|/|v| = 1.61

Watch the stretch ratio Av/v|Av|/|v| alongside the rotation angle. At the two special directions, the ratio locks onto a fixed number — that number is λ|\lambda| for that direction, no matter how far out you drag vv along it.

Worked example

For A=(1221)A = \begin{pmatrix}1&2\\2&1\end{pmatrix}:

  1. Solve the characteristic equation

    det(AλI)=(1λ)24=λ22λ3=(λ3)(λ+1)=0\det(A-\lambda I) = (1-\lambda)^2 - 4 = \lambda^2 - 2\lambda - 3 = (\lambda-3)(\lambda+1) = 0, so λ1=3\lambda_1 = 3 and λ2=1\lambda_2 = -1.

  2. Solve for each eigenvector
    • For λ1=3\lambda_1=3: (A3I)v=02x+2y=0x=y(A-3I)v=0 \Rightarrow -2x+2y=0 \Rightarrow x=y, giving direction (1,1)(1,1).
    • For λ2=1\lambda_2=-1: (A+I)v=0x+y=0(A+I)v=0 \Rightarrow x+y=0, giving direction (1,1)(1,-1).

    Normalized, these are v1=(12,12)v_1=(\tfrac{1}{\sqrt2},\tfrac{1}{\sqrt2}) and v2=(12,12)v_2=(\tfrac{1}{\sqrt2},-\tfrac{1}{\sqrt2}) — exactly the 45°45° and 45°-45° directions from the demo above.

  3. Turn it into an SVD

    Singular values are λ|\lambda|, sorted:

    • σ1=3\sigma_1=3
    • σ2=1\sigma_2=1

    Since λ2\lambda_2 is negative, its left singular vector flips sign:

    • u1=v1=(12,12)u_1=v_1=(\tfrac{1}{\sqrt2},\tfrac{1}{\sqrt2})
    • u2=v2=(12,12)u_2=-v_2=(-\tfrac{1}{\sqrt2},\tfrac{1}{\sqrt2})

    Each term is a rank-1 outer product, scaled by its singular value:

    • σ1u1v1=3(0.50.50.50.5)=(1.51.51.51.5)\sigma_1 u_1v_1^\top = 3\begin{pmatrix}0.5&0.5\\0.5&0.5\end{pmatrix} = \begin{pmatrix}1.5&1.5\\1.5&1.5\end{pmatrix}
    • σ2u2v2=1(0.50.50.50.5)\sigma_2 u_2v_2^\top = 1\begin{pmatrix}-0.5&0.5\\0.5&-0.5\end{pmatrix}

    Adding the two terms entrywise reconstructs AA exactly:

    (1.51.51.51.5)+(0.50.50.50.5)=(1221)\begin{pmatrix}1.5&1.5\\1.5&1.5\end{pmatrix} + \begin{pmatrix}-0.5&0.5\\0.5&-0.5\end{pmatrix} = \begin{pmatrix}1&2\\2&1\end{pmatrix}
Checkpoint

Drag v until Av points the same direction as v — angle under 2°. Hint: it's near the diagonal, like (0.71, 0.71).

rotation = 97.1° | A = [[1, 2], [2, 1]]
Drag v to try it
Summary
Av=λvA=QΛQ(symmetric)A=UΣV(any matrix)Av = \lambda v \qquad\qquad A = Q\Lambda Q^\top \quad(\text{symmetric}) \qquad\qquad A = U\Sigma V^\top \quad(\text{any matrix})

Every matrix has a set of directions it only stretches, never rotates — the eigendecomposition finds them exactly, by solving one polynomial. This isn't just an algebra exercise: later, Part II's PCA (Principal Component Analysis) chapter finds "the direction of maximum variance" by eyeballing a scatter plot. That direction is the top eigenvector of the data's covariance matrix — this chapter's machinery is what actually computes it, instead of eyeballing it.