Skip to content
DeepForgeby svx
All problems
MediumLinear Algebrala-285

Gram-Schmidt Next Orthonormal Vector

Problem

Extend an orthonormal pair q1, q2 to include vector a by one step of Gram-Schmidt.

Subtract the projections of a onto q1 and q2, normalize the residual, and return the resulting unit vector. Return None if a lies in span(q1, q2), meaning the residual norm is below 1e-12.

Hint

Assume q1 and q2 are already orthonormal; only one vector needs to be produced.

Test cases

case 1
in: [[1,0,0],[0,1,0],[1,1,1]]
expected: [0,0,1]
case 2
in: [[1,0,0],[0,1,0],[2,0,0]]
expected: null
case 3
in: [[1,0,0],[0,1,0],[0,3,4]]
expected: [0,0,1]
case 4
in: [[0.7071067811865476,0.7071067811865476,0],[0,0,1],[1,1,1]]
expected: null
case 5
in: [[1,0,0],[0,1,0],[0,0,0]]
expected: null
Starter codePython
def gram_schmidt_next(q1, q2, a):
    # Your code here
    pass

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