Skip to content
DeepForgeby svx
All problems
MediumLinear Algebrala-209

Givens Rotation Parameters

Problem

Return the Givens rotation parameters [c, s] that zero out the second component of [a, b]:

[[c, s], [-s, c]] * [a, b] = [r, 0], with r = sqrt(a^2 + b^2)

Return [1.0, 0.0] if both inputs are 0.

Hint

The resulting matrix is orthogonal with determinant 1 and c^2 + s^2 = 1.

Test cases

case 1
in: [3,4]
expected: [0.6,0.8]
case 2
in: [0,1]
expected: [0,1]
case 3
in: [0,0]
expected: [1,0]
case 4
in: [-3,4]
expected: [-0.6,0.8]
Starter codePython
def givens_parameters(a, b):
    # Your code here
    pass

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