Skip to content
DeepForgeby svx
All problems
HardOptimizationop-073

Condition Number Estimate 2x2

Problem

Estimate the condition number of a 2x2 matrix from its eigenvalues.

For A = [[a, b], [c, d]], the eigenvalues are mid +/- sqrt(((a - d) / 2) ** 2 + b * c) with mid = (a + d) / 2. Return the ratio of the largest absolute eigenvalue to the smallest, or -1.0 when the smallest is zero.

Hint

The ratio of extreme absolute eigenvalues is the 2-norm condition number.

Test cases

case 1
in: [[[2,1],[1,2]]]
expected: 3
case 2
in: [[[4,1],[1,3]]]
expected: 1.9387489019317514
case 3
in: [[[1,2],[2,1]]]
expected: 3
case 4
in: [[[1,1],[1,1]]]
expected: -1
Starter codePython
def condition_number_2x2(A):
    # Your code here
    pass

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