Optimize control value=NaN

299 views
Skip to first unread message

Himanshu Nagpal

unread,
Jun 8, 2015, 9:29:51 AM6/8/15
to yal...@googlegroups.com
Hi all,

Below is the simple code given in yalmip examples on yalmip website.

yalmip('clear')
clear all

% Model data
A = [2 -1;1 0.2];
B = [1;0];
nx = 2; % Number of states
nu = 1; % Number of inputs

% MPC data
Q = eye(2);
R = 2;
N = 7; %prediction horizon

% Initial state
x0 = [3;1];

u = sdpvar(repmat(nu,1,N),repmat(1,1,N));

constraints = [];
objective = 0;
x = x0;
for k = 1:N
 x = A*x + B*u{k};
 objective = objective + norm(Q*x,1) + norm(R*u{k},1);
 constraints = [constraints, -1 <= u{k}<= 1, -5<=x<=5];
end
optimize(constraints,objective);
value(u{1})


But I get the solution =NaN. I have tried several times.

Please help me, why it appears NaN always.

Thanks,

Himanshu


Johan Löfberg

unread,
Jun 8, 2015, 9:31:57 AM6/8/15
to yal...@googlegroups.com
So what is returned when you tun optimize (i.e., remove the ;)


optimize(constraints,objective)

ans = 

    yalmiptime: 0.8003
    solvertime: 0.0057
          info: 'Successfully solved (GUROBI-GUROBI)'
       problem: 0



Himanshu Nagpal

unread,
Jun 8, 2015, 9:36:04 AM6/8/15
to yal...@googlegroups.com
I get the following solution after removing ; .

 yalmiptime: NaN
   solvertime: NaN
          info: 'Unknown problem in solver (try using 'debug'-flag in sdpsettings) (Error using linprog (line 164)
Invalid choice of Al...'
       problem: 9


ans =

   NaN

Johan Löfberg

unread,
Jun 8, 2015, 9:40:40 AM6/8/15
to yal...@googlegroups.com
OK. This is due to a known issue in matlab 2015a when you only have linprog available.

If you explicitly select the solver, it will work I think
optimize(constraints,objective,sdpsettings('solver','linprog'))

Of course, if you intend to solve any real problem, you should install a better LP solver

Himanshu Nagpal

unread,
Jun 8, 2015, 9:46:43 AM6/8/15
to yal...@googlegroups.com
yups its a problem of solver. I will try to install cplex.

Himanshu Nagpal

unread,
Jun 8, 2015, 9:46:57 AM6/8/15
to yal...@googlegroups.com
thank you.

Johan Löfberg

unread,
Jun 8, 2015, 9:48:02 AM6/8/15
to yal...@googlegroups.com
the bug is in yalmip

Himanshu Nagpal

unread,
Jun 8, 2015, 10:07:41 AM6/8/15
to yal...@googlegroups.com
still getting the same error even after using specific solver (linprog).


    yalmiptime: NaN
    solvertime: NaN
          info: 'Unknown problem in solver (try using 'debug'-flag in sdpsettings) (Error using linprog (line 164)
Invalid choice of ...'

Johan Löfberg

unread,
Jun 8, 2015, 10:12:51 AM6/8/15
to yal...@googlegroups.com
ok, replace extras/sdpsettings and solvers/yalmip2quadprog
sdpsettings.m
yalmip2quadprog.m

Himanshu Nagpal

unread,
Jun 8, 2015, 10:18:52 AM6/8/15
to yal...@googlegroups.com
Thank you so much, It is working now. 

-Himanshu
Reply all
Reply to author
Forward
0 new messages