-3

I want to solve a non-linear optimization problem using cvxpy. I get a DCP Error when introducing 1/x in the constraints, where x is a variable.

For instance such a code leads to a DCP Error

import cvxpy

x = cvxpy.Variable(1)

obj = cvxpy.Maximize(x)
cst = [1/x >= 1]

prob = cvxpy.Problem(obj, cst)
opt_val = prob.solve()

Expected result is x=1. Also 1/x is obviously convex so I don't understand what the problem is...

Til
  • 5,150
  • 13
  • 26
  • 34
Xb19
  • 130
  • 2
  • 10
  • 1
    Look at the error message `DCPError("Can only divide by a scalar constant.")`. You are dividing by a variable. – Jacques Kvam Jun 14 '19 at 05:01
  • I do not have this prompt. Mine says "DCPError: Problem does not follow DCP rules." EDIT : as it is allowed to divide by a variable in CVXOPT, I would assume it is also possible using CVXPY – Xb19 Jun 14 '19 at 23:15

1 Answers1

0

I fixed the issue by adding an optionnal parameter to prob.solve() :

import cvxpy

x = cvxpy.Variable(1)

obj = cvxpy.Maximize(x)
cst = [1/x >= 1]

prob = cvxpy.Problem(obj, cst)
opt_val = prob.solve(qcp=True)
opt_val

Returns x = 1 as expected.

Xb19
  • 130
  • 2
  • 10