Lab 5: Constrained Optimization via Duality & KKT (Quadratic)

CILO: 2
Weeks: 21–23
Lab #5

Aim

Solve a convex quadratic minimization with linear equality constraint and verify KKT conditions.

Objectives

Algorithm / Procedure

  1. Define variables x, y.
  2. Set objective minimize x^2 + y^2.
  3. Set constraint x + y = 1.
  4. Solve with a convex optimizer.
  5. Verify that solution (0.5,0.5) satisfies KKT.

Python Code

import cvxpy as cp

x = cp.Variable()
y = cp.Variable()

objective = cp.Minimize(x**2 + y**2)
constraints = [x + y == 1]

prob = cp.Problem(objective, constraints)
result = prob.solve()

print("Optimal Value:", round(result, 4))
print("x =", round(x.value, 4), "y =", round(y.value, 4))

Sample Output (expected)

Optimal Value: 0.5
x = 0.5 y = 0.5