Wiki
Core13 min read

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 Ax=bAx = b by rows and it is a pile of equations to satisfy at once. Read it by columns and it asks: can bb be built as a combination of the columns of AA? 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 A∈Rm×nA \in \mathbb{R}^{m\times n} and b∈Rmb \in \mathbb{R}^m, the system Ax=bAx = b is consistent exactly when bb lies in the column space of AA. The number of solutions is then:

  • none if bb is outside the column space — the inconsistent case;
  • exactly one if the columns are independent (full column rank nn);
  • infinitely many if the columns are dependent, one per null-space vector.

Equivalently, if AA is square then Ax=bAx = b has a unique solution for every bb exactly when det⁡A≠0\det A \neq 0. 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 xx satisfies Ax=bAx = b, we choose the xx that makes AxAx as close to bb as possible, in the Euclidean sense:

x^=arg⁡min⁡x∥Ax−b∥2.\hat{x} = \arg\min_{x} \lVert Ax - b \rVert^2.

The minimizer satisfies the normal equations

A⊤A x^=A⊤b,A^\top A\, \hat{x} = A^\top b,

and the fitted vector b^=Ax^\hat{b} = A\hat{x} is the orthogonal projection of bb onto the column space of AA. The residual b−b^b - \hat{b} 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 ∑ei=0\sum e_i = 0 and ∑xiei=0\sum x_i e_i = 0 hold no matter what: those are the two normal equations written out.

Why not solve A⁻¹b?

If AA is not square, A−1A^{-1} 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 A⊤AA^\top A — 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 AA 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 bb 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 x^\hat{x} 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

  1. 1Solve x + y = 3, x − y = 1. What is x?
    Numeric answer
  2. 2Fit y = m·x through the origin to the points (1, 2) and (2, 4). What is m?
    Numeric answer
  3. 3Which two equations define the least-squares solution when Ax = b is inconsistent? Give the standard name.
    Short answer
  4. 4At the least-squares solution, the residual b − A·x is orthogonal to which space?
    Multiple choice
  5. 5If an m×n system has more equations than unknowns, it can still be consistent.
    True / false

Where next: eigenvalues and eigenvectors — the special directions a matrix stretches without rotating, and the gateway to the SVD.