<s>[INST] Vector Project onto Subspace So the question is:
Let S be the subspace of $\mathbb{R}^3$ spanned by the vectors $ u_2 = \begin{pmatrix} \frac{2}{3}\\\frac{2}{3}\\\frac{1}{3}\end{pmatrix} u_3 = \begin{pmatrix} \frac{1}{\sqrt{2}}\\\frac{-1}{\sqrt{2}}\\0\end{pmatrix}$. Let $x=(1,2,2)^T$. Find the projection p of x onto S. Show that $(p-x)\perp u_2$ and $(p-x)\perp u_2$.
I understand how to show that they are perpendicular and I actually found the answer for the projection. It's:
$\begin{pmatrix} \frac{23}{18}\\\frac{41}{18}\\\frac{8}{9} \end{pmatrix}$
The problem is, i have no idea why i am doing what I am doing, I just followed my notes. Can someone explain why I was supposed to do:
$(xu_2)u_2 + (xu_3)u_3$
To find p.
 [/INST] Let $\{v_1,\dotsc,v_m\}$ be a basis for a subspace $V$ of $\Bbb R^n$. The matrix of the orthogonal projection onto $V$ is
$$
P=A\left(A^\top A\right)^{-1}A^\top
$$
where $A$ is the matrix whose columns are $\{v_1,\dotsc,v_m\}$. A nice discussion of this can be found in these notes.
In our case we have
$$
A=
\left[\begin{array}{rr}
\frac{2}{3} & \frac{1}{2} \, \sqrt{2} \\
\frac{2}{3} & -\frac{1}{2} \, \sqrt{2} \\
\frac{1}{3} & 0
\end{array}\right]
$$
Thus
$$
P = 
\left[\begin{array}{rrr}
\frac{17}{18} & -\frac{1}{18} & \frac{2}{9} \\
-\frac{1}{18} & \frac{17}{18} & \frac{2}{9} \\
\frac{2}{9} & \frac{2}{9} & \frac{1}{9}
\end{array}\right]
$$
Now, the projection of $v=(1,2,2)$ is
$$
Pv=
\left(\frac{23}{18},\,\frac{41}{18},\,\frac{8}{9}\right)
$$
</s>