2
votes

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.

1

1 Answers

5
votes

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()