All problems
Singular Values 2x2
Problem
Compute the singular values of a 2x2 matrix A as the square roots of the eigenvalues of A^T A.
Return [larger, smaller] as floats. Singular values are non-negative even when a numerical eigenvalue is slightly negative.
Hint
A^T A is symmetric positive semidefinite, so its eigenvalues are non-negative.
Test cases
case 1
in: [[[1,0],[0,2]]]
expected: [2,1]
case 2
in: [[[3,0],[0,4]]]
expected: [4,3]
case 3
in: [[[1,1],[0,0]]]
expected: [1.4142135623730951,0]
case 4
in: [[[1,2],[3,4]]]
expected: [5.464985704219043,0.3659661906262571]
Starter codePython
def singular_values_2x2(A):
# Your code here
pass4 test cases · run your code against them in the editor