Nonlinear optimal control by using yalmip

8 次查看(过去 30 天)
Kazu
Kazu 2013-10-10
编辑: Kazu 2016-10-9
I tried to implement the nonlinear optimal control by using YALMIP. The nonlinear dynamics involves sin and cos function and the code is;
%
yalmip('clear')
clear all
Q1 = eye(3);
R = 0.5*eye(2);
N=30;
u1 = sdpvar(N,1);
u2 = sdpvar(N,1);
x01 = sdpvar(1,1);
x02 = sdpvar(1,1);
x03 = sdpvar(1,1);
constraints = [];
objective = 0;
x1 = x01;
x2 = x02;
x3 = x03;
T=0.2; %sampling time
for k = 1:N
u1k = u1(k);
u2k = u2(k);
x1 = x1-u1k*T*cos(x3);
x2 = x2-u1k*T*sin(x3);
x3 = x3-u2k*T;
xk=[x1;x2;x3];
uk=[u1k;u2k];
objective = objective + norm(Q1*xk,1) + norm(R*uk,1);
constraints = [constraints, -3 <= u1k<= 3, -1 <= u2k<= 1,-pi<=x3<=pi];
end
options = sdpsettings('verbose',1,'solver','fmincon');
controller = optimizer(constraints,objective,options,[x01;x02;x03],[u1 u2]);
x=[10;15;pi];
uopt=controller{x}
%
Then I get the strange optimal control inputs, where all the components are "NaN". It seems that the reason is because I used the nonlinear operators "sin"and "cos". Anybody knows how to fix this problem?
Thank you

回答(1 个)

Johan Löfberg
Johan Löfberg 2013-11-5
The problem is that you are creating a nonconvex nonlinear problem, and fmincon simply fails to find a solution. You see this if you catch the problem flag from the optimizer call
[uopt,problem]=controller{x}
The model you create is extremely complex. Since you declare the dynamics using assignments, x(N) will be an enormously complex function of the input variables. The computational tree will really deep. It is much better if you declare the MPC problem in implicit prediction form (i.e., optimize over both x and u and connect them using equality constraints). See the YALMIP Wiki for details on MPC examples.
Having said that, it will still be nonlinear and nonconvex and most likely fmincon will struggle to find a solution. Start with N=1, and if that doesn't work, well...

类别

Help CenterFile Exchange 中查找有关 Nonlinear Optimization 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by