All problems
Modified Gram-Schmidt QR
Problem
Compute the QR decomposition A = Q*R of an n x 3 matrix A with linearly independent columns using modified Gram-Schmidt.
Q is n x 3 with orthonormal columns and R is 3x3 upper triangular: R[k][j] is the projection of column j onto q_k, and R[j][j] is the residual norm. Return None if some column reduces to norm below 1e-12.
Hint
Modified Gram-Schmidt subtracts projections from the current residual rather than the original column.
Test cases
case 1
in: [[[1,0,0],[0,1,0],[0,0,1]]]
expected: [[[1,0,0],[0,1,0],[0,0,1]],[[1,0,0],[0,1,0],[0,0,1]]]
case 2
in: [[[1,0,0],[1,1,0],[1,1,1]]]
expected: [[[0.5773502691896258,-0.8164965809277263,0],[0.5773502691896258,0.4082482904638628,-0.7071067811865476],[0.5773502691896258,0.4082482904638628,0.70710678118654…
case 3
in: [[[1,1,0],[0,1,1],[1,0,1]]]
expected: [[[0.7071067811865475,0.40824829046386313,-0.5773502691896257],[0,0.8164965809277261,0.5773502691896256],[0.7071067811865475,-0.40824829046386296,0.577350269189…
case 4
in: [[[1,0,0],[2,0,0],[0,1,1]]]
expected: null
case 5
in: [[[2,0,0],[0,3,0],[1,1,5]]]
expected: [[[0.8944271909999159,-0.12777531299998798,-0.4285714285714286],[0,0.9583148474999099,-0.28571428571428575],[0.4472135954999579,0.25555062599997597,0.8571428571…
Starter codePython
def modified_gram_schmidt_qr(A):
# Your code here
pass5 test cases · run your code against them in the editor