Problems with code / function, microscopic traffic modeling

조회 수: 17 (최근 30일)
Antonio Spiere
Antonio Spiere 2020년 10월 12일
편집: Antonio Spiere 2020년 10월 12일
I want to setup an IDM model. I have the following code, but it won`t work. It should handle a variable amount of cars and with different car lengths L. Has anyone a solution for this? here are the mathematical expressions from (https://www.researchgate.net/publication/323400960_Comparison_of_Vehicle_Dynamics_of_Microscopic_Car_Following_Models_Optimal_Velocity_and_Intelligent_Driver_Model):
function idm_new
% Zeit, Geschwindigkeit und Position des ersten Fahrzeugs
%zeit_Vektor = 1:1:60;
simulationtime = 60; % in Sekunden
vel_first = (35/3.6);
numberofcars = 3;
% X entspricht Wegstrecke
% Linearer Verlauf der Geschwindigkeit - Ort, gleiche Beschleunigung
X = zeros(simulationtime,1);
for i = 1:1:simulationtime+1
X(i) = vel_first * (i-1);
time_vector(i) = (i-1);
velocity_vector (i) = [vel_first];
distance_vector (i) = X(i);
end
time_vector = time_vector.';
velocity_vector = velocity_vector.';
distance_vector = distance_vector.';
initial_values = zeros(numberofcars,1);
for i = 1:numberofcars
initial_values(i) = initial_values(i) + 2*i;
end
% System Loesung
Zeitspanne=0:.001:simulationtime;
[Th,Y] = ode45( @(Zeit,y)idm(Zeit,y,numberofcars,distance_vector,time_vector,velocity_vector),Zeitspanne,initial_values);
% Diagramm
figure(1);
hold on;
name_cell = {};
name_cell{1} = ['Car ' num2str(0) ];
for k = 1:numberofcars
plot(Th,Y(:,k),'Color',rand(1,3),'LineWidth',.5*k)
name_cell{k+1} = ['Car ' num2str(k) ];
end
function dy = idm(Zeit,y,numberofcars,distance_vector,time_vector,velocity_vector)
dy = zeros(numberofcars,1);
% Parameter
a = 1.0;
b = 1.5;
delta = 4;
T = 1.0;
L = [4.5,3.0, 12.4];
s_0 = 2.0;
v_0 = 15;
Term = 1/(2*sqrt(a*b));
% first car
%x_0 =
distance_interp = interp1(time_vector, distance_vector, Zeit);
velocity_interp = interp1(time_vector, velocity_vector, Zeit);
% calculate Delta_v for the first car
Delta_v(1) = y(numberofcars+1)-velocity_interp;
% calculate s
s(1) = distance_interp-y(1) - L(1);
% Desired distance to the first vehicle
s_stern(1) = s_0 + max(0,y(numberofcars)*T + y(numberofcars)*Delta_v(1)*Term);
% Folgefahrzeuge
for i = 2:numberofcars
Delta_v(i) = y(numberofcars+i)-y(numberofcars+i-1);
s(i) = y(i-1)-y(i) - L(i);
s_star(i) = s0 + max(0,y(numberofcars+i)*T+y(numberofcars+i)*Delta_v(i)*Term);
end
for i=1:numberofcars
dy(i) = y(i+numberofcars);
end
for i=1:numberofcars
dy(i+numberofcars) = a*(1 - (y(i+numberofcars)/v_0).^delta - (s_star(i)/s(i)).^2);
end
end
end

답변 (0개)

카테고리

Help CenterFile Exchange에서 Historical Contests에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by