What is the closest point of a subspace to a given vector? In the plane, drop a perpendicular. In any dimension, the answer is the orthogonal projection, and it rests on the splitting $\mathbb{R}^n = W \oplus W^{\perp}$ from orthogonal complements and on a basis of $W$.
Onto a line. The projection of $\mathbf{y}$ onto the line through $\mathbf{u}$ is $$\hat{\mathbf{y}} = \frac{\mathbf{y}\cdot\mathbf{u}}{\mathbf{u}\cdot\mathbf{u}}\mathbf{u},$$ and $\mathbf{z} = \mathbf{y} - \hat{\mathbf{y}}$ is orthogonal to $\mathbf{u}$ (check: $\mathbf{z}\cdot\mathbf{u}$ $= \mathbf{y}\cdot\mathbf{u} - \frac{\mathbf{y}\cdot\mathbf{u}}{\mathbf{u}\cdot\mathbf{u}}\mathbf{u}\cdot\mathbf{u}$ $= 0$).
Key idea
Why it works
Worked example: Projection onto a plane
- First check the basis is orthogonal: $\mathbf{u}_1\cdot\mathbf{u}_2 = -1 + 1 + 0 = 0$. ✓
- $\dfrac{\mathbf{y}\cdot\mathbf{u}_1}{\mathbf{u}_1\cdot\mathbf{u}_1} = \dfrac{4}{2} = 2$ and $\dfrac{\mathbf{y}\cdot\mathbf{u}_2}{\mathbf{u}_2\cdot\mathbf{u}_2} = \dfrac{12}{6} = 2$.
- $\hat{\mathbf{y}}$ $= 2\begin{bmatrix} 1 \\ 1 \\ 0 \end{bmatrix} + 2\begin{bmatrix} -1 \\ 1 \\ 2 \end{bmatrix}$ $= \begin{bmatrix} 0 \\ 4 \\ 4 \end{bmatrix}$.
- $\mathbf{z} = \mathbf{y} - \hat{\mathbf{y}} = \begin{bmatrix} 1 \\ -1 \\ 1 \end{bmatrix}$. Check: $\mathbf{z}\cdot\mathbf{u}_1 = 0$ and $\mathbf{z}\cdot\mathbf{u}_2 = -1 - 1 + 2 = 0$. ✓
- Distance $= \lVert\mathbf{z}\rVert = \sqrt{3}$.
Answer: $\hat{\mathbf{y}} = (0, 4, 4)$; distance $\sqrt{3}$
Worked example: Projection onto a line
- $\mathbf{y}\cdot\mathbf{u} = 28 + 12 = 40$ and $\mathbf{u}\cdot\mathbf{u} = 20$.
- $\hat{\mathbf{y}} = 2(4, 2) = (8, 4)$, and $\mathbf{y} - \hat{\mathbf{y}} = (-1, 2)$, which is orthogonal to $(4, 2)$. ✓
Answer: $(8, 4)$
Common mistake