Vector projection (source code)

= Vector projection
{title2=$\operatorname{proj}_{\mathbf c}\mathbf a=(\mathbf a\cdot\mathbf c)\mathbf c/\|\mathbf c\|^2$}
{wiki}

The <vector projection> multiplies the <scalar projection> by the chosen <unit vector>, giving the <orthogonal projection> onto the <linear span> of a nonzero real <Euclidean vector> $\mathbf c$:
$$
\mathbf p=\operatorname{proj}_{\mathbf c}\mathbf a
=\frac{\mathbf a\cdot\mathbf c}{\mathbf c\cdot\mathbf c}\mathbf c,\qquad
\mathbf r=\mathbf a-\mathbf p,\qquad \mathbf r\cdot\mathbf c=0.
$$
For $\mathbf a=(3,4)$ and $\mathbf c=(2,0)$, this gives $\mathbf p=(6/4)(2,0)=(3,0)$ and $\mathbf r=(0,4)$; the <dot product> $\mathbf r\cdot\mathbf c=0$ checks the <orthogonal projection residual>. Replacing $\mathbf c$ by $(-2,0)$ gives the same $\mathbf p=(-6/4)(-2,0)=(3,0)$: reversing direction changes the <scalar projection>, but preserves the <vector projection> onto the line.

For a short proof of the nearest-point property, any <vector> $\mathbf z$ on this line satisfies $\|\mathbf a-\mathbf z\|^2=\|\mathbf r\|^2+\|\mathbf p-\mathbf z\|^2$ by the <Pythagorean identity>. The second term is uniquely minimized at $\mathbf z=\mathbf p$. This connects a directional measurement to the <orthogonal projection> used in approximation.https://ocw.mit.edu/courses/18-06-linear-algebra-spring-2010/resources/lecture-15-projections-onto-subspaces/[Strang, MIT 18.06, Lecture 15: projections onto subspaces]{ref}