Euler Hall — free maths guides

Check that the error b - p is orthogonal to the column space

Compute the error e = b - p of a proposed projection and dot it with every column of A. The idea in plain words, a worked example, and a check with the answers shown — part of the free Linear Algebra guides.

The property, stated once

For a subspaceSS and a vectorbb, the projectionpp is the point ofSS closest tobb. Equivalently — and this is the definition to compute with —pp is the point ofSS for which e=b−pis orthogonal to every vector of S.e=b-p \quad\text{is orthogonal to every vector of } S.

WhenSS is the column space ofAA, "orthogonal to every vector ofSS" reduces to a finite list:ee must be perpendicular to each column ofAA. That is the same statement as ATe=0,A^Te=\mathbf{0}, which is the normal equationAT(b−Ax^)=0A^T(b-A\hat x)=\mathbf{0} rearranged.

Three facts that follow, all used constantly.

  1. 1.ee is perpendicular to every column ofAA.
  2. 2.ee is perpendicular to every vector in the column space, because each is a combination of the columns.
  3. 3.ee is perpendicular topp, becausepp is itself in the column space.

One thing that does not follow.ee is not perpendicular tobb. See the trap.

Why the error is the right thing to test

Projection is a minimisation: among all points ofSS,pp is the closest tobb. The condition that characterises a minimum is exactly orthogonality of the error, and it is worth seeing why once because the same argument returns for least squares.

The argument. Letpp be the closest point and letss be any other point ofSS. Writeb−p=eb-p=e. For any realtt, ∥b−(p+ts)∥2=∥e−ts∥2=∥e∥2−2t eTs+t2∥s∥2.\|b-(p+ts)\|^2=\|e-ts\|^2=\|e\|^2-2t\,e^Ts+t^2\|s\|^2. This is a quadratic intt with a minimum att=eTs/∥s∥2t=e^Ts/\|s\|^2. Forpp to be the closest point,t=0t=0 must be the minimum, which requireseTs=0e^Ts=0. Sincess was arbitrary inSS, the error is perpendicular to all ofSS.

Why this matters practically. The condition is a test, not just a definition: given any candidatepp, you can check it in one dot product per column and know whether it is right. Nothing else about a projection is this cheap to verify.

And why the formula is what it is. SolvingAT(b−Ax^)=0A^T(b-A\hat x)=\mathbf{0} givesATAx^=ATbA^TA\hat x=A^Tb, hencex^=(ATA)−1ATb\hat x=(A^TA)^{-1}A^Tb andp=A(ATA)−1ATbp=A(A^TA)^{-1}A^Tb. The projection matrix is a consequence of the orthogonality condition, not a separate fact to memorise.

Worked example: two columns, one good coefficient and one bad

Let A=[101101],b=[133].A=\begin{bmatrix}1&0\\1&1\\0&1\end{bmatrix},\qquad b=\begin{bmatrix}1\\3\\3\end{bmatrix}.

The true least-squares solution. WithATA=[2112]A^TA=\begin{bmatrix}2&1\\1&2\end{bmatrix} andATb=[46]A^Tb=\begin{bmatrix}4\\6\end{bmatrix}, x^=[2/38/3],p=Ax^=[2/310/38/3],e=b−p=[1/3−1/31/3].\hat x=\begin{bmatrix}2/3\\8/3\end{bmatrix},\qquad p=A\hat x=\begin{bmatrix}2/3\\10/3\\8/3\end{bmatrix},\qquad e=b-p=\begin{bmatrix}1/3\\-1/3\\1/3\end{bmatrix}. Check both columns:a1Te=13−13+0=0a_1^Te=\frac13-\frac13+0=0 ✓ anda2Te=0−13+13=0a_2^Te=0-\frac13+\frac13=0 ✓.

A wrong coefficient and what it looks like. Tryx^=(1,0)\hat x=(1,0): thenp=(1,1,0)p=(1,1,0) ande=(0,2,3)e=(0,2,3). Both dots fail —a1Te=2a_1^Te=2 anda2Te=5a_2^Te=5. So a single wrong coefficient can break every dot at once.

A wrong coefficient that breaks only one. Tryx^=(2/3, 8/3)+(0,1)\hat x=(2/3,\,8/3)+(0,1): that is(2/3, 11/3)(2/3,\,11/3), givingp=(2/3, 13/3, 11/3)p=(2/3,\,13/3,\,11/3) ande=(1/3,−4/3,−2/3)e=(1/3,-4/3,-2/3). Thena1Te=13−43=−1a_1^Te=\frac13-\frac43=-1 anda2Te=−43−23=−2a_2^Te=-\frac43-\frac23=-2. Again both. The direction that breaks exactly one dot is a displacement along a vector perpendicular to the other column, which is why the practice items draw matrices whose columns are not perpendicular — with orthogonal columns the two failure patterns collapse into one.

By the end you can
  • Compute the error e = b - p of a proposed projection and dot it with every column of A
  • Name which column a proposed projection fails against, and read that as 'the coefficient was wrong'
  • Explain why e is perpendicular to the whole column space and to p, but not to b
Test yourself

(a) A projection ofb=(1,1,1)b=(1,1,1) onto a plane givesp=(1,1,0)p=(1,1,0). What is the error and what isaTea^Te for a columna=(0,0,1)a=(0,0,1) spanning the normal? (b) Ifee is the error of a projection, what ise⋅pe\cdot p? (c) Cane⋅be\cdot b ever be zero for a non-exact fit?

Answers

(a)e=b−p=(0,0,1)e=b-p=(0,0,1) andaTe=1≠0a^Te=1\ne0, so thispp is not the projection onto that plane — the error is along the normal, which is exactly the failure the check catches.

(b) Zero.pp lies in the column space andee is perpendicular to the whole of it.

(c) No.e⋅b=∥e∥2e\cdot b=\|e\|^2, which is strictly positive unlesse=0e=\mathbf{0}, i.e. unless the fit is exact.

Work out where to start — free, no accountAnswer six real questions — free, no account