Using check() function for results from optimizer()

19 views
Skip to first unread message

XB G

unread,
Sep 21, 2018, 3:51:02 PM9/21/18
to YALMIP
I'm running this example from the post on optimizer():

clear
sdpvar x a b
Constraints = [-a <= x <= a];
Objective = (x-b)^2;
Saturation = optimizer([-a <= x <= a], Objective,[],[a;b],x);
xoptimal = Saturation{[1;3]};

check(Constraints)

The last line tries to calculate the residues of constraints, but it returns NaN. What is the best/easiest way to check feasibility using the solution found by optimizer()?

Thanks!

Johan Löfberg

unread,
Sep 21, 2018, 4:42:41 PM9/21/18
to YALMIP
you cannot use check with optimizer. optimizer is extremely bare bones and does nothing more but returning a solution, in order to keep it as fast as possible

XB G

unread,
Sep 21, 2018, 6:19:54 PM9/21/18
to YALMIP
A (trivial) solution is to manually assign values to all variables, then use check(). This might easily cause mistakes but it does work..

clear
sdpvar x a b
Constraints = [-a <= x <= a];
Objective = (x-b)^2;
Saturation = optimizer([-a <= x <= a], Objective,[],[a;b],x);
xoptimal = Saturation{[1;3]};

assign(x, xoptimal); assign(a, 1); assign(b,3);
check(Constraints) 

Johan Löfberg

unread,
Sep 22, 2018, 2:43:48 AM9/22/18
to YALMIP
Sure (but then why use optimize when you are doing such slow operations anyway)
Reply all
Reply to author
Forward
0 new messages