pythonmatlaboptimizationcvxpycvx

CVXPY - passing both variables and constants


I'm trying to do the following (CVX matlab code):

variable x(2)
minimize(norm([x;1]) + 2*max([x;0])

But when I try to this in python CVXPY, I get an error:

x = Variable(2)
norm([x, 1])

TypeError: float() argument must be a string or a number, not 'Variable'


Solution

  • from cvxpy import *
    x = Variable(2)
    prob=Problem(Minimize(norm(hstack([x, 1]))))
    prob.solve()