In $\mathbb{R}^4$, let $U=$ span$\{(1,1,0,0),(1,1,1,1)\}$. (a) Compute an orthonormal basis for $U$. 
(b) Find $u\in U$ such that the Euclidean distance $||u-(1,2,3,4)||$ is as small as possible.
Here's what I have:
(a) To find an orthonormal basis, we'll use the Gram-Schmidt Algorithm. The process is as follows:
Given $k$ basis vectors $v_1,v_2,\cdots,v_k$, we apply the following steps:


*

*Let $q_1=\frac{1}{||v_1||}v_1$.

*For $i=2$ to $k$, repeat steps 3 and 4.

*Let $w_i=v_i-\langle q_1,v_i\rangle q_i-\langle q_2,v_i\rangle q_2-\cdots-\langle q_{i-1},v_i\rangle q_{i-1}$

*Let $q_i=\frac{1}{||w_i||}w_i$


The vectors $q_1,\cdots q_k$ are our orthonormal basis. Now, we apply these steps to the given problem.
$$q_1=\frac{1}{||v_1||}v_1=\frac{1}{\sqrt{2}}v_1=(\frac{1}{\sqrt{2}},\frac{1}{\sqrt{2}},0,0)$$
$$w_2=v_2-\langle q_1,v_2\rangle q_1=(1,1,1,1)-(\frac{1}{\sqrt{2}}+\frac{1}{\sqrt{2}})(\frac{1}{\sqrt{2}},\frac{1}{\sqrt{2}},0,0)=(0,0,1,1)$$
$$q_2=\frac{1}{\sqrt{2}}w_2=(0,0,\frac{1}{\sqrt{2}},\frac{1}{\sqrt{2}})$$
So $\{q_1,q_2\}$ is an orthonormal basis for $U$.
(b) I recognize this as a least squares problem, but I'm a bit lost on how to actually set it up, because we don't have something with the form $Ax\approx b$. I mean, I know that $b=(1,2,3,4)$ and $u$ somehow represents $Ax$, but we don't have a matrix $A$, and $u$ is just an element of the span of $2$ vectors.
 A: Your proof for part (a) is correct.
For part (b) let $$ u=(\alpha , \alpha ,\beta ,\beta)$$ You need to minimize $$ (\alpha -1)^2+( \alpha -2)^2 + (\beta -3)^2+ (\beta-4)^2.$$ Partial derivatives are zero at $\alpha = 3/2$ and $\beta =7/2$. Thus $u=(3/2, 3/2, 7/2,7/2)$is the desired vector. 
A: Because you have an orthonormal basis, things become increasingly easy.
The least squares problem is solved by
$$x_{ls} = (A^TA)^{-1}(A^Tb)$$
Where $A$ is a matrix which has your basis as columns and $b$ is $<1,2,3,4>$.  Solve this for $x_{ls}$ and then the solution is $Ax_{ls}$.
A: The shortest distance to $U$ is measured along a direction orthogonal to it, therefore the element of $U$ that minimizes the distance to a given vector $b$ is the orthogonal projection of $b$ onto $U$, that is, the component of $b$ that lies in $U$.  
There are various ways to compute this projection, but since you’ve already constructed an orthonormal basis for $U$, the easiest thing to do is to compute the individual projections onto the basis vectors and combine them. In fact, this is exactly what you do at each step of the Gram-Schmidt process: you compute the orthogonal projection of the current vector onto the space spanned by the orthonormal basis vectors generated up to that point and subtract that projection from the vector to get its component that doesn’t lie in that span. So, using that projection formula from the Gram-Schmidt process, $$\begin{align} u = (u_1^Tb)u_1+(u_2^Tb)u_2 &= \frac3{\sqrt2}\left(\frac1{\sqrt2},\frac1{\sqrt2},0,0\right)+\frac7{\sqrt2}\left(0,0,\frac1{\sqrt2},\frac1{\sqrt2}\right) \\ &= \left(\frac32,\frac32,\frac72,\frac72\right). \end{align}$$  
The connection to finding a least-squares solution to the possibly-inconsistent linear system $Ax=b$ is that you essentially replace $b$ with its orthogonal projection onto the column space of $A$.
A: Muhammad gave you a nice way using partial derivative so I'll just throw out here another way without using derivatives
The shortest distance to a plane create angle of $\pi/2$, so let's create the vector $\vec v=\begin{bmatrix}1-a\\2-a\\3-b\\4-b\end{bmatrix}$, this vector is the vector from the point $(1,2,3,4)$ to an arbitrary point on the plane.
I want that this arbitrary point on the plane will minimize $\vec v$, so I'll check when the vector create angle of $\pi/2$ to the plane($\langle\cdot,\cdot\rangle$ is the dot product):$$\langle\vec v,(1,1,0,0)\rangle=0\\\langle\vec v,(0,0,1,1)\rangle=0$$here I get 2 equations: $(1-a)1+(2-a)1=0\implies a=1.5$ and $(3-b)1+(4-b)1=0\implies b=3.5$ thus the answer is $u=(1.5,1.5,3.5,3.5)$
