All problems
Convexity Check Quadratic
Problem
Check whether a 2x2 quadratic has a positive semidefinite Hessian.
With A = [[a, b], [c, d]], symmetrize b = (b + c) / 2 and return True only when a >= 0, d >= 0, and a * d - b ** 2 >= 0. These are the Sylvester conditions for convexity.
Hint
A symmetric 2x2 matrix is PSD when its diagonal is non-negative and its determinant is non-negative.
Test cases
case 1
in: [[[2,1],[1,2]]]
expected: true
case 2
in: [[[2,3],[3,2]]]
expected: false
case 3
in: [[[0,1],[1,0]]]
expected: false
case 4
in: [[[1,0],[0,0]]]
expected: true
Starter codePython
def is_convex_quadratic(A):
# Your code here
pass4 test cases · run your code against them in the editor