following the formulation in the link:
Householder matrix and QR factorization.PDF
the code is as follows: