python - convex programming with cvxopt or cvxpy -
i need optimize problem cvxopt or cvxpy in python , it's being kind of dificult:
obj function:
minimize sum(a*x^2+b/x)
st:
5 <= x < 40; sum(v/d)<=t
where x
variable (vector);
, b know vectors , t constant.
the following code solves problem in cvxpy. assumed meant sum(x/d) <= t
.
# replace these values. n = 2 = 2 b = 2 d = 2 t = 1000 import cvxpy cvx x = cvx.variable(n) obj = cvx.sum_entries(a*x**2 + b*cvx.inv_pos(x)) constr = [5 <= x, x <= 40, cvx.sum_entries(x/d) <= t] prob = cvx.problem(cvx.minimize(obj), constr) prob.solve()
Comments
Post a Comment