Can’t I use find in general on a set of terms where each term has a cvx variable in it ?

# Undefined function 'find' for input arguments of type 'cvxcnst'

**Mark_L_Stone**(Mark L. Stone) #2

No.

Depending om what you are trying to do, perhaps there’s a way of using CVX’;s MIDCP capability to accomplish what you want.

**menna_khaled**(Menna Khaled) #3

I tried to do it using an if statement and got this error

"Constraints may not appear in if/then statements"

So there’s no manipulation that I can do to check the value of a term including a cvx variable ?

**Mark_L_Stone**(Mark L. Stone) #4

You’ll have to show us what you are trying to accomplish. You may benefit from (re-)reading Why isn’t CVX accepting my model? READ THIS FIRST! and the CVX Users’ Guide

**menna_khaled**(Menna Khaled) #5

number = 8;

cvx_begin gp

variable vars(5)

minimize(sum(vars))

exp1 = vars(1)*vars(2);

exp2 = vars(3)*vars(4);

exp3 = vars(5)*vars(1);

if exp1<1

exp1 = 1;

end

prod([exp1 exp2 exp3])>number

cvx_end

**menna_khaled**(Menna Khaled) #6

this is a simplified version of what I want to do, I don’t want to discard the solution altogether in case this condition isn’t satisfied that’s why I needn’t add it as a constraint. However, I need to eliminate the effect of exp1 from the expression in case it’s lower than a certain number

**Mark_L_Stone**(Mark L. Stone) #7

You could use `exp1 = max(vars(1)*vars(2),1);`

instead of the `if,`

but would then not be allowed to have exp1 in the prod constraint.

Alternatively, you could declare exp1adj as a variable and write

`exp1adj>=vars(1)*vars(2); exp1adj>=1;`

and use exp1adj in the prod constraint. But then you would need to add a binary with a big M style constraint to enforce the max because your program doesn’t force things in the right direction without it. And I believe those extra constraints to do that would not be allowed in your gp.

So I don’t see how to do this even as an MIDCP. If someone else can figure out a way to do it, please post it.

**menna_khaled**(Menna Khaled) #8

when I tried your first option I got this error:

Cannot perform the operation min( {log-convex}, {real constant} )

And my expression is indeed log-convex, but when I wrote the same expression with max instead of min it worked fine and in addition, the prod less than a certain number worked fine!

So my problem now is that I need it to be min not max, no workaround through this ?

**Mark_L_Stone**(Mark L. Stone) #9

I was trying to say:

`exp1 = vars(1)*vars(2); if exp1<1 exp1 = 1; end`

is equivalent to `exp1 = max(vars(1)*vars(2),1);`

. So I don;t know why you’re talking about min.

I don;t see how, even using MIDCP capability, to implement the model you wrote in CVX.

However, with the particular input data you have provided, I ran the problem

number = 8;

cvx_begin gp

variable vars(5)

minimize(sum(vars))

exp1 = vars(1)*vars(2);

exp2 = vars(3)*vars(4);

exp3 = vars(5)*vars(1);

prod([exp1 exp2 exp3])>number

cvx_end

and it turned out that the optimal solution has exp1 = 2.519813223126918, which satisfies your requirement to have it be >= 1. And therefore your problem has been solved in this instance. I.e., I relaxed (omitted) a constraint, but it happened to be satisfied at the optimum of the relaxed problem. You said that this was a simplified version of what you want to do, so I don;t know whether this same approach will work for your “real” problem.

**menna_khaled**(Menna Khaled) #10

It’s just that I did a simplified version of the code for you, when I tried it it was max(log-concave,1) so it gave an error so I tried the minimum of 1/firstArgument and 1/secondArgument.

However, this works with no errors:

number = 8;

cvx_begin gp

variable vars(5)

minimize(sum(vars))

exp1 = max(vars(1)*vars(2),cvx(ones(1,1)));

exp2 = vars(3)*vars(4);

exp3 = vars(5)*vars(1);

prod([exp1 exp2 exp3])<=number

cvx_end