All problems
Householder QR Step
Problem
Apply one Householder QR step to the first column of matrix A (n x 2).
Build the unit Householder vector from the first column with alpha = -sign(col[0]) * ||col||_2, form H = I - 2*v*v^T, and return H*A with zeros below the first entry of column 0.
Hint
The Householder reflection maps the first column to a multiple of e1, producing a triangular first column.
Test cases
case 1
in: [[[3,4],[0,0],[0,0]]]
expected: [[-3,-4],[0,0],[0,0]]
case 2
in: [[[1,1],[1,2],[1,3]]]
expected: [[-1.7320508075688772,-3.4641016151377544],[0,0.3660254037844386],[0,1.3660254037844384]]
case 3
in: [[[1,0],[0,1],[0,0]]]
expected: [[-1,0],[0,1],[0,0]]
case 4
in: [[[2,3],[2,1],[0,0]]]
expected: [[-2.828427124746189,-2.8284271247461885],[0,-1.414213562373095],[0,0]]
Starter codePython
def householder_qr_step(A):
# Your code here
pass4 test cases · run your code against them in the editor