Index exceeds the number of array elements (1)

1 次查看(过去 30 天)
Hello,
I'm implementing NMPC for the control of quadcopter. minimal_example is the script which calls nmpc. u is the control vector of 4 variables, x is a state vector of 12 variables. Dynamic equations (second order system) are described in mathmodel function. During the simulation it shows the error:
Index exceeds the number of array elements (1).
Error in minimal_example>mathmodel (line 82)
xdot = [x(2);
Can anyone suggest how can I fix it? Thank you in advance!
function xdot = mathmodel(t, p, x, u, T)
xdot = [x(2);
(x(4)*x(6)*(p.Iyy-p.Izz)-(u(1)+u(2)+u(3)+u(4))*p.IR*x(4)...
+(p.b*p.l*(u(2)^2-u(4)^2)))/p.Ixx; %phi_dot
x(4); %theta
(x(2)*x(6)*(p.Izz-p.Ixx)+(u(1)+u(2)+u(3)+u(4))*p.IR*x(2)...
+(p.b*p.l*(u(3)^2-u(1)^2)))/p.Iyy; %theta_dot
x(6); %ksi
(x(4)*x(2)*(p.Ixx-p.Iyy)+(p.d*(u(1)^2+u(3)^2-u(2)^2-u(4)^2)))/p.Izz; %ksi_dot
x(8); %X
((p.b*(u(1)^2+u(2)^2+u(3)^2+u(4)^2))*(sin(x(1))*sin(x(5))...
+cos(x(1))*sin(x(3))*cos(x(5))))/p.mass; %X_dot
x(10); %Y
((p.b*(u(1)^2+u(2)^2+u(3)^2+u(4)^2))*(cos(x(1))*sin(x(3))*sin(x(5))...
-sin(x(1))*cos(x(5))))/p.mass; %Y_dot
x(12); %Z
((p.b*(u(1)^2+u(2)^2+u(3)^2+u(4)^2))*(cos(x(1))*cos(x(3)))-p.mass*p.g)/p.mass]'; %Z_dot
end

采纳的回答

Jim Riggs
Jim Riggs 2019-6-25
编辑:Jim Riggs 2019-6-25
In the calculation of xdot I see subscripted references for x (up to 12) and u (up to 4).
You should check the size of x and u in the function that is calling "mathmodel" and make sure that x and u have the propper dimensions -> x(12) and u(4)
  1 个评论
pozmogov
pozmogov 2019-7-1
Thank you for the answer! The problem has been solved by specifying the tolerances of the ODE solver and by proper setting the xmeasure and u dimencions (row/column vector)
tol_opt = 1e-6;
opt_option = 0;
type = 'differential equation';
atol_ode_real = 1e-8;
rtol_ode_real = 1e-8;
atol_ode_sim = atol_ode_real;
rtol_ode_sim = rtol

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MPC Design 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by