Visual walkthrough — QR decomposition
Before line one, three plain words we will lean on the whole way:
We will use the tiny matrix as our running board example. Two crooked arrows in 3D. Let's straighten them.
Step 1 — Plant the first clean axis
WHAT. We take the first crooked arrow and shrink it to length , keeping its direction. Call the result .
- — the raw first arrow.
- — its length, found by the dot product with itself.
- dividing by — the only thing that changes is the length (); the direction is untouched.
So .
WHY. Every other arrow will be measured against . A ruler must have length before you measure with it — that's all "normalize" means.
PICTURE. The pale-yellow arrow is ; the blue arrow is the shortened lying right on top of it, now exactly one unit long.
Step 2 — Measure the shadow of the second arrow
WHAT. Before we clean , we ask: how much of already points along ? That amount is a single number,
- — dot product = "how far reaches in the direction."
- the result — the length of the shadow casts on the line.
- we name it — it will become an entry of the recipe card (row , column ).
WHY. The dot product is chosen precisely because it reads off a shadow length. This is the projection idea: is the piece of that is "already explained" by our first axis.
PICTURE. Drop a dashed perpendicular from the tip of onto the line. Where it lands marks the shadow (pink).
Step 3 — Subtract the shadow to reveal the new direction
WHAT. Erase the explained piece. Whatever remains must be perpendicular to :
- — the full second arrow.
- — the shadow from Step 2, now scaled back into a real arrow.
- — the leftover, the part of at a right angle to .
Check it worked: . ✓ Perpendicular, exactly as promised.
WHY. Subtracting the shadow is the whole trick of the Gram-Schmidt process: remove what's shared, keep what's new. A dot product of confirms the leftover is a brand-new independent direction.
PICTURE. Vector subtraction as a triangle: minus the pink shadow gives the green , standing at to the line.
Step 4 — Shrink the leftover to length one
WHAT. Turn into a unit ruler , and record its original length:
- — how long the new direction was before shrinking.
- — this length becomes the diagonal recipe entry (row , column ).
- — our second clean axis, length , perpendicular to .
WHY. We store the length in because we will need it to rebuild later. The unit vector is for measuring; the length is for reconstructing. Note automatically — the leftover was non-zero because our two arrows were genuinely different (linearly independent).
PICTURE. The green (length ) shrinks onto the blue unit . Now : a clean right-angle corner.
Step 5 — Read the recipe backwards: rebuild the originals
WHAT. We have clean axes . Now flip every equation to express the original arrows as combinations of clean ones:
- uses only — with .
- uses (amount ) and (amount ) — but never a later axis, because was cleaned before ever existed.
Collect the recipe numbers into a grid , and the clean axes into :
WHY the zero (upper-triangular)? was straightened before was born, so cannot appear in 's recipe — its coefficient is forced to . That single in the bottom-left is what "upper-triangular" means: each arrow only ever uses axes that already existed. This is the QR decomposition result, .
PICTURE. as an instruction card: column tells you the exact mix of that rebuilds . The bottom-left cell is greyed out — the "you can't use a future axis" rule.
Step 6 — The degenerate case: what if the leftover is zero?
WHAT. Suppose were a copy of 's direction, say . Its shadow onto would be the whole arrow, so the leftover is
WHY this breaks QR. To make we divide by — but here that is , and dividing by zero is undefined. Also , so 's diagonal is no longer strictly positive. Geometrically: there is no new direction to plant an axis in.
The rule this forces. QR (thin, with positive diagonal) needs the columns of to be linearly independent — no arrow may be a mix of the others. When they are independent, every leftover is non-zero, every , and the whole construction runs safely.
PICTURE. Two collinear yellow arrows: the shadow eats the entire second arrow, leaving nothing (a red dot at the origin) — the moment the algorithm has to stop.
Step 7 — Sign convention: why we insist
WHAT. Nothing stopped us from choosing pointing the opposite way (multiply by ). If we do, then flips sign too, and shifts to match — so still holds, but with a different and .
WHY. A factorization we cannot pin down is annoying. To make QR unique, we demand which is guaranteed the moment we always divide by a positive length. That one convention removes the sign ambiguity.
PICTURE. Same corner, two allowed choices of (up-blue vs down-pink); we keep the one giving a positive diagonal.
The one-picture summary
Everything above, on one board: crooked arrows on the left flow through "straighten & record" into the clean frame plus the triangular recipe , and multiplying them back reproduces .
Recall Feynman retelling — say it like a story
I had two bent arrows on the chalkboard. I grabbed the first one and just squeezed it to length one — that's my first clean ruler, . Then I looked at the second arrow and asked, "how much of you is just leaning the same way as my ruler?" That amount is one number, ; I wiped that part off. Whatever was left had to be standing at a perfect right angle — I squeezed that down to length one too and called it , writing down how long it had been (). Now I have a tidy square corner of rulers, . The little card of numbers I wrote down — " = so much of ruler 1", " = so much of ruler 1 plus so much of ruler 2" — is . Because arrow 1 was straightened before ruler 2 ever existed, ruler 2 can't show up in arrow 1's recipe, so one corner of is always zero — that's the triangle shape. If ever a "leftover" came out to nothing (the arrows were secretly the same direction), I'd be dividing by zero, so I only play this game with genuinely-different arrows and always keep the recorded lengths positive so the answer is one-of-a-kind.
Recall Quick self-test
- What number is geometrically? ::: The length of 's shadow on the line, i.e. .
- Why is the bottom-left of zero? ::: is built before exists, so 's coefficient in must be .
- What goes wrong if columns are dependent? ::: A leftover , so and we'd divide by zero.
- Which rule makes QR unique? ::: Every diagonal .
Connections
- Gram-Schmidt process — this walkthrough is Gram–Schmidt, drawn.
- Orthonormal bases and projections — Step 2's shadow is a projection.
- Least squares and normal equations — the payoff of having .
- Householder reflections — a rounding-stable route to the same .
- Eigenvalues and the QR algorithm — repeats this factorization.
- LU decomposition — a triangular sibling, without the clean frame.