Linear systems: solving, and what to do when you cannot
Intersecting equations, the column picture, and least squares as the principled answer to an inconsistent system.
Three measurements of a physical law rarely lie on a perfect line. A handful of equations in two unknowns almost never share one common point. And yet we want a slope and an intercept anyway. Linear systems are the language for this, and the interesting case is not the tidy one where everything is solvable — it is the overdetermined one where nothing is.
Two pictures of the same system
Read by rows and it is a pile of equations to satisfy at once. Read it by columns and it asks: can be built as a combination of the columns of ? Both pictures give the same answer, but the column reading is the one that tells you what to do when the answer is no.
Below, five measurements of a line are shown with their least-squares fit. Move the values and watch the residuals — the fit always settles so that its error is orthogonal to the data columns.
Five equations, two unknowns — almost never exactly solvable
- fit slope m
- 1.890
- intercept b
- 0.210
- Σ residual
- 0.0000
- Σ x·residual
- -0.0000
The last two numbers are the whole idea. Least squares chooses the line whose residual vector is orthogonal to the columns — Σ residual = 0 and Σ x·residual = 0, no matter how you drag the points. That is the normal equations, and it is the same “project onto a subspace” move that returns later as mean-square estimation. When the points are collinear the residual is exactly zero and the system is consistent again.
Existence and uniqueness
For and , the system is consistent exactly when lies in the column space of . The number of solutions is then:
- none if is outside the column space — the inconsistent case;
- exactly one if the columns are independent (full column rank );
- infinitely many if the columns are dependent, one per null-space vector.
Equivalently, if is square then has a unique solution for every exactly when . Row-reduction (Gaussian elimination) is the mechanical way to decide which case you are in; the column-space question is the geometric way to understand it.
The inconsistent case: least squares
When no satisfies , we choose the that makes as close to as possible, in the Euclidean sense:
The minimizer satisfies the normal equations
and the fitted vector is the orthogonal projection of onto the column space of . The residual is perpendicular to every column — that orthogonality is not a coincidence, it is the definition of "closest point". If you drag the points in the widget above, the readouts and hold no matter what: those are the two normal equations written out.
Why not solve A⁻¹b?
If is not square, does not exist. Even when it does, forming the inverse is slower and less numerically stable than factorizing (QR or SVD). In practice least squares is solved with a QR factorization or the SVD, never by inverting — squaring the matrix doubles its condition number. The normal equations are the right mental model, not the right implementation.
Geometry of the four subspaces
Every matrix carries four subspaces, and they pair up:
- the column space and its orthogonal complement, the left null space;
- the row space and its orthogonal complement, the null space.
The row space and the column space both have dimension equal to the rank. A solution exists iff has no component in the left null space, and the solution is unique iff the null space is trivial. This is the whole existence-and-uniqueness story in one picture.
Illustrative vs real
The widget fits five points with two unknowns, which is small enough to solve by hand. Production regression can have millions of rows and thousands of features; the mathematics is identical, only the factorization used to compute changes. The residual's orthogonality to the column space is the invariant that survives the scaling.
Check yourself
Eduspheria wiki · Mathematics for AI, Linear algebra
0 / 5 answered
Where next: eigenvalues and eigenvectors — the special directions a matrix stretches without rotating, and the gateway to the SVD.