I need to solve an optimization problem with CVXOPT or CVXPY in Python and I have run into difficulties. The objective function is
Minimize Sum(a*x^2+b/x)
subject to the following constraints
5 <= x < 40;
sum(v/d)<=T
where vector x
is the optimization variable, vectors a
and b
are given, and T
is a given scalar.
The following code solves the problem in CVXPY. I assumed that you meant sum(x/d) <= T
.
# Replace these with your values.
n = 2
a = 2
b = 2
d = 2
T = 1000
import cvxpy as 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()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.