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 CenterFile Exchange에서 Matrix Computations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by