Clarification on Chained Inequality Warning in YALMIP

14 views
Skip to first unread message

yize

unread,
Jul 11, 2025, 10:45:09 PMJul 11
to YALMIP
  Dear Prof.Johan Löfberg

 While using YALMIP with Gurobi in MATLAB R2024a, I received the following warning when writing a chained inequality:  
 ⚠️ a <= b <= c interpreted as (a <= b) <= c.
Normally, you probably intended to test a <= b <= c in a mathematical sense.
If all arguments are numeric scalars, use (a <= b) && (b <= c),
otherwise use (a <= b) & (b <= c).  

 Here is a minimal working example:  

F = sdpvar(1,1);
Constraints = [];
Constraints = [Constraints; 2 <= F <= 5];
Constraints = [Constraints; F == 3];
solver_options = sdpsettings('solver', 'gurobi', 'verbose', 2);
sol = optimize(Constraints, [], solver_options);
value(F)

Despite the warning, the result I got was correct: F = 3.

My question is: in the case of scalar decision variables such as F, can this warning safely be ignored in practice? That is, does YALMIP automatically treat 2 <= F <= 5 as (2 <= F) & (F <= 5) in such cases? Or is it recommended that we always write the constraints explicitly as:

Constraints = [Constraints; 2 <= F; F <= 5];

  Thank you very much for your time and for your continued work on YALMIP!  

Best regards,
Yize Liu

Johan Löfberg

unread,
Jul 12, 2025, 2:59:45 AMJul 12
to YALMIP
Sounds like you are looking at some lint warning from matlab. that is irrelevant as it does not understand yalmip code.

[a <= b<=c] is short for [a<=b, b<= c]

Reply all
Reply to author
Forward
0 new messages