import numpy as np import cvxpy as cp ## PROBLEM 3 # Create data m = 30 n = 10 np.random.seed(2021) A = np.random.randn(m, n) y = np.random.randn(m) # Set up CVX problem x = cp.Variable(n) objective = cp.Minimize(0.5*cp.norm(A@x - y,2)**2) constraints = [0 <= x] prob = cp.Problem(objective, constraints) # The optimal objective value is returned by `prob.solve()` result = prob.solve() # The optimal value for x is stored in `x.value` xstar = x.value # The optimal Lagrange multiplier for a constraint is stored in # `constraint.dual_value` lambdastar = constraints[0].dual_value