Skip to content

Why orthogonal projection gives the closest point

7 min read

Short answer

The orthogonal projection of b\mathbf{b} onto a subspace is the closest point of that subspace to b\mathbf{b}, and it is characterized by one fact: the error b−p\mathbf{b}-\mathbf{p} is perpendicular to the subspace. The Pythagorean theorem turns that perpendicularity into minimality.

Diagramabp
The projection p of b onto the line through a is the foot of the perpendicular. The dashed error segment meets the line at a right angle.

Projecting onto a line

Points on the line are tat\mathbf{a}. The squared distance to b\mathbf{b} is f(t)=∥b−ta∥2=∥b∥2−2t a⋅b+t2∥a∥2f(t)=\|\mathbf{b}-t\mathbf{a}\|^2=\|\mathbf{b}\|^2-2t\,\mathbf{a}\cdot\mathbf{b}+t^2\|\mathbf{a}\|^2. Minimizing: f′(t)=−2 a⋅b+2t∥a∥2=0f'(t)=-2\,\mathbf{a}\cdot\mathbf{b}+2t\|\mathbf{a}\|^2=0, so

t=a⋅ba⋅a,p=a⋅ba⋅a a.t=\frac{\mathbf{a}\cdot\mathbf{b}}{\mathbf{a}\cdot\mathbf{a}},\qquad \mathbf{p}=\frac{\mathbf{a}\cdot\mathbf{b}}{\mathbf{a}\cdot\mathbf{a}}\,\mathbf{a}.

At this tt, the error satisfies a⋅(b−p)=0\mathbf{a}\cdot(\mathbf{b}-\mathbf{p})=0: it is perpendicular to the line. Calculus and geometry agree.

Why perpendicular means closest

Let p\mathbf{p} be a point of the subspace SS with b−p⊥S\mathbf{b}-\mathbf{p}\perp S, and let q\mathbf{q} be any other point of SS. Then p−q∈S\mathbf{p}-\mathbf{q}\in S, so it is perpendicular to the error, and the Pythagorean theorem gives

∥b−q∥2=∥b−p∥2+∥p−q∥2 ≥ ∥b−p∥2.\|\mathbf{b}-\mathbf{q}\|^2=\|\mathbf{b}-\mathbf{p}\|^2+\|\mathbf{p}-\mathbf{q}\|^2\ \ge\ \|\mathbf{b}-\mathbf{p}\|^2.

Every other point is strictly farther unless q=p\mathbf{q}=\mathbf{p}. This works in any number of dimensions and for any subspace, which is why projection is the foundation of least squares.

Projecting onto a subspace

For a subspace spanned by the columns of AA, requiring the error to be perpendicular to every column gives AT(b−Ax^)=0A^T(\mathbf{b}-A\hat{\mathbf{x}})=\mathbf{0}, the normal equations ATAx^=ATbA^TA\hat{\mathbf{x}}=A^T\mathbf{b}. The projection is p=Ax^=Pb\mathbf{p}=A\hat{\mathbf{x}}=P\mathbf{b} with

P=A(ATA)−1AT(columns independent).P=A(A^TA)^{-1}A^T\quad(\text{columns independent}).

Two identities describe any projection matrix: P2=PP^2=P (projecting twice changes nothing) and PT=PP^T=P (it is symmetric, which is what makes it orthogonal rather than slanted).

Worked example

Project b=(2,3)\mathbf{b}=(2,3) onto the line through a=(4,1)\mathbf{a}=(4,1), and find the distance from b\mathbf{b} to the line.

a⋅b=11\mathbf{a}\cdot\mathbf{b}=11, a⋅a=17\mathbf{a}\cdot\mathbf{a}=17, so t=1117t=\tfrac{11}{17} and p=1117(4,1)=(4417,1117)\mathbf{p}=\tfrac{11}{17}(4,1)=\left(\tfrac{44}{17},\tfrac{11}{17}\right).

Error: e=b−p=(−1017,4017)\mathbf{e}=\mathbf{b}-\mathbf{p}=\left(-\tfrac{10}{17},\tfrac{40}{17}\right). Check: e⋅a=−4017+4017=0\mathbf{e}\cdot\mathbf{a}=-\tfrac{40}{17}+\tfrac{40}{17}=0 ✓.

Distance: ∥e∥2=100+1600289=10017\|\mathbf{e}\|^2=\tfrac{100+1600}{289}=\tfrac{100}{17}, so the distance is 1017≈2.43\tfrac{10}{\sqrt{17}}\approx2.43. Pythagoras check: ∥b∥2=13=12117+10017\|\mathbf{b}\|^2=13=\tfrac{121}{17}+\tfrac{100}{17}. ✓

Try it yourself

Project b=(1,2)\mathbf{b}=(1,2) onto the line through a=(1,1)\mathbf{a}=(1,1) and verify the error is perpendicular.

Show the answer

t=1+21+1=32t=\tfrac{1+2}{1+1}=\tfrac32, so p=(32,32)\mathbf{p}=(\tfrac32,\tfrac32) and the error is (−12,12)(-\tfrac12,\tfrac12). Its dot product with (1,1)(1,1) is 00, so it is perpendicular.

Keep going with practice

Vidi's projection and least-squares lessons both rest on this perpendicular-error idea.