If statement error


(Micaela Serôdio) #1

hi, I’m having a problem with an if statement

if (norm(Ex(:,k) - c_pos(:,k))-2)<=0
d=0;
else d=(norm(E
x(:,k) - c_pos(:,k))-2);

It appears that
“The following error occurred converting from cvxcnst to logical:
Disciplined convex programming error:
Constraints may not appear in if/then statements.”

How can i do it without having this issue. Ty


(Mark L. Stone) #2

You need to use Big M approach using binary variables using CVX’s MIDCP capability. Search on this forum for relevant posts. You can read chapter 9 of https://docs.mosek.com/MOSEKModelingCookbook-letter.pdf and also read https://www.artelys.com/uploads/pdfs/Xpress/mipformref-1.pdf .


(Xixi) #3

Did you solve it? I have the same problem.


(Mark L. Stone) #4

if you have the same problem, the same links apply to you.