<s>[INST] QR transformation with Householder transformation It's a task i do to understand minimizing the error including the QR transformation with the help of Householder transformation. I think i really do something wrong but i dont get it running i hope you can help me.
Given the task to minimizing the error of
$$ A = \begin{pmatrix}
1 &1\\
1 & 0\\
1 & 1 \\
1 & 4
\end{pmatrix}
 b=\left[2,\frac{1}{2},\frac{3}{2},5\right]^T
$$
So at first getting $A^TA = \begin{pmatrix} 4 & 6 \\ 6 &18 \end{pmatrix}$  
after this calculate the householder vector $v_1=a_1+\alpha*e_1$.
$\alpha = sign(a_{1,1})*\lVert a_{1}\rVert = \sqrt{52} $
so
$$ v_1 = \begin{pmatrix} 4 \\ 6 \end{pmatrix} + \sqrt{52}*\begin{pmatrix}1 \\ 0 \end{pmatrix}$$
BUT the problem is if i calculate Q ouf of this:
$$Q = I- \frac{2*v*v^T}{v^T*v} $$ 
I would be done. It would be $A^TA = QR$ with $ R= QA^TA$. (Sure i am resulting in some matix like $R=\begin{pmatrix} x &y\\0&z\end{pmatrix}$
But if i calculate that with Matlab i get incorrect results ($R=A^Tb$). Even the calculation of $v$ seems to be incorrect since it should ne just simple in fact that no calculater is allowed. If i simply calculate $A^TAx=A^Tb$ it's a simple calculation resulting in $x_1=\frac{7}{12} x_2=\frac{10}{9}$ which i dont get with the QR in any way.
 [/INST] Based on the comments, this is probably what you're supposed to do.
To transform $A$ to the upper triangular form requires an application of two Householder transformations. Take
$$
Q_1=I-2\frac{v_1v_1^T}{v_1^Tv_1}=
\frac{1}{6}
\begin{bmatrix}
    -3  &  -3  &  -3  &  -3 \\
    -3  &   5  &  -1  &  -1 \\
    -3  &  -1  &   5  &  -1 \\
    -3  &  -1  &  -1  &   5 \\
\end{bmatrix}
\quad\text{with}\quad v_1=[3,1,1,1]^T.
$$
This gives
$$
Q_1^TA=\begin{bmatrix}
-2 &   -3 \\
 0 & -4/3 \\
 0 & -1/3 \\
 0 &  8/3
\end{bmatrix}.
$$
Next, take
$$
Q_2=I-2\frac{v_2v_2^T}{v_2^Tv_2}
=\frac{1}{117}\begin{bmatrix}
       117 &   0 &   0 &   0 \\
         0 & -52 & -13 & 104 \\
         0 & -13 & 116 &   8 \\
         0 & 104 &   8 &  53 
\end{bmatrix}
\quad\text{with}\quad v_2=[0,-13/3,-1/3,8/3]^T
$$
to get
$$
R:=Q^TA:=Q_2^TQ_1^TA=
\begin{bmatrix}
 -2 & -3 \\
  0 &  3 \\
  0 &  0 \\
  0 &  0 
\end{bmatrix}.
$$
Apply $Q^T$ to $b$ to get
$$
Q^Tb=
\begin{bmatrix}
-9/2 \\
   10/3 \\
 -11/39 \\
 -19/78
\end{bmatrix}.
$$
Hence, the least squares problem $Ax=b$ is equivalent to the least squares problem
$$
\begin{bmatrix}
 -2 & -3 \\
  0 &  3 \\
  0 &  0 \\
  0 &  0 
\end{bmatrix}x
=
\begin{bmatrix}
-9/2 \\
   10/3 \\
 -11/39 \\
 -19/78
\end{bmatrix}.
$$
The residual 2-norm is minimal, if the first two components of the residual vector are zero, that is,
the least squares solution is given by the solution of
$$
\begin{bmatrix}
 -2 & -3 \\
  0 &  3
\end{bmatrix}x
=
\begin{bmatrix}
-9/2 \\
   10/3
\end{bmatrix}.
$$
</s>