Index exceeds the number of array elements (1)
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
pozmogov
am 24 Jun. 2019
Kommentiert: pozmogov
am 1 Jul. 2019
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
0 Kommentare
Akzeptierte Antwort
Jim Riggs
am 25 Jun. 2019
Bearbeitet: Jim Riggs
am 25 Jun. 2019
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)
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrix Computations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!