Clear Filters
Clear Filters

subscript indices must either be real positive integers or logicals. matlab ode15s

1 view (last 30 days)
Hi everyone!
I'm solving a DAE system of equations: a previous version of 19 equations worked, but now I'm trying to get my model more complicated by deleting 2 equations and adding 4 new ones (thus assembling 21 equations). The new mass matrix M indicates where the differential equations are located. Apparently there's an error in the ode solver, as I get the error message before Matlab even starts to compute the solution, but I can't see it!
tic
[t,y] = ode15s(@(t,y) longitudinale_puro_nomi_veri(t,y,momento_1,momento_2,...
J_1,J_2,delta_v,delta_v_0,tau_1,tau_2,delta_1,delta_2,a_1,a_2,m,J_z,J_zx,...
dati_pacejka_r,dati_pacejka_f,R_1,R_2,g,h,Cz_1,Cz_2,inizio_rampa,fine_rampa,...
m_1,Z_statico_1,Z_statico_2,theta_11,theta_12,theta_21,theta_22),tspan,y0_nomi_veri,options);
toc
The error message is: Subscript indices must either be real positive integers or logicals
Here's the function where all the equations are written: (the second line in the error message addresses me to the first line of vector out)
function out=longitudinale_puro(t,y,momento_1,momento_2,J_1,J_2,...
delta_v,delta_v_0,tau_1,tau_2,delta_1,delta_2,a_1,a_2,m,J_z,J_zx,...
dati_pacejka_r,dati_pacejka_f,R_1,R_2,g,h,Cz_1,Cz_2,...
inizio_rampa,fine_rampa,m_1,Z_statico_1,Z_statico_2,...
theta_11,theta_12,theta_21,theta_22)
delta_1=tau_1*delta_v; % Angoli alle ruote
delta_2=tau_2*delta_v;
momento_1=4*t;
% 21 Unknowns:
alfa_1=y(1);
alfa_2=y(2);
F_y_1=y(3);
F_y_2=y(4);
F_x_1=y(5);
F_x_2=y(6);
v=y(7);
r=y(8);
u=y(9);
F_z_1=y(10);
F_z_12=y(11);
F_z_2=y(12);
F_z_22=y(13);
epsilon_1=y(14);
epsilon_2=y(15);
omega_1=y(16);
omega_2=y(17);
schiacciamento_1=y(18);
schiacciamento_2=y(19);
R_pr_1=y(20);
R_pr_2=y(21);
% Equations
out=[-alfa_1+delta_1-(v+r*a_1)/u; % Congruenza: deriva alfa_1
-alfa_2+delta_2-(v-r*a_2)/u; % Congruenza: deriva alfa_2
-F_y_1+pacejka('Fy0',F_z_1,0,-alfa_1*180/pi,-epsilon_1,dati_pacejka_f); % Legame costitutivo F_y_1
-F_y_2+pacejka('Fy0',F_z_2,0,-alfa_2*180/pi,-epsilon_2,dati_pacejka_r); % Legame costitutivo F_y_2
-F_x_1+pacejka('Fx0',F_z_1,0,-alfa_1*180/pi,-epsilon_1,dati_pacejka_f); % Legame costitutivo F_x_1
-F_x_2+pacejka('Fx0',F_z_2,0,-alfa_2*180/pi,-epsilon_2,dati_pacejka_r); % Legame costitutivo F_x_2
(F_y_1+F_y_2)/m-u*r; % Equilibrio trasversale
(F_y_1*a_1-F_y_2*a_2)/J_z; % Equilibrio imbardata
(F_x_1+F_x_2-F_y_1*delta_1)/m+v*r; % Equilibrio longitudinale
-F_z_1+Z_statico_1-theta_11*(F_y_1+F_y_2)-theta_12(F_y_1*a_1-F_y_2*a_2)-(F_x_1+F_x_2-F_y_1*delta_1)*h/l;
-F_z_12+Z_statico_1+theta_11*(F_y_1+F_y_2)+theta_12(F_y_1*a_1-F_y_2*a_2)-(F_x_1+F_x_2-F_y_1*delta_1)*h/l;
-F_z_2+Z_statico_2-theta_21*(F_y_1+F_y_2)-theta_22(F_y_1*a_1-F_y_2*a_2)+(F_x_1+F_x_2-F_y_1*delta_1)*h/l;
-F_z_22+Z_statico_2+theta_21*(F_y_1+F_y_2)+theta_22(F_y_1*a_1-F_y_2*a_2)+(F_x_1+F_x_2-F_y_1*delta_1)*h/l;
-epsilon_1+(u-R_pr_1*omega_1)/u; % Congruenza: slip x_1
-epsilon_2+(u-R_pr_2*omega_2)/u; % Congruenza: slip x_2
(momento_1-F_x_1*(R_1-schiacciamento_1))/J_1; % Bilancio ruota 1
(momento_2-F_x_2*(R_2-schiacciamento_2))/J_2; % Bilancio ruota 2
-schiacciamento_1+F_z_1/Cz_1; % Schiacciamento 1
-schiacciamento_2+F_z_2/Cz_2; % Schiacciamento 2
-R_pr_1+R_1-schiacciamento_1/3; % Raggio puro rotolamento 1
-R_pr_2+R_2-schiacciamento_2/3]; % Raggio puro rotolamento 2

Accepted Answer

John D'Errico
John D'Errico on 27 Mar 2017
Is theta12 a function? A vector? Is it a scalar? MATLAB appears to think that theta12 is a variable, because of the error message.
If it is a scalar, then why are you using it as if you are indexing into it? :)
-F_z_1+Z_statico_1-theta_11*(F_y_1+F_y_2)-theta_12(F_y_1*a_1-F_y_2*a_2)-(F_x_1+F_x_2-F_y_1*delta_1)*h/l;
With no operator to follow the variable, only a paren, MATLAB assumes that theta12 MUST be a vector. It then evaluates (F_y_1*a_1-F_y_2*a_2) as an index into that variable, which I am sure must fail.
The same applies to theta22.
  2 Comments
Francesco Ardia
Francesco Ardia on 27 Mar 2017
Thanks John! Both theta_12 and theta_22 are coefficients: I had forgetten the * multiplication sign! Silly mistake, thanks for looking across the code and helping me!
John D'Errico
John D'Errico on 28 Mar 2017
Whenever I see this kind of error in long computations, that is the place to look. I just had to scan down through the code until I saw a left parens that was not preceded by an operator.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!