All problems
Convexity Check via Hessian
Problem
A twice-differentiable function of two variables is convex when its Hessian is positive semidefinite everywhere.
For the constant Hessian H = [[p, q], [q, r]], this holds exactly when p >= 0, r >= 0, and p*r - q^2 >= 0. Return a boolean.
Hint
Sylvester's criterion for a 2x2 symmetric matrix: all leading principal minors are nonnegative.
Test cases
case 1
in: [2,0,2]
expected: true
case 2
in: [2,3,2]
expected: false
case 3
in: [0,0,0]
expected: true
case 4
in: [1,1,1]
expected: true
case 5
in: [-1,0,1]
expected: false
Starter codePython
def is_convex_hessian(p, q, r):
# Return True if H is positive semidefinite
# Your code here
pass5 test cases · run your code against them in the editor