Skip to content
DeepForgeby svx
All problems
HardLinear Algebrala-267

One-Sided Jacobi SVD Step

Problem

Compute the rotation parameters [c, s] of a one-sided Jacobi step that orthogonalizes two column vectors p and q.

With a = p.p, b = q.q, d = p.q, set zeta = (b - a) / (2d), t = sign(zeta) / (|zeta| + sqrt(1 + zeta^2)), c = 1 / sqrt(1 + t^2), and s = c*t. Return [1.0, 0.0] when d == 0.

Hint

Applying the rotation (p, q) -> (c*p - s*q, s*p + c*q) makes the two columns orthogonal.

Test cases

case 1
in: [[1,1],[1,0]]
expected: [0.8506508083520399,-0.5257311121191335]
case 2
in: [[1,0],[0,1]]
expected: [1,0]
case 3
in: [[2,1],[1,2]]
expected: [0.7071067811865475,0.7071067811865475]
case 4
in: [[1,1],[1,-1]]
expected: [1,0]
Starter codePython
def jacobi_orthogonalize(p, q):
    # Your code here
    pass

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