Solution (source code)

= Solution

A <Givens rotation> $\Omega^{[p,q]}$ is the identity except in rows and columns $p,q$, where it has the block
$$
\begin{pmatrix}c&s\\-s&c\end{pmatrix},
\qquad c=\cos\theta,
\quad s=\sin\theta.
$$
For $a=A_{pj}$ and $b=A_{qj}$, choose
$$
c=\frac{a}{\sqrt{a^2+b^2}},
\qquad
s=\frac{b}{\sqrt{a^2+b^2}}
$$
when $(a,b)\ne(0,0)$. Then
$$
(\Omega^{[p,q]}A)_{qj}=-sa+cb=0.
$$
If both entries vanish, any angle works.

For the given <matrix>, first use
$$
\Omega^{[1,3]}=
\begin{pmatrix}
1/\sqrt2&0&1/\sqrt2\\
0&1&0\\
-1/\sqrt2&0&1/\sqrt2
\end{pmatrix}.
$$
It gives
$$
\Omega^{[1,3]}A=
\begin{pmatrix}
2&1&1\\
0&\sqrt3&0\\
0&1&\sqrt3
\end{pmatrix}.
$$
Then use
$$
\Omega^{[2,3]}=
\begin{pmatrix}
1&0&0\\
0&\sqrt3/2&1/2\\
0&-1/2&\sqrt3/2
\end{pmatrix}.
$$
Thus $R=\Omega^{[2,3]}\Omega^{[1,3]}A$ is
$$
R=
\begin{pmatrix}
2&1&1\\
0&2&\sqrt3/2\\
0&0&3/2
\end{pmatrix}.
$$
All leading row entries are positive. The resulting <QR decomposition by Givens rotations> is
$$
\boxed{A=QR},
$$
where
$$
\boxed{
Q=(\Omega^{[2,3]}\Omega^{[1,3]})^T
=\begin{pmatrix}
\sqrt2/2&-\sqrt2/4&-\sqrt6/4\\
0&\sqrt3/2&-1/2\\
\sqrt2/2&\sqrt2/4&\sqrt6/4
\end{pmatrix}}
$$
and $R$ is the <matrix> above. Since it is a product of transposed rotations, $Q$ is orthogonal.