Declaring a constraint funtion, which value is calculated based on the argument interval?

Hello,

I have a problem, which I will present here in a simplified manner.

Let’s say

r = p * x (for 0<=x<=q)

r = p * q (for x>=q)

How do I declare it in constraint block, as I’m not supposed to use if/then statements?

This could be expressed as:
x >= 0;
r == p*min(x,q);

Unfortunately, p*min(x,q) is not affine in x, and therefore violates the DCP ruleset required by CVX, which mandates that both sides of an equality constraint be affine.

Without seeing your full optimization problem, I don’t know whether there might be some problem reformulation which would be DCP-compliant. Perhaps the min could be moved into the objective function (of course it would have to be a convex optimization problem, which I can’t assess, as I haven’t seen the problem).

Actually, I’m trying to define the revenue contraint rj(xj) in the 4.17 exercise from the cvxbook.

Formulate the problem as a Linear Program (linear objective and constraints), as directed in the exercise, which is being left to you to carry out (hint: consider introducing new variables as necessary). Then it will be DCP-compliant.