Hexa Scholar

Projection onto a subspace and least squares

A brass sphere suspended in the air beside a flat, unmarked navy drafting board.
The sphere represents a target in space, and the board represents a patch of a plane.

The question

Where on a plane would you put a point to get closest to a target off the plane?

  1. 1 SeeMove a point across a plane.
  2. 2 TryPredict what rescaling a column changes.
  3. 3 ProveBuild the closest-point proof.
  4. 4 ApplyFit measurements and check residuals.
Before you start · 3 quick checks on column combinations, dot products and lengths

Two ideas before you start

2 ideas

Columns give directions you can move

Adding a multiple of the second column moves the output parallel to that column.

Each coefficient sets how much of a column to use. The output is the sum of those contributions.

Exact definition

Let \(A\) be a real matrix with \(m\) rows and \(n\) columns \(a_1,\ldots,a_n\), with \(m,n\) positive integers. Its column space \(S=\operatorname{Col}(A)\) is the set of all outputs \(Ax=\sum_j x_j a_j\) as the coefficient vector \(x\) ranges over \(\mathbb R^n\).

That set contains the origin and is closed under addition and scalar multiplication, so it is a subspace of \(\mathbb R^m\). If two columns are independent and there are no others, their combinations form a plane through the origin.

A residual runs from output to target

A dashed segment joins the candidate output to a fixed target.

Move the output and the residual changes, even though the target stays put.

Exact definition

For a candidate \(q=Ax\) and a target \(b\) in the same output space, the residual is \(r=b-q\). The Euclidean squared distance from \(q\) to \(b\) is \(\|r\|^2=r\cdot r\), the sum of the squares of the entries of \(r\).

A least-squares coefficient vector minimizes \(\|b-Ax\|^2\) over all \(x\). Since squaring is increasing on nonnegative numbers, it also minimizes the Euclidean distance.

Refresher on column space, independence and orthogonality

If \(Ax\) and \(Ay\) are outputs, their difference is \(A(x-y)\), also an output. The columns are independent when \(Ax=0\) forces \(x=0\). In that case, two coefficient vectors with the same output must be equal. The column space and null space lesson develops these ideas.

The dot product of real vectors is the sum of their coordinatewise products. Two vectors are orthogonal when this sum is zero. This includes the zero vector, for which no angle is defined. See the dot product and projection onto a line for a geometric example.

A vector is orthogonal to a subspace if its dot product with every vector in the subspace is zero. Dot products distribute over sums and respect scalar multiples. That lets you test orthogonality against a spanning list of vectors.

1 See

Place the closest point

The diamond is the target \(b\). The arrows show the column directions \(a_1\) and \(a_2\). The dashed segment is the residual from your mark to \(b\).
How to read the plane drawing

The grid is a finite patch of a plane in three-dimensional output space. Every intersection represents a combination of the columns. The controls move the mark in smaller steps than the drawn grid spacing.

Screen lengths and angles depend on the viewing direction. Use the displayed dot products to test the residual against the actual columns in space. The squared distance is computed from the three coordinates of the residual.

2 Try

What changes when the columns change?

Answer the prediction to open the coefficient controls.

3 Prove

Why the perpendicular residual gives the closest point

Closest-point theorem

Let \(S\) be a linear subspace of finite-dimensional real Euclidean space, and let \(b\) be any vector in that space. A point \(p\in S\) is the unique closest point to \(b\) in \(S\) exactly when \(r=b-p\) is orthogonal to \(S\). Such a \(p\) always exists and is called the orthogonal projection of \(b\) onto \(S\).

For the proof builder, assume \(p\in S\) and \(r=b-p\) is orthogonal to \(S\). Fix any competing \(q\in S\) with \(q\ne p\), and write \(d=q-p\). The goal is to compare the squared distances. If \(S\) consists only of the origin, there is no competitor and \(p\) is the only choice.

4 Apply

Find and check fitted outputs

Enter a whole number, a decimal, or a fraction for an exact answer. Enter a decimal within the stated tolerance for the distance question. Hints are available before you open each worked solution.

Key point Build the columns in output space, solve the normal equations and check the residual against those columns. The least-squares line uses this setup with a column of ones and a column of measured inputs. Its residual lives in the space of response vectors, where each coordinate is a vertical miss for one observation.
Level Intro Prerequisites Dot products and column space Time ~30 min

Further reading