Matrix Decompositions & SVD
You can't tell much about 12 until you write it as — then everything about it is obvious. This unit does the same to matrices: take the tangled transformation apart into a few pure moves — rotate, stretch, rotate back. We climb a three-rung ladder: the flawless symmetric case, the general square case, and then the boldest factorization in linear algebra — the SVD, which works on every matrix ever written, and whose truncation is the mathematics inside image compression, recommender systems, and PCA.
Taking things apart — the oldest trick in mathematics
Someone hands you the number 5040 and asks: is it divisible by 48? Ugly question — until you factor it: , and . Read the exponents: yes, instantly. You didn't change the number; you revealed what it was made of. Now recall from Unit 1 that a matrix isn't a grid of numbers — it's a verb, a machine that moves space. A raw matrix tangles rotation, stretching, and shearing into one bundle of entries. Matrix decomposition is prime factorization for transformations: rewrite as a short sequence of pure moves you can actually picture.
The punchline of the whole unit, up front: almost every matrix you'll meet can be written as rotate → stretch along axes → rotate. The three famous decompositions are not three unrelated tricks — they are one idea applied to progressively harder matrices, each rung dropping one requirement and gaining one power:
Why climb in this order? Because each rung teaches one lesson. Spectral shows the dream scenario: perpendicular axes, real scalings, no distortion. Eigendecomposition asks what if the natural axes lean? — the idea survives, but the tidy transpose becomes a real inverse. And SVD asks the boldest question — what if the matrix isn't even square, so "eigenvector" is meaningless? — and answers it with one elegant move that works for every matrix in existence.
When we factor , the number doesn't change. What's the analogue for ?
The shape we're chasing — diagonal matrices are trivial
Every decomposition in this unit is a scheme for smuggling a diagonal matrix into the middle of the product. Why the obsession? Because for a diagonal
every hard matrix question collapses into arithmetic on separate numbers. The determinant is just the product (Unit 4's volume dial, read off directly). The -th power is each entry raised to the — no matrix multiplication at all. The inverse is each non-zero entry flipped to . Solving is one-line divisions. A diagonal matrix is independent one-dimensional problems wearing a trench coat — nothing interacts, nothing tangles.
So the game is: given a general , find a change of viewpoint in which becomes diagonal. That's it. That's the unit.
. What is , and how long did it take you?
Diagonalizable — same machine, better glasses
Formally: is diagonalizable if there is an invertible and a diagonal with
Where do and come from? Multiply the definition out. , and because is diagonal, the product just scales each column of by its own diagonal entry. Column by column, says:
— which you have seen before. The columns of must be eigenvectors of , and the diagonal of must be their eigenvalues. Diagonalization isn't a new technique; it is Unit 4's eigen-hunt, repackaged as a factorization. The lecture's opening example: with gives — and sure enough, the columns and are exactly the eigenvectors of for and (check: ✓).
One catch, straight from Unit 4's fine print: this needs n independent eigenvectors to fill 's columns — and must be genuinely invertible. Matrices with enough eigenvectors get the luxury; defective ones (the shear!) are turned away at the door. Hold that thought for Section 6.
Rung 1 · Spectral — the flawless case, plus a reading you haven't seen
The trampoline. Grab a circular trampoline at two perpendicular points and pull: one axis stretches by , the perpendicular one by , and the circle becomes an ellipse whose axes line up exactly with your hands. That is a symmetric matrix: pure stretch along perpendicular directions, no twist. Unit 4's Spectral Theorem is the guarantee: symmetric has orthonormal eigenvectors and real eigenvalues, so
, with free of charge.
In the language of this unit: spectral decomposition is diagonalization where happens to be orthonormal — the lucky rung where the inverse costs nothing.
Now the new reading, and it's the most important formula of the unit. Multiply out column-against-row instead of the usual row-against-column, and the product unpacks into a sum of rank-1 layers:
Each block is a projector — Unit 3's shadow machine, boxed up as a matrix: it flattens any input onto the line through . So a symmetric matrix literally reads: "project onto axis 1 and amplify by , plus project onto axis 2 and amplify by , …" The eigenvalues become an honest importance ranking of the axes. Toggle the layers yourself:
The lecture's 3 × 3 spectral workout — every step
Decompose (symmetric, so the theorem applies). Eigenvalues: gives , , — all real, as promised. Eigenvectors: solving each by Unit 1 elimination: , , . Sanity check for free: , — orthogonality arrived without being asked, the Spectral Theorem working in the wild. Assembled: with , or as layers: — the first layer does most of the work, the layer is a finishing touch.
In , undoing the rotation costs a transpose. In , it costs a genuine matrix inverse. What buys symmetric matrices the discount?
Rung 2 · Eigendecomposition — speak the matrix's native language
A general square matrix looks chaotic in your standard grid because it rotates and stretches at once. But the matrix has a private coordinate system — its eigenvectors — in which it does nothing but scale numbers. is a translator: read right-to-left, translates your vector into the matrix's native eigen-language, does the embarrassingly simple scaling there, and translates back to your language. The transformation was never complicated — you were just listening in the wrong language.
The price of leaving the symmetric world: the eigenvectors lean. For the lecture's : eigenvalues from , so (a negative eigenvalue — flip-and-scale — something a positive-definite symmetric matrix never shows). Eigenvectors: and . Check the angle: — not perpendicular. So is invertible but not orthonormal, and the clean transpose is gone: , computed honestly.
Why bother? The payoff is matrix powers for free. Sandwiched between and , repeated multiplication telescopes — every interior collapses to :
Computing by brute force is nine dot products, twice. With the decomposition: cube two numbers (, ) and translate once — , done. The same telescope drives matrix exponentials, Markov-chain steady states, and the long-run behaviour of recurrent networks. Watch the translator and the telescope run:
Using with : what happens to for large even ?
Diagonalize the triangular in your head: eigenvalues, and is this spectral or merely eigen?
Where the ladder breaks — and why we need one more rung
Eigendecomposition is powerful, but it has a door policy, and Unit 4 already showed you both bouncers. Defective matrices: the shear owns a single eigen-direction — algebraic multiplicity 2, geometric multiplicity 1 — so there aren't enough independent columns to build an invertible . No decomposition. Rotations: turns every real direction, its eigenvalues fled to — no real exists at all. And beyond both: a data matrix isn't even square, so is meaningless — the input is 2-D, the output 3-D; they can't be parallel because they don't live in the same space.
Three failures, one root cause: eigendecomposition insists on using a single set of axes for both input and output. The fix — dropping that insistence — is the SVD, and it repairs all three failures at once.
Rung 3 · SVD — two frames, every matrix, no exceptions
Eigendecomposition asked: "which directions does the matrix not rotate?" — too demanding; rotations and rectangles refuse. SVD asks the question that always has an answer: "which perpendicular frame of input directions lands on a perpendicular frame of output directions?" Feed any matrix the unit circle (or sphere) and the output is always a perfect ellipse (or ellipsoid). SVD names the perpendicular input directions that map onto the ellipse's perpendicular axes . Two frames instead of one — that single generosity makes it universal.
The theorem, in full dress. Every of rank factors as
where is orthonormal (the right-singular vectors — input axes), is orthonormal (the left-singular vectors — output axes), and is "diagonal" with the singular values on its diagonal, sorted loudest-first by convention, padded with zeros to match 's shape. Read right-to-left, it is the unit's mantra in its final form: rotates the input so the special directions sit on the axes, stretches each axis by , rotates into the final pose. Rotate · stretch · rotate — now for any matrix, including the ones eigendecomposition rejected:
The rotation had no real eigendecomposition. Its SVD?
has eigenvalues and (triangular shortcut). Are its singular values also 3 and 5?
Building U, Σ, V — the symmetric-matrix bridge
Where do the three factors come from? From the rung we already own. may be rectangular, but (size ) and (size ) are both square, symmetric — Unit 4's Gram matrices — so Rung 1 applies to them. Substitute the SVD and watch the structure fall out:
That is a spectral decomposition of — so is its eigenvector matrix, and the eigenvalues sitting in are : the singular values are the square roots of 's eigenvalues (which the spectral theorem guarantees are real and — this is why σ's never go negative or complex). Symmetrically, hands to us as the eigenvectors of . And in practice you never even compute the second one: post-multiplying by gives , i.e. column by column
— each output axis is just the normalized image of its input axis. One eigendecomposition plus matrix–vector products and you own the whole factorization.
① Form the smaller of or . ② Spectrally decompose it (Rung 1 / Unit 4 machinery). ③ , sorted descending, zeros dropped. ④ Its eigenvectors are (or ); the other family comes free via . ⑤ Assemble , padding with zero rows/columns to match 's shape.
The lecture's wide example, walked through. (2×3, rank 2). Step 1: , symmetric as promised. Step 2: its eigenvalues are — the zero is no accident: a 2×3 matrix has rank at most 2, so one input direction must be crushed. Step 3: , so — 2×3 like , with a zero column of padding. Step 4: eigenvectors , , — and , riding the zero eigenvalue, is exactly the nullspace direction annihilates. Step 5: , — automatically orthonormal. Assembled, exactly.
The tall twin: SVD of B = [[1,1],[0,1],[1,0]] — featuring an old friend
is 3×2, so be smart and take the smaller Gram matrix: — the very matrix this unit keeps meeting. Its spectral data is memorized by now: on , . So , as above, and , . A third vector completes the 3×3 but rides on : pads with a zero row, because sends 2-D into 3-D and the third output dimension receives nothing. Tall matrices pad with zero rows (unreachable outputs); wide ones with zero columns (annihilated inputs). always wears 's shape.
You need the SVD of a 1000×3 dataset matrix. Which Gram matrix do you eigendecompose?
In the wide example, carries . What is this direction, in Unit 1's vocabulary?
Seeing a rectangular matrix — 2-D in, 3-D out
This is the picture eigendecomposition could never draw: a matrix whose input and output live in different spaces. eats a flat 2-D vector and produces a point in 3-D. Feed it the whole unit circle and the output is an ellipse — but an ellipse floating on a tilted plane inside 3-D space, the plane spanned by and . The third output direction sticks out of that plane and receives exactly nothing — it is the zero row of made visible. Drag the probe around the input circle and watch its image travel the ellipse:
The layer cake — low-rank approximation, live
Now collect the unit's two best ideas and let them collide. Section 4 read a symmetric matrix as a sum of importance-ranked projection layers. The SVD does the same for every matrix: multiply out column-against-row and 's diagonal pairs each with its :
— a stack of rank-1 layers, sorted loudest-first because the σ's are sorted. Since real-world matrices concentrate their energy in the first few singular values, truncating the sum at terms gives the rank- approximation , and the Eckart–Young theorem says this is not merely a compression — it is provably the best possible rank- approximation of , with error exactly the loudest singular value you discarded: .
The companion's tiny example, by hand: keep only the loudest layer of the tall . , and the error is the dropped . Six numbers describing a matrix of six — no saving yet at this toy size. But scale it up: an image is a matrix, and now the layer cake becomes a compressor. Try it:
Switch the widget to pure noise and drag : the reconstruction barely improves, because noise spreads its energy evenly across all singular values — there are no quiet layers to discard for free. Structure compresses; noise doesn't. Flip that insight around and you get denoising: real signal hides in the loud early layers, noise in the faint tail, so truncating the SVD removes noise. One theorem, two superpowers.
You keep layers of a matrix whose singular values are . What is ?
A image, stored as rank-50 layers: roughly what fraction of the original million numbers?
The spectral norm — and the family portrait
One last gift from the SVD. Ask: what is the most a matrix can ever amplify a vector? That worst-case stretch is the spectral norm,
— simply the longest semi-axis of the output ellipsoid, achieved by feeding in (the output points along ). The lecture's example: has , so — and the ratio says this matrix amplifies its favourite direction fifteen times more than its least favourite: fairly ill-conditioned, the kind of matrix that makes numerical software sweat. Spectral norms bound errors, govern the stability of deep networks (exploding/vanishing signals track products of σ's), and put the "spectral" in spectral normalization for GANs.
And the family portrait, one table to close the ladder:
| Eigen / Spectral | SVD | |
|---|---|---|
| Form | (or ) | |
| Works on | square, with enough eigenvectors | every matrix, any shape, always |
| Frames | one set of axes (input = output) | two sets: input , output |
| Orthogonality | generally not orthogonal | always orthonormal |
| Diagonal entries | eigenvalues — can be negative or complex | singular values — always real, , sorted |
| Outer factors | are inverses | generally unrelated |
| The link | = eigenvectors of · = eigenvectors of · | |
For , which number is ?
The whole story, in five lines
① A matrix is a transformation, and decomposition is prime factorization for transformations: rewrite as rotate → stretch → rotate, without changing what it does. ② The chase is always for a diagonal middle — because diagonal matrices reduce every question to arithmetic on separate numbers. ③ Spectral (, symmetric only) is the flawless rung: perpendicular axes, free transpose, and the layer reading . Eigen (, square + enough eigenvectors) keeps the idea on tilted axes and pays with an inverse — earning . ④ SVD () drops every remaining requirement by using two orthonormal frames bridged by non-negative stretches — built from the spectral decomposition of , with for free. ⑤ Sorting the σ's turns every matrix into a loudest-first layer cake: truncate for the provably-best low-rank approximation (Eckart–Young), read as the worst-case amplification (spectral norm), and you hold the mathematics of compression, denoising, PCA, and recommenders in one formula.
Every matrix is rotate · stretch · rotate. The only questions are whether the two rotations are the same (symmetric), whether they're transposes or inverses (spectral vs eigen), and how fast the stretches fade (that's compressibility). Once you sort the stretches loudest-first, keeping the top few is the best summary a matrix can have — and half of applied ML is exactly that act.