Skip to content
DeepForgeby svx
All problems
HardLinear Algebrala-137

QR Decomposition

Problem

Compute the reduced QR decomposition A = Q*R of an n x 2 matrix A with linearly independent columns.

Build the two orthonormal columns of Q (n x 2) with Gram-Schmidt and the upper triangular R (2 x 2). Return [Q, R], with entries as floats.

Hint

R stores the projection coefficients r01 and the residual norm r11.

Test cases

case 1
in: [[[1,0],[0,1]]]
expected: [[[1,0],[0,1]],[[1,0],[0,1]]]
case 2
in: [[[1,1],[1,2],[1,3]]]
expected: [[[0.5773502691896258,-0.7071067811865475],[0.5773502691896258,0],[0.5773502691896258,0.7071067811865475]],[[1.7320508075688772,3.4641016151377553],[0,1.4142135…
case 3
in: [[[1,1],[1,-1]]]
expected: [[[0.7071067811865475,0.7071067811865475],[0.7071067811865475,-0.7071067811865475]],[[1.4142135623730951,0],[0,1.4142135623730951]]]
case 4
in: [[[2,0],[0,1]]]
expected: [[[1,0],[0,1]],[[2,0],[0,1]]]
Starter codePython
def qr_decomposition(A):
    # Your code here
    pass

4 test cases · run your code against them in the editor