logical for sdpvar

127 views
Skip to first unread message

Abdul

unread,
Mar 19, 2014, 9:53:54 AM3/19/14
to yal...@googlegroups.com
Hi
I have two sdpvar x and y and I am trying to use logical condition: if x==y, statements end;
I receive the error message

error occurred converting from lmi to logical:
Undefined function or method 'logical' for input arguments of type 'lmi'.

I tried the command true(x==y) instead and I also received an error message : Inputs must be numeric !!
Any help appreciated.

Johan Löfberg

unread,
Mar 19, 2014, 10:04:22 AM3/19/14
to
As I answered on mail to you, you have to do modelling using binary variables and implies operators.

if x == y
 z should be 5
end

Model= [implies(x == y, z = 5)]

This is a very ill-conditioned model though if x and y are continuous variables, as the condition is pretty much undefined when |x-y| is smaller than the solver tolerance (starting at, say, 1e-6)

Generally, try to write logical models as implies(binary variable, condition) and then impose logics using additional constraints on the binary variables. That way, you know what you are doing and nothing strange can happen
http://users.isy.liu.se/johanl/yalmip/pmwiki.php?n=Commands.Implies

The model above would be something like
binvar negative positive zero
margin
= 0.001 % or whatever you think is close enough to zero)
Model = [implies(negative, x <= y-margin), implies(zero, -margin <= x - y <= margin), implies(positive, x >= y + margin)];
Model = [Model, implies(zero, z == 5);
Model = [Model, negative+zero+positive == 1]


As always in big-M based models, you have to explicit good bounds on all involved variables (x and y)



yajna maharaj

unread,
Dec 28, 2015, 2:46:42 AM12/28/15
to YALMIP
Hi All

I need to use the implies statement as well, but my constraint is slightly different. Working with the same example, my problem is as follows: 

if x-y<=0, z should be 0
if x-y>0, z should be (x-y)

I am just having a bit of trouble extending the logic from the code that was posted to my problem. 

Any help would be appreciated!

Johan Löfberg

unread,
Dec 28, 2015, 3:16:42 AM12/28/15
to YALMIP
Binary or continuous variables?

yajna maharaj

unread,
Dec 28, 2015, 3:43:38 AM12/28/15
to YALMIP
All are continuous variables (unfortunately).

Johan Löfberg

unread,
Dec 28, 2015, 2:01:56 PM12/28/15
to YALMIP
The obvious model would be

binvar case1 case 2
Model = [implies(case1, [x-y<=0,z==0]), implies(case2,[x-y>=0, z ==(x-y)]), case1+case2 == 1]

and as always, you have to have explicit bounds on the variables x,y,z to make the big-M model numerically sound, and you will not have any control over what happens when x+y=0, as you always have numerical tolerances in the solver etc

Reply all
Reply to author
Forward
0 new messages