Tutorials › Linear Algebra › Distances And Projection Errors

Orthogonal Complements and Projections · Tutorial 678 of 1000

Distances And Projection Errors

Use the orthogonal residual to calculate distance to a subspace and measure exactly how much worse any alternative approximation is.

Intermediate 10 min read

What You'll Learn

  • Define distance from a vector to a subspace using the Euclidean norm.
  • Identify the orthogonal residual of a projection.
  • Prove the Pythagorean identity for orthogonal vectors.
  • Calculate distances to lines and planes using projection residuals.
  • Compare the error of a projection with the error of another vector in the subspace.
  • Distinguish an error vector, its norm, and its squared norm.

Distance as an Orthogonal Residual

When a vector does not lie in a subspace, its distance to that subspace measures how closely the subspace can approximate it. The distance is not the length of a particular coordinate difference chosen arbitrarily: it is the smallest possible error norm among all vectors in the subspace. The orthogonal projection identifies the vector that achieves this smallest error, and the residual from that projection gives the distance directly.

Throughout, work in \(\mathbb{R}^n\) with the Euclidean dot product \(\mathbf{u}\cdot\mathbf{v}=\mathbf{u}^{\top}\mathbf{v}\) and norm \(\|\mathbf{u}\|=\sqrt{\mathbf{u}\cdot\mathbf{u}}\). Let \(W\) be a subspace of \(\mathbb{R}^n\). For \(\mathbf{x}\in\mathbb{R}^n\), the distance from \(\mathbf{x}\) to \(W\) is the infimum of the errors \(\|\mathbf{x}-\mathbf{w}\|\) over all \(\mathbf{w}\in W\). Since \(W\) is finite-dimensional, the Best Approximation Theorem gives a unique vector \(\mathbf{p}\in W\) that minimizes this error. It is the orthogonal projection of \(\mathbf{x}\) onto \(W\), written \(\operatorname{proj}_W\mathbf{x}\); its residual is \(\mathbf{x}-\mathbf{p}\), which is orthogonal to every vector in \(W\).

Definition: For a subspace \(W\subseteq\mathbb{R}^n\) and \(\mathbf{x}\in\mathbb{R}^n\), define \(d(\mathbf{x},W)=\inf_{\mathbf{w}\in W}\|\mathbf{x}-\mathbf{w}\|\). The projection residual is \(\mathbf{r}=\mathbf{x}-\operatorname{proj}_W\mathbf{x}\). The residual is an error vector; the distance is the nonnegative number \(\|\mathbf{r}\|\).

The distinction between vector and number matters. A residual contains direction as well as size, while distance records only its length. Also, the Euclidean norm is built from squares: the squared distance is \(\|\mathbf{r}\|^2\), not a sum of the signed coordinates of \(\mathbf{r}\).

The Pythagorean Identity for Projection Errors

The key calculation compares the projection error with the error from any other choice in \(W\). It relies on the Pythagorean identity: when two vectors are orthogonal, the square of the norm of their sum is the sum of their squared norms.

Lemma (Pythagorean identity): If \(\mathbf{u},\mathbf{v}\in\mathbb{R}^n\) and \(\mathbf{u}\cdot\mathbf{v}=0\), then \(\|\mathbf{u}+\mathbf{v}\|^2=\|\mathbf{u}\|^2+\|\mathbf{v}\|^2\).

Proof. By the definition of the Euclidean norm and the distributive law for the dot product, \(\|\mathbf{u}+\mathbf{v}\|^2=(\mathbf{u}+\mathbf{v})\cdot(\mathbf{u}+\mathbf{v})=\mathbf{u}\cdot\mathbf{u}+\mathbf{u}\cdot\mathbf{v}+\mathbf{v}\cdot\mathbf{u}+\mathbf{v}\cdot\mathbf{v}\). The dot product is symmetric over \(\mathbb{R}\), and the cross terms are zero because \(\mathbf{u}\cdot\mathbf{v}=0\). The remaining terms are \(\|\mathbf{u}\|^2+\|\mathbf{v}\|^2\). \(\square\)

Theorem (Projection error identity): Let \(W\) be a subspace of \(\mathbb{R}^n\), let \(\mathbf{x}\in\mathbb{R}^n\), and let \(\mathbf{p}=\operatorname{proj}_W\mathbf{x}\). For every \(\mathbf{w}\in W\), \(\|\mathbf{x}-\mathbf{w}\|^2=\|\mathbf{x}-\mathbf{p}\|^2+\|\mathbf{p}-\mathbf{w}\|^2\). Consequently, \(d(\mathbf{x},W)=\|\mathbf{x}-\mathbf{p}\|\), and the projection \(\mathbf{p}\) is the unique vector in \(W\) attaining that distance.

Proof. Fix any \(\mathbf{w}\in W\). Since \(\mathbf{p}\) and \(\mathbf{w}\) both belong to the subspace, their difference \(\mathbf{p}-\mathbf{w}\) belongs to \(W\). The projection residual \(\mathbf{x}-\mathbf{p}\) is orthogonal to every vector in \(W\), so \((\mathbf{x}-\mathbf{p})\cdot(\mathbf{p}-\mathbf{w})=0\). Now split the error from \(\mathbf{w}\) as \(\mathbf{x}-\mathbf{w}=(\mathbf{x}-\mathbf{p})+(\mathbf{p}-\mathbf{w})\). The two summands are orthogonal, so the Pythagorean identity gives \(\|\mathbf{x}-\mathbf{w}\|^2=\|\mathbf{x}-\mathbf{p}\|^2+\|\mathbf{p}-\mathbf{w}\|^2\). The second term on the right is nonnegative, so every \(\mathbf{w}\in W\) has error at least \(\|\mathbf{x}-\mathbf{p}\|\). Taking \(\mathbf{w}=\mathbf{p}\) makes that second term zero, so the lower bound is attained and equals the infimum defining distance. If another \(\mathbf{w}\) attains the same distance, the identity forces \(\|\mathbf{p}-\mathbf{w}\|^2=0\), hence \(\mathbf{p}=\mathbf{w}\). This proves both the distance formula and uniqueness. \(\square\)

The identity gives more information than the statement that projection is best. The increase in squared error from choosing \(\mathbf{w}\) instead of \(\mathbf{p}\) is exactly \(\|\mathbf{p}-\mathbf{w}\|^2\). Thus, moving the chosen approximation farther from the projection adds a precise, nonnegative amount to its squared error.

Corollary: For any \(\mathbf{w}\in W\), \(\|\mathbf{x}-\mathbf{w}\|\ge d(\mathbf{x},W)\), with equality if and only if \(\mathbf{w}=\operatorname{proj}_W\mathbf{x}\).

Proof. The projection error identity says that \(\|\mathbf{x}-\mathbf{w}\|^2=d(\mathbf{x},W)^2+\|\mathbf{p}-\mathbf{w}\|^2\). Since the last term is nonnegative, \(\|\mathbf{x}-\mathbf{w}\|^2\ge d(\mathbf{x},W)^2\). Both norms are nonnegative, so taking square roots preserves the inequality. Equality holds exactly when \(\|\mathbf{p}-\mathbf{w}\|^2=0\), which is equivalent to \(\mathbf{w}=\mathbf{p}\). \(\square\)

Calculating and Comparing Distances

Worked Example: A Subspace Spanned by Orthogonal Vectors

Let \(W=\operatorname{span}\{(1,1,0),(0,0,1)\}\) and \(\mathbf{x}=(2,0,3)\). Find the distance from \(\mathbf{x}\) to \(W\), then compare the projection error with the error from choosing \(\mathbf{w}=\mathbf{0}\).

The spanning vectors are orthogonal. The projection of \(\mathbf{x}\) onto the first is \(\frac{(2,0,3)\cdot(1,1,0)}{(1,1,0)\cdot(1,1,0)}(1,1,0)=\frac{2}{2}(1,1,0)=(1,1,0)\). Its projection onto the second is \(\frac{(2,0,3)\cdot(0,0,1)}{(0,0,1)\cdot(0,0,1)}(0,0,1)=\frac{3}{1}(0,0,1)=(0,0,3)\). Adding these components gives \(\mathbf{p}=(1,1,3)\in W\). The residual is \(\mathbf{r}=\mathbf{x}-\mathbf{p}=(2,0,3)-(1,1,3)=(1,-1,0)\). It is orthogonal to both spanning vectors, since \((1,-1,0)\cdot(1,1,0)=1-1=0\) and \((1,-1,0)\cdot(0,0,1)=0\).

Therefore, \(\|\mathbf{r}\|^2=1^2+(-1)^2+0^2=2\), so \(d(\mathbf{x},W)=\sqrt{2}\). For \(\mathbf{w}=\mathbf{0}\), the error vector is \(\mathbf{x}-\mathbf{w}=(2,0,3)\), whose squared norm is \(2^2+0^2+3^2=13\). The identity predicts \(\|\mathbf{x}-\mathbf{w}\|^2=\|\mathbf{r}\|^2+\|\mathbf{p}-\mathbf{w}\|^2=2+(1^2+1^2+3^2)=2+11=13\).

Check: The directly computed squared error is \(13\), and the two orthogonal contributions add to \(13\). Thus the distance is \(\sqrt{2}\), while the zero-vector choice has error \(\sqrt{13}\).

Worked Example: Distance to a Line in R³

Let \(W=\operatorname{span}\{(1,2,2)\}\) and \(\mathbf{x}=(1,0,0)\). Find the distance to \(W\) and compare with the error from choosing the zero vector.

Write \(\mathbf{a}=(1,2,2)\). The projection is \(\mathbf{p}=\frac{\mathbf{x}\cdot\mathbf{a}}{\mathbf{a}\cdot\mathbf{a}}\mathbf{a}\). Here \(\mathbf{x}\cdot\mathbf{a}=1\) and \(\mathbf{a}\cdot\mathbf{a}=1+4+4=9\), so \(\mathbf{p}=\frac19(1,2,2)=(\frac19,\frac29,\frac29)\). Then \(\mathbf{r}=\mathbf{x}-\mathbf{p}=(\frac89,-\frac29,-\frac29)\). As a check of residual orthogonality, \(\mathbf{r}\cdot\mathbf{a}=\frac89-\frac49-\frac49=0\).

The squared residual norm is \(\|\mathbf{r}\|^2=(\frac89)^2+(-\frac29)^2+(-\frac29)^2=\frac{64}{81}+\frac4{81}+\frac4{81}=\frac{72}{81}=\frac89\). Hence \(d(\mathbf{x},W)=\sqrt{\frac89}=\frac{2\sqrt{2}}{3}\). For the choice \(\mathbf{w}=\mathbf{0}\), the squared error is \(\|\mathbf{x}\|^2=1\). The projection's squared norm is \(\|\mathbf{p}\|^2=\frac{1+4+4}{81}=\frac19\), so the identity gives \(\|\mathbf{x}-\mathbf{0}\|^2=\frac89+\frac19=1\).

Check: The direct squared error from \(\mathbf{0}\) is \(1\), equal to the sum of the squared distance \(\frac89\) and the squared displacement \(\frac19\) from \(\mathbf{p}\) to \(\mathbf{0}\).

Worked Example: Comparing Two Approximations in a Plane

Let \(W=\{(a,b,0):a,b\in\mathbb{R}\}\), the coordinate plane with third coordinate zero, and let \(\mathbf{x}=(3,4,5)\). Find the distance to \(W\), then compare the projection with the alternative \(\mathbf{w}=(1,2,0)\).

The point \(\mathbf{p}=(3,4,0)\) lies in \(W\), and its residual is \(\mathbf{r}=\mathbf{x}-\mathbf{p}=(0,0,5)\). Every vector in \(W\) has third coordinate zero, so \(\mathbf{r}\) is orthogonal to every vector in \(W\). Thus \(\mathbf{p}\) is the orthogonal projection and \(d(\mathbf{x},W)=\|\mathbf{r}\|=\sqrt{0^2+0^2+5^2}=5\).

For the alternative \(\mathbf{w}=(1,2,0)\), the displacement within the plane is \(\mathbf{p}-\mathbf{w}=(2,2,0)\), with squared norm \(2^2+2^2+0^2=8\). The direct error is \(\mathbf{x}-\mathbf{w}=(2,2,5)\), with squared norm \(2^2+2^2+5^2=33\). The identity verifies the comparison: \(\|\mathbf{x}-\mathbf{w}\|^2=25+8=33\).

Check: The alternative error is \(\sqrt{33}\), which is greater than the projection error \(5\), since \(33>25\). The difference in their squared errors is \(8=\|\mathbf{p}-\mathbf{w}\|^2\).

Common Pitfall: Adding Norms Instead of Squared Norms

The Pythagorean identity is an identity of squared norms. It does not say that the length of a sum of orthogonal vectors is the sum of their lengths. In the first example, take \(\mathbf{w}=\mathbf{0}\). The projection residual has norm \(\sqrt{2}\), and the displacement \(\mathbf{p}-\mathbf{0}\) has norm \(\sqrt{11}\). A common incorrect calculation is \(\|\mathbf{x}\|=\sqrt{2}+\sqrt{11}\). That would give the wrong error: the direct calculation gives \(\|\mathbf{x}\|=\sqrt{13}\), not \(\sqrt{2}+\sqrt{11}\). The correct calculation is \(\|\mathbf{x}\|^2=2+11=13\), and only then do we take the square root.

Another way to avoid confusion is to keep the vector equation and the scalar equation distinct. First split the error vector as \(\mathbf{x}-\mathbf{w}=(\mathbf{x}-\mathbf{p})+(\mathbf{p}-\mathbf{w})\). Then use orthogonality to add the squared norms. The two terms are perpendicular vectors, not two nonnegative numbers to add as lengths.

Using the Identity to Assess an Approximation

The projection error identity is useful whenever a subspace is used to approximate data or a vector. It tells us both the minimum achievable error and the exact penalty for a particular alternative. If an alternative \(\mathbf{w}\in W\) is close to the projection \(\mathbf{p}\), its squared error exceeds the minimum by only \(\|\mathbf{p}-\mathbf{w}\|^2\). If \(\mathbf{w}\) is far from \(\mathbf{p}\), that squared displacement is added in full. The identity applies whether \(W\) is a line, a plane, or any other subspace of \(\mathbb{R}^n\).

For practical calculations, the essential checks are that the proposed projection belongs to \(W\) and that its residual is orthogonal to \(W\). Once those conditions hold, the distance is the residual norm. To compare any other candidate, compute its displacement from the projection and add the square of that displacement to the squared distance. This avoids comparing complicated error vectors by inspection and makes equality conditions explicit.

Check Your Understanding

For each question, keep track of whether you are calculating a vector, a norm, or a squared norm.

  1. If \(d(\mathbf{x},W)=3\) and \(\|\operatorname{proj}_W\mathbf{x}-\mathbf{w}\|=4\) for some \(\mathbf{w}\in W\), what are \(\|\mathbf{x}-\mathbf{w}\|^2\) and \(\|\mathbf{x}-\mathbf{w}\|\)?
  2. For \(W=\operatorname{span}\{(1,0)\}\subseteq\mathbb{R}^2\) and \(\mathbf{x}=(2,3)\), find the projection residual and the distance.
  3. Why must \(\mathbf{p}-\mathbf{w}\) lie in \(W\) when both \(\mathbf{p}\) and \(\mathbf{w}\) belong to \(W\)?
  4. In the line example, verify directly that the squared error from \(\mathbf{w}=\mathbf{0}\) is \(1\), and identify the two squared terms that sum to it.
  5. State the equality condition in the projection error identity and explain what it means geometrically.

Test yourself: Linear Algebra final exam practice

Ready to check what you know? Work a full-length practice final, then open the complete worked solutions.

Want all 1,114 practice problems?

This tutorial covers one topic. Calc Pass covers the full Calculus AB & BC curriculum (the core of Calculus I and II): full review, every practice question, and step-by-step solutions to each one.

QR code to download the Calc Pass app

Get the Calc Pass App

Scan to download and practice on the go, with instant scoring.

Calc Pass Volume 1: 1,114 Practice Questions book cover

Vol. 1: 1,114 Questions

The complete practice question bank, organized by AB & BC topic.

View on Amazon
Calc Pass Volume 2: Solutions Manual book cover

Vol. 2: Solutions Manual

Fully worked solutions to every question in Volume 1.

View on Amazon