Index exceeds the number of array elements (1)

1 回表示 (過去 30 日間)
pozmogov
pozmogov 2019 年 6 月 24 日
コメント済み: pozmogov 2019 年 7 月 1 日
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 Center および File ExchangeMPC Design についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by