MATLAB Answers

Index exceeds the number of array elements (1).

2 views (last 30 days)
Vincent Lau
Vincent Lau on 27 Oct 2020
Edited: Cris LaPierre on 27 Oct 2020
Error in NLP_forlooooppiiee (line 80)
tau(k) = floor ( [(C_ud - q_ud(k)) * l_veh / (N_ud * v_ud*c)]);
E1 = 10;
E2 = 4;
E3 = 2;
c = (60/3600); %hr
N_ud = 3;
v_ud = 50; % km/hr
l_veh = (7/1000); %km
l_ud = 1; % km
beta_udo1 = 0.33;
beta_udo2 = 0.34;
beta_udo3 = 0.33;
mu_udo1 = 1600; %veh/hr
mu_udo2 = 1800;
mu_udo3 = 1500;
C_ud = N_ud * l_ud / l_veh;
n_ud0 = 0;
%Parameters link o1-d
N_o1d = 3;
v_o1d = 60;
l_veh = 7;
l_o1d = 1000;
beta_o1du = 0.33;
beta_o1do2 = 0.33;
beta_o1do3 = 0.34;
mu_o1du = 1600;
mu_o1do3 = 1800;
mu_o1do2 = 1500;
for k = 1:60
%initial values
q_udo1(1) = 0;
q_udo2(1) = 0;
q_udo3(1) = 0;
q_ud(1) = 0;
n_ud(1) = 0;
%g_d(k)
g_d(k) = (30/3600);
%a_enter_ud
if k <= 20
a_enter_ud(k) = 1800 + 10*E1;
end
if k > 20 && k<= 40
a_enter_ud(k) = 2100 + 10*E2;
end
if k > 40
a_enter_ud(k) = 2300 + 10*E3;
end
%C_do1
if k <= 20
C_do1(k)= 40 + E1;
end
if k > 20 && k<= 35
C_do1(k) = 40 + E1 - 2 * (k -20);
end
if k>35 && k<=45
C_do1(k) = 10+E1;
end
if k>45
C_do1(k) = 10 + E1 + 2*(k-45);
end
%C_do2
C_do2(k) = C_do1(k) - E2;
%C_do3
if k <= 30
C_do3(k) = 30 - E3;
end
if k>30
C_do3(k) = 30 + E3;
end
%tau(k)
tau(k) = floor ( (C_ud - q_ud(k)) * l_veh / (N_ud * v_ud*c) );
%gamma(k)
gamma(k) = mod(( (C_ud - q_ud(k)) * l_veh / (N_ud * v_ud)),c);
%k-tau -- zorgt ervoor dat er geen negatieve index komt
z(k) = k - tau(k);
if z(k) <= 0
z(k) = 1;
end
%k-tau-1 zorgen ervoor dat er geen negatieve index komt
e(k) = k - tau(k) - 1;
if e(k) <=0
e(k) = 1;
end
%a_arriv_ud
a_arriv_ud(k) = ((c-gamma(k))/c * a_enter_ud(z(k))) + (gamma(k)/c * a_enter_ud(e(k)));
%a_arriv_udo
a_arriv_udo1(k) = beta_udo1 * a_arriv_ud(k);
a_arriv_udo2(k) = beta_udo2 * a_arriv_ud(k);
a_arriv_udo3(k) = beta_udo3 * a_arriv_ud(k);
%a_leave_udo1
a_leave_udo1(k) = min([mu_udo1 * g_d(k)/c, (q_udo1(k)/c) + a_arriv_udo1(k), C_do1(k)/c]);
a_leave_udo2(k) = min([mu_udo2 * g_d(k)/c, (q_udo2(k)/c) + a_arriv_udo2(k), C_do2(k)/c]);
a_leave_udo3(k) = min([mu_udo3 * g_d(k)/c, (q_udo3(k)/c) + a_arriv_udo3(k), C_do3(k)/c]);
%q_udo(k+1)
q_udo1(k+1) = q_udo1(k) + c*(a_arriv_udo1(k) - a_leave_udo1(k));
q_udo2(k+1) = q_udo2(k) + c*(a_arriv_udo2(k) - a_leave_udo2(k));
q_udo3(k+1) = q_udo3(k) + c*(a_arriv_udo3(k) - a_leave_udo3(k));
%q_ud(k)
q_ud(k) = q_udo1(k) + q_udo2(k) + q_udo3(k);
%a_leave_ud
a_leave_ud(k) = a_leave_udo1(k) + a_leave_udo2(k) + a_leave_udo3(k);
%n_ud(k+1)
n_ud(k+1) = n_ud(k) + c *(a_enter_ud(k) - a_leave_ud(k));
end

  0 Comments

Sign in to comment.

Answers (1)

Cris LaPierre
Cris LaPierre on 27 Oct 2020
Edited: Cris LaPierre on 27 Oct 2020
I suggest looking at one of these posts.

  0 Comments

Sign in to comment.

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by