QR decomposition Q and R matrix I had the vectors $(1,0,1),(-1,1,1),(1,0,1),(-1,1,1)$ and performed the orthogonalization process and got the orthonormal vectors:
$$(\frac{1}{\sqrt{2}}, 0, \frac{1}{\sqrt{2}}), (-\frac{1}{\sqrt{3}}, \frac{1}{\sqrt{3}}, \frac{1}{\sqrt{3}}), (0,0,0), (0,0,0)$$
Now I wasn't sure how to approach putting these vectors into the $Q$ and $R$ matrix since for $Q$ I would get a $3\times 4$ matrix where the first two columns are the first two vectors and the other two columns are the zero vectors.. which I thought becomes a problem for the $R$ matrix since it's supposed to be a upper triangular matrix? Am I able to write the $Q$ matrix as just $3\times 2$ where I just use the first two vectors? I have checked my orthogonalization working and all vectors are orthogonal and when I have checked that they are unit vectors I am just unsure about how to approach the $Q$ and $R$ matrices.
 A: Here's how usually deal with the QR decomposition. Let's call $v_1,v_2,v_3,v_4$ the given vectors and $u_1,u_2,u_3,u_4$ the ones to find with the Gram-Schmidt algorithm.
(GS$\mathbf{1}$)
$u_1=v_1$;
$\langle u_1,u_1\rangle=2$.
(GS$\mathbf{2}$)
$\alpha_{12}=\dfrac{\langle u_1,v_2\rangle}{\langle u_1,u_1\rangle}=0$,
$u_2=v_2-\alpha_{12}u_1=v_2$;
$\langle u_2,u_2\rangle=3$.
(GS$\mathbf{3}$)
$\alpha_{13}=\dfrac{\langle u_1,v_3\rangle}{\langle u_1,u_1\rangle}=1$,
$\alpha_{23}=\dfrac{\langle u_2,v_3\rangle}{\langle u_2,u_2\rangle}=0$,
$u_3=v_3-\alpha_{13}u_1-\alpha_{23}u_2=0$
(GS$\mathbf{4}$)
$\alpha_{14}=\dfrac{\langle u_1,v_4\rangle}{\langle u_1,u_1\rangle}=0$,
$\alpha_{24}=\dfrac{\langle u_2,v_4\rangle}{\langle u_2,u_2\rangle}=1$,
$\alpha_{34}=0$,
$u_4=v_4-\alpha_{14}u_1-\alpha_{24}u_2-\alpha_{34}u_3=0$
Now we set $Q_0=[u_1\ u_2\ u_3\ u_4]$ and $R_0=[\alpha_{ij}]$, where $\alpha_{ij}$ has been determined above for $i<j$, $\alpha_{ii}=1$ and $\alpha_{ij}=0$ for $i>j$:
$$
Q_0=\begin{bmatrix}
1 & -1 & 0 & 0 \\
0 & 1 & 0 & 0 \\
1 & 1 & 0 & 0
\end{bmatrix},
\qquad
R_0=\begin{bmatrix}
1 & 0 & 1 & 0 \\
0 & 1 & 0 & 1 \\
0 & 0 & 1 & 0 \\
0 & 0 & 0 & 1
\end{bmatrix}
$$
From the algorithm above, we know that $[v_1\ v_2\ v_3\ v_4]=Q_0R_0$.
Now the matrix $Q_1$ is obtained from $Q_0$ by removing the null columns; the matrix $R_1$ is obtained from $R_0$ by removing the rows having the same index as the null columns in $Q_0$. This way, $Q_1R_1=Q_0R_0$:
$$
Q_1=\begin{bmatrix}
1 & -1 \\
0 & 1 \\
1 & 1
\end{bmatrix},
\qquad
R_1=\begin{bmatrix}
1 & 0 & 1 & 0 \\
0 & 1 & 0 & 1
\end{bmatrix}
$$
Finally, divide each column of $Q_1$ by its norm and multiply the corresponding row of $R_1$ by the same number:
$$
Q=\begin{bmatrix}
1/\sqrt{2} & -1/\sqrt{3} \\
0 & 1/\sqrt{3} \\
1\sqrt{2} & 1\sqrt{3}
\end{bmatrix},
\qquad
R=\begin{bmatrix}
\sqrt{2} & 0 & \sqrt{2} & 0 \\
0 & \sqrt{3} & 0 & \sqrt{3}
\end{bmatrix}
$$
The matrix $R$ is supposed to be “pseudoupper triangular”: the entries with row index greater than the column index are $0$. The “pseudodiagonal“ entries (with row index equal to the column index) must be nonzero.
