Here is the algorithm for Housholder $QR$ factorization:
$A$ is a $m \times n$ matrix and $m$ is greater than $n$.
$For \quad k=1 \quad to \quad n$
$\quad x = A_{k:m,k}$
$\quad v_{k} = sign(x_{1})||x||_{2}e_{1} + x$
$\quad v_{k} =\frac {v_{k}} {||v_{k}||_2}$
$\quad A_{k:m,k:n}= A_{k:m,k:n} - 2v_{k}( v_{k}^{*} A_{k:m,k:n})$
$End$
Then the following code is a $QR$ factorization algorithm and it is analog to algorithm above but it uses the rotation matrices $F$ and $J$ instead of Householder reflections. $$F = \begin{bmatrix}-c&s \\ s&c \end{bmatrix}$$ $$J= \begin{bmatrix}c&s\\ -s&c \end{bmatrix}$$ $$s = sin(\theta)$$ $$c = cos(\theta)$$ $\theta$ is the angle between a vector and $x$-axis.
$For \quad j=1:n$
$\quad For \quad i=m:-1:j+1$
$\quad \quad a = A(i-1,j) $
$\quad \quad b =A(i,j)$
$\quad \quad c = \frac{a}{\sqrt{(a^2+b^2)}} % c = cos(\theta)$
$\quad \quad s = \frac{b}{\sqrt{(a^2+b^2)}} % s = sin(\theta)$
$\quad \quad A(i-1:i,j:n)=\begin{bmatrix}c&-s \\ s&c \end{bmatrix}*A(i-1:i,j:n);$
$\quad End$
$End$
I cannot really follow the logic of the second algorithm. How it is mapped to the first algorithm or even $QR$ factorization? Does anyone have any insights?
Thanks.