How to use "external" MATLAB functions in CVX?

(Prashant Saikia) #1

I have a constraint in my problem that uses floor function on the optimization variable, x (which is a vector), to check if x contains integers or not, as I want only integer solutions.

for i=1:n

CVX is not able to handle it and throws the following error:

Undefined function ‘floor’ for input arguments of type ‘cvx’.

How do I overcome this?

The same error is shown when I use the mod or the rem functions:

for i=1:n

Undefined function ‘rem’ for input arguments of type ‘cvx’.

for i=1:n
	mod(x(i,1),2)==0 | mod(x(i,1),2)==1

Undefined function ‘mod’ for input arguments of type ‘cvx’.

(Mark L. Stone) #2

These are non-convex functions. Please read Why isn’t CVX accepting my model? READ THIS FIRST! and the CVX Users’ Guide.

(Prashant Saikia) #3

Oh. I did not know these are non-convex functions. If only CVX gave the error “non-convex constraint” or something. Anyway, could you please advise me on how to write a convex constraint to make my solution lie in the domain of integers?

(Michael C. Grant) #4

The message you received is MATLAB’s error message; CVX is not involved, and actually cannot be. In order for CVX to intervene in situations like this, it would be necessary to write special “error-trapping” code code for every single function in MATLAB’s library, even the functions that it cannot and does not support. That is clearly untenable.

So instead, we have an extensive users guide, including a list of functions that CVX does support, and the FAQ linked to above—which actually explains the meaning of the exact message MATLAB gave you. Please read those before you proceed with CVX any further.

(Mark L. Stone) #5

You can declare variables as integer or binary, per the CVX User’s Guide. You can solve it if you have version of CVX and solver which supports MIDCP.