Skip to content
DeepForgeby svx
All problems
MediumLinear Algebrala-083

Eigenvalues 2x2

Problem

Compute the real eigenvalues of a 2x2 matrix from the characteristic polynomial

lambda^2 - tr(A)*lambda + det(A) = 0

Return [larger, smaller] as floats, or None if the discriminant tr^2 - 4*det is negative.

Hint

The trace is the sum of the eigenvalues and the determinant is their product.

Test cases

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

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