Beautiful Math
Path

Linear algebra · Lesson 5

Row reduction and least squares

Gaussian elimination is organized matrix moves that simplify linear systems. Overdetermined least squares is a projection story: the best fit is the shadow in the column space.

Core ~24 minDeep study ~73 minWhat does a row operation preserve?Why is the least-squares residual orthogonal to the column space?

Before this: Matrices as linear maps, Dot products and projections

How this idea was born

Two equations in two unknowns can be a clean crossing of lines. Real measurement piles on more equations than unknowns: redundant surveys, noisy sensors, overdetermined recipes. Exact solution may be impossible. You still need a principled compromise.
Carl Friedrich Gauss (1777-1855) used systematic elimination while wrestling with astronomical and geodetic data, including least-squares calculations. MacTutor and the matrices-and-determinants topic page are the short historical stops. Naming caution: elimination methods are older (Newton and others appear in the lineage); Gauss's notation helped standardize hand computation, and later practice attached his name. Steal the ethic of careful bookkeeping when many equations fight at once, not a monopoly myth.
For a modern rereader, this chapter has two faces that belong together. Row reduction is organized matrix moves that simplify Ax=bA\mathbf{x}=\mathbf{b}. Least squares is what you do when no x\mathbf{x} hits b\mathbf{b} exactly: project b\mathbf{b} onto the column space of AA, tying straight back to dot products.

First principles

best compromise
Three noisy lines rarely meet at one point. Least squares picks the compromise that minimizes total squared miss.
A linear system Ax=bA\mathbf{x}=\mathbf{b} asks whether b\mathbf{b} lies in the column space of AA (the span of AA's columns). Row operations (swap rows, scale a row, add a multiple of one row to another) produce an equivalent system: same solution set, cleaner shape. Gaussian elimination drives the matrix toward row echelon form; back substitution reads the unknowns. Inconsistent systems reveal a contradictory row such as 0=c0=c with c0c\neq 0.
When Ax=bA\mathbf{x}=\mathbf{b} has no exact solution (typical when there are more independent equations than unknowns), least squares seeks
x^=argminxAxb2.\hat{\mathbf{x}} = \arg\min_{\mathbf{x}} \|A\mathbf{x}-\mathbf{b}\|^2.
Geometrically, Ax^A\hat{\mathbf{x}} is the projection of b\mathbf{b} onto the column space of AA. The residual r=bAx^\mathbf{r}=\mathbf{b}-A\hat{\mathbf{x}} is orthogonal to every column of AA:
ATr=0ATAx^=ATb.A^{\mathsf{T}}\mathbf{r} = \mathbf{0} \quad \Rightarrow \quad A^{\mathsf{T}}A\hat{\mathbf{x}} = A^{\mathsf{T}}\mathbf{b}.
Those are the normal equations. The orthogonality claim is the same projection story you met with dot products, now in the column space.

Worked intuition

Elimination is dishwashing for equations: stack them, cancel variables methodically, do not smuggle arithmetic errors. Each row operation is a legal rewrite that preserves the solution set (for exact arithmetic).
Least squares is shadow-casting. b\mathbf{b} is a point hanging off the subspace of reachable AxA\mathbf{x} vectors. Drop a perpendicular. The foot of the perpendicular is the closest reachable prediction. Squared length of the leftover is the residual sum of squares.
Fitting a line ymx+cy \approx mx+c through many noisy points is this story in coordinates: stack rows (xi,1)(x_i, 1), form AA, and solve for (m,c)(m,c) in the least-squares sense.
Algebrica's Gaussian elimination and systems pages drill the moves; the inner-product page refreshes why orthogonality of the residual is the defining geometry.

Common confusions

Row reduction changes the answer. Done correctly, it changes the costume, not the solution set. Pivoting strategies matter for numerical stability; the exact-arithmetic ideal is equivalence.
Least squares always finds "the truth." It finds the closest point in a chosen model class under Euclidean residual length. Wrong features, wrong subspace, wrong answer - optimally wrong.
Normal equations are always the best computational path. Forming ATAA^{\mathsf{T}}A can worsen conditioning. QR and SVD methods often compute the same geometric projection more stably. The geometry stays; the algorithm can upgrade.
Orthogonal residual means "uncorrelated with reality." It means orthogonal to the column space you chose. Features you did not include can still correlate with the residual.
Overdetermined means inconsistent always. Sometimes the extra equations agree. Overdetermined describes shape (more equations than unknowns), not automatic contradiction.
Elimination solves least squares directly without a criterion. Elimination solves exact linear systems. Least squares adds a projection criterion when exactness fails.

History & stories

Gauss used elimination and least squares in concrete scientific computation. MacTutor's Gauss biography and the matrices historical topic page keep the story grounded. Legendre published on least squares around the same era; priority disputes exist and need not detain the geometry.
The durable gift is twofold: systematic simplification of linear systems, and a projection ethic when data overconstrain a linear model.

Real world

Surveyors collect more measurements than strict degrees of freedom; residuals get distributed rather than ignored. Laboratory calibrations fit lines through noisy instrument readings. Spreadsheet "Add trendline" is ordinary least squares wearing a chart menu.
Anytime you accept that equations disagree and still want one parameter vector, you are in this chapter.

Open when you want the machine-learning connection. Skip freely.

Field notes, extra examples, and glossary live here when you want more than the core path.

Carry this forward

  • Matrix moves simplify systems; projection settles overdetermined fights.
  • Residuals orthogonal to Col(A)\mathrm{Col}(A) are the geometric signature of least squares.
  • Next: eigenvalues reveal stretch factors along special directions.

Read more

Go deeper when curiosity hits - videos, essays, and primary trails.

Check your understanding

A short learning loop - try a few, learn from misses, mark complete when you have engaged. No timer, no scoreboard.

1.Gaussian elimination uses row operations to…
2.Least squares picks x̂ to…
3.The least-squares residual is orthogonal to…
4.Normal equations are…
5.Gauss naming caution…

Try at least 3 core prompts, or choose I'll return later.