Visual walkthrough — Least squares — normal equations, QR approach
Step 1 — The vectors we are handed
WHAT. We have a bunch of "measurements" stacked into one tall list of numbers , and a machine that turns unknown dials into a prediction .
- A vector is just an arrow: a list of numbers that also points somewhere. is a point in -dimensional space.
- is a matrix: a rectangular grid of numbers with rows and columns, written . "Tall" means — more equations (rows) than unknowns (columns).
- are the unknowns — the dials we get to twist.
WHY. We want exactly. But with more equations than dials, the target usually cannot be hit. So we must define "as close as possible" before we can chase it.
PICTURE. In the figure, (plum) floats in space. As we twist the dials , the tip of (orange) can only reach a flat sheet — never quite touching .

Step 2 — Where can actually go? (the column space)
WHAT. Split into its columns (each column is itself an arrow in -space). Then Every term here scales a column-arrow by a dial number and adds them up. Twisting the dials sweeps out all possible mixtures of the columns.
- That set of all mixtures is the column space — see Column Space and Rank. It is a flat sheet (a subspace) through the origin.
WHY. Whatever we do, lives inside this sheet. So "closest reachable point to " means "closest point of the sheet to ." This turns an algebra problem into a geometry problem.
PICTURE. The two columns (teal) and (orange) span a tilted plane. Every reachable prediction is a dot somewhere on that plane; hovers off it.

Step 3 — "Closest" means shortest arrow — measured how?
WHAT. The gap between target and prediction is the residual: Its length is the Euclidean norm Under the square root each miss is squared (so signs can't cancel) and summed — this is just Pythagoras in dimensions.
WHY square the length instead of using the raw length? We will minimise (drop the square root). WHY is that legal and nicer? Because is a plain polynomial in the entries — a smooth, gently curved bowl whose minimum we can find by clean linear algebra, with no square root to carry around. And since squaring is an increasing function on lengths (), the same that makes the length smallest also makes its square smallest — we lose nothing by minimising the square.
PICTURE. Watch the residual arrow (plum) shrink and swing as the prediction dot slides across the plane. There is one position where it is shortest.

Step 4 — The shortest arrow is the perpendicular one
WHAT. Claim: the residual is shortest exactly when it stands perpendicular to the plane . This is the key geometric fact behind Orthogonal Projection.
WHY. Suppose the residual leaned even a little bit along the plane. Then that leaning component points in a direction we can actually reach (it is inside ). Slide the prediction dot a hair in that direction and the miss gets shorter — so we were not at the minimum. The only arrow you cannot shorten by sliding within the plane is the one with zero component in the plane — i.e. straight up, perpendicular.
PICTURE. Two candidate residuals: a slanted one (still shortenable, orange dashes) and the perpendicular winner (plum). The right-angle mark shows the winner meeting the plane at .

Step 5 — Turning "perpendicular" into equations
WHAT. "Perpendicular to the plane" means perpendicular to every spanning column . Two arrows are perpendicular when their dot product is zero — the dot product measures how much they line up; zero means they don't line up at all.
WHY. A plane is fully pinned down by its spanning arrows. If is perpendicular to each column, it is perpendicular to every mixture of them — the whole plane. So little equations capture the geometry exactly.
PICTURE. The residual makes a right angle with and with simultaneously — the two right-angle marks.

Step 6 — Stack the equations: the Normal Equations appear
WHAT. Writing all dot-product equations in one line means stacking the columns as the rows of (the transpose, flipped so its columns become rows): Distribute the over the subtraction:
WHY may we distribute? Because matrix multiplication distributes over addition, — multiplying a sum is the same as multiplying each piece and then combining. Here that lets us split the single perpendicularity statement into a "target part" and a "prediction part" that we can rearrange separately. Move one term across:
Term by term: is a small square matrix (its entry is the dot product of two columns); is a short -vector (entry is ). We turned a tall impossible system into a short square solvable one.
WHY. This is now equations in unknowns — square, and (when the columns are independent) uniquely solvable.
PICTURE. The tall collapses into the compact square ; the diagram shows the shrink.

Step 7 — The QR shortcut (same answer, safer arithmetic)
WHAT. Instead of forming , factor (via QR Factorization / Gram-Schmidt Process), where has orthonormal columns (, the identity) and is upper triangular (zeros below the diagonal). Substituting into the normal equations:
Why we may cancel . In the thin (reduced) QR of a full-column-rank , the matrix is square, and its diagonal entries are the nonzero lengths produced during Gram–Schmidt — so and is invertible. A product of invertible matrices is invertible, so is invertible too. Multiplying both sides on the left by legally removes it:
Term by term: reads off 's coordinates in the perfect right-angle frame ; being triangular means the last unknown pops out alone, then the next by back-substitution.
WHY bother? First, what does "safer" mean? Picture the machine stretching space: it stretches some directions a lot and others a little. A singular value of is one such stretch factor — the amount lengthens a particular unit input direction (the biggest one, , is the most can ever stretch a unit arrow; the smallest, , the least). The condition number (see Condition Number) is the ratio of biggest to smallest stretch — a single number measuring how much the matrix amplifies rounding error. Big = touchy arithmetic. The trouble with the normal equations is that forming squares every singular value (its stretch factors are the ), so : a mildly touchy becomes badly touchy. QR never builds , so it keeps the sensitivity at — while giving the identical .
PICTURE. The messy tilted columns of get straightened into the clean perpendicular axes of ; projecting onto square axes is effortless.

Step 8 — Every case, cleanly split
WHAT. To leave nothing out, cross two independent yes/no questions:
- Independent columns? (full column rank vs rank-deficient) — decides if is invertible.
- Is reachable? ( vs not) — decides whether the smallest residual is exactly or merely nonzero.
That gives four boxes, all covered:
| reachable () | unreachable () | |
|---|---|---|
| Independent columns | Unique solving exactly; least squares reproduces the exact solution. | Unique ; the healthy projection case. |
| Dependent columns | Residual is , but infinitely many give it — a whole flat family of exact solutions. | Infinitely many minimisers all sharing the same nonzero best shadow . |
WHY. These four boxes are mutually exclusive and together exhaust every possibility (columns independent or not target reachable or not), so a reader can never hit a scenario we skipped.
- The zero degenerate limit (). This sits in the "dependent columns" row: the prediction is stuck at the origin, the residual is just , and any is a minimiser. Nothing to fit.
Whenever a row says "infinitely many," the fair, canonical pick is the shortest , delivered by the Pseudoinverse (Moore-Penrose).
PICTURE. Left: fat healthy plane, unique drop (independent columns). Right: collapsed thin plane, a whole line of dial-settings landing on the same shadow (dependent columns).

The one-picture summary
Everything above is one gesture: drop perpendicularly onto the plane of reachable predictions; the foot of that drop is ; the drop-arrow is the residual.

The final schematic below distils the retelling into one flow: target → drop → foot → miss, with the two formulas hanging off it.

Recall Feynman retelling — the whole walkthrough in plain words
You are trying to hit a floating dot , but your gun can only fire onto a tilted table top (the column space) — the dot hangs above it, out of reach. So you aim for the spot on the table nearest the dot. Which spot? Drop a plumb line straight down from the dot to the table; where it lands is your best shot , and the plumb line itself is the miss (the residual). "Straight down" is the whole secret: a plumb line stands at right angles to the table, so its miss is at right angles to every direction you could have aimed. Writing "at right angles to every column" in symbols is , which tidies into . QR is the same drop done with a cleaner set of measuring sticks (perfect right-angle axes ), so your calculator doesn't fumble the arithmetic: . And if the table is secretly just a line (dependent columns), lots of aim-settings land on the same spot — you pick the gentlest one.