Skip to content
DeepForgeby svx
All problems
HardOptimizationop-363

KKT Point for Diagonal Quadratic

Problem

Minimize x^2 + y^2 subject to x + 2y = c. Stationarity gives 2x = lambda and 2y = 2 lambda, so x = c/5 and y = 2c/5 with lambda = 2c/5.

Given c, return [x, y, lambda].

Hint

Solve the linear system from the two stationarity equations and the constraint.

Test cases

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

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