Matrix with both integer and non integer values

Hello everyone,

I have a matrix of lets say n variables. Very few of them have to be integer and equal between them. I am a bit stack because till now I have not used a matrix with mixed values, only full integers or no integers. Can this be done somehow with the integer keyword? Is there an elegant way to do it? I tried:
variable UVW(length(X),3); variable UVW(Ufirst,1) integer; variable UVW(Vfirst,2) integer; variable UVW(Wfirst,3) integer;

But of course I get the error: Duplicate variable name: UVW.

Any idea?

You could declare integer variables and separately declare continuous variables. Then concatenate all the variables into the matrix you want.

variables a b
variable c integer
M = [a c;c b]

You can also use other keywords when declaring variables, as discussed in The Basics — CVX Users' Guide .
Here’s a (stupid) illustration

cvx_begin
variable X(2,2) diagonal integer
variable Y(2,2) banded(1,1)
Z = X + Y
minimize(trace(Z))
Z == semidefinite(2)
cvx_end

Just concatenating them as you did ruins the order though. Lets make up a scenario. Suppose you have :

        cvx_begin
        variable x(10)

And we need the first and the fifth to be integer. Appending the two integer ones at the end means we somehow have to rearrange them. Creating a new matrix of indices might solve this, but it is definitively not that elegant. Any suggestion? I did not probably make the problem clear in the initial question.

variable a(2) integer
variable b(8)
x = [a(1);b(1:3);a(2);b(4:8)]

I’ll leave any elegance refinement and index wizardry to you.

Just use equality constraints. Create new integer variables, and constraint them to be equal to the elements in the matrix you need to be integers.

1 Like

This sounds cleaner. Thanks Michael.