# Need help finding the projection of a vector onto a subspace.

(a) Find the projection of the vector $\vec b=(2,1,0,1)$ onto the subspace $V$ consisting of all vectors of the form $(x_1,x_2,x_3,x_4)$ such that $x_1+x_2+x_3+x_4=0$.

(b) What is the distance from the vector $\vec b$ to the subspace $V$?

Formulas needed: $\|\vec u-\vec v\|=$ distance

${\rm proj}_{\vec v}\vec u=\frac{\langle \vec u,\vec v\rangle}{\|\vec v\|^2}\vec v$.

• If you have those formulas, then it should be possible to solve the question using the equation for a (hyper)plane. Which part are you having trouble with? May 12, 2015 at 5:12

There are various ways to do this, here is my favourite.

First find a basis for $V$. And to make it as easy as possible, find a basis consisting of orthogonal vectors. In this case it's not too hard by trial and error, say $$\def\v#1{{\bf#1}} \v v_1=(1,-1,0,0)\ ,\quad \v v_2=(0,0,1,-1)\ ,\quad \v v_3=(1,1,-1,-1)\ .$$ Then $$\def\proj{{\rm proj}} \proj_V\v b=\proj_{\v v_1}\v b+\proj_{\v v_2}\v b+\proj_{\v v_3}\v b\ , \tag{*}$$ and each term can be calculated from your projection formula.

Then find the distance between $\v b$ and the projection by using your distance formula.

Note that $(*)$ is true because $\v v_1,\v v_2$ and $\v v_3$ are mutually orthogonal - it will not give the correct answer for just any old basis.

If $\{v_1,\dotsc,v_n\}$ is a basis for a subspace $S$ of $\Bbb R^n$, then the projection matrix of $S$ is $$P=A\left(A^\top A\right)^{-1} A^\top$$ where $$A=\begin{bmatrix} v_1 & v_2 & \dotsb & v_n \end{bmatrix}$$ In our case, the columns of $$A= \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \\ -1 & -1 & -1 \end{bmatrix}$$ form a basis for the subspace $S$ of $\Bbb R^4$ described by the equation $$x_1+x_2+x_3+x_4=0$$ One checks that $$P = \frac{1}{4} \begin{bmatrix} 3 & -1 & -1 & -1 \\ -1 & 3 & -1 & -1 \\ -1 & -1 & 3 & -1 \\ -1 & -1 & -1 & 3 \end{bmatrix}$$ Hence the projection of $\vec b$ onto $S$ is $$P \vec b = \frac{1}{4} \begin{bmatrix} 3 & -1 & -1 & -1 \\ -1 & 3 & -1 & -1 \\ -1 & -1 & 3 & -1 \\ -1 & -1 & -1 & 3 \end{bmatrix} \begin{bmatrix} 2\\1\\0\\1 \end{bmatrix} = \begin{bmatrix} 1\\0\\-1\\0 \end{bmatrix}$$ The distance from $\vec b$ to $S$ is then given by $\lVert\vec b-P\vec b\rVert$. Can you compute this distance?

An advantage to this strategy is that it is quite algorithmic. If you are interested in the derivation of the formula for the projection matrix $P$, check out this note.

• I'm a little confused, the way that David answered it gives me a different type of answer than yours. Which one is correct D: May 12, 2015 at 5:58
• the answer i got when i solved David's way is (3/2,1/2,-3/2,-1/2) for part a and for part b got a distance of (5)^(1/2) May 12, 2015 at 6:00
• That distance would be 2 right? May 12, 2015 at 6:09
• So did i do something wrong when i solved it David's way? May 12, 2015 at 6:12
• You are correct that the distance is $2$. Try reworking the numbers with David's solution. May 12, 2015 at 6:13

The vector $\vec w = \frac{1}{2} (1,1,1,1)$ is a unit vector orthogonal to $V$. The projection of $\vec b$ onto $\vec w$ is the vector $2 \vec w = (1,1,1,1)$. Thus, the vector $\vec b - 2\vec w = (1,0,-1,0)$ is the orthogonal projection of $\vec b$ onto $V$. Notice, that $\vec b = (2,1,0,1) = (1,1,1,1) + (1,0,-1,0)$ is the decomposition of $\vec b$ as a sum of two orthogonal vectors, one in $V$ and one orthogonal to $V$. The distance of $\vec b$ to $V$ is $\|2 \vec w\| = 2$.