Skip to content
DeepForgeby svx
All problems
MediumCalculusca-271

PSD Check with Smallest Eigenvalue

Problem

A symmetric 2x2 matrix H = [[a, b], [b, c]] is positive semidefinite exactly when its smallest eigenvalue is nonnegative.

That eigenvalue is (a + c)/2 - sqrt(((a - c)/2)^2 + b^2). Given a, b, c, return [is_psd, lambda_min], which also certifies convexity of a quadratic with this Hessian.

Hint

The eigenvalues of a symmetric 2x2 matrix have a closed form via the discriminant.

Test cases

case 1
in: [2,0,2]
expected: [true,2]
case 2
in: [2,3,2]
expected: [false,-1]
case 3
in: [0,0,0]
expected: [true,0]
case 4
in: [1,1,1]
expected: [true,0]
case 5
in: [-1,0,1]
expected: [false,-1]
Starter codePython
def psd_check_2x2(a, b, c):
    # Return [is_psd, lambda_min]
    # Your code here
    pass

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