Skip to content
DeepForgeby svx
All problems
MediumLinear Algebrala-312

Singular Values of 3x2 via A^T A

Problem

Compute the two singular values of a 3x2 matrix A as square roots of the eigenvalues of A^T A.

A^T A is 2x2, so its eigenvalues come from the quadratic formula. Return [larger, smaller] as floats, clamping tiny negative numerical eigenvalues to zero.

Hint

Singular values are the square roots of the eigenvalues of the Gram matrix A^T A.

Test cases

case 1
in: [[[1,0],[0,1],[0,0]]]
expected: [1,1]
case 2
in: [[[3,0],[0,0],[0,0]]]
expected: [3,0]
case 3
in: [[[1,1],[0,0],[1,1]]]
expected: [2,0]
case 4
in: [[[1,0],[1,0],[0,1]]]
expected: [1.4142135623730951,1]
case 5
in: [[[2,1],[0,0],[0,0]]]
expected: [2.23606797749979,0]
Starter codePython
def singular_values_3x2(A):
    # Your code here
    pass

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