IDM Car following microspoic model

14 次查看(过去 30 天)
Hi everyone,
Can someone help why the following code couldn't run? It's an IDM car following microscopic model introduced by the equations and parameters below:
Equations.jpg
load mytrafficdata5;
someidmm(Time_t,Distance_n,Velocity_n)
function someidmm(Time_t,Distance_n,Velocity_n)
% y is velocity
% t is time
% Using interpolant for distance and velocity
close all;
time_vector = Time_t;
init_speed = 0.2;
vel_vector = Velocity_n;
Dist_vector= Distance_n;
F_time = time_vector(end);
figure (1);
[T,Y] = ode45(@(t,y)idm5(t,y),[0,F_time],init_speed);
plot(T,Y(:,1),'b-',time_vector,vel_vector,'r--')
legend('By IDM','Real Velocity')
xlabel('Time')
ylabel('Velocity (m/sec)')
legend('Location','best')
function dy = idm5(t,y)
% parameters
x0_dot =30; % unit is m/sec
delta =4;
a=0.3;
b= 3;
s0=2;
Th=1.5; %time headway=1.5 sec
k = 1/(2*sqrt(a*b));
lc=5;
dist_interp = interp1(time_vector, Dist_vector, t);
vel_interp = interp1(time_vector, vel_vector, t);
xn = dist_interp;
Delta_v = y-vel_interp;
Dis = int(y,[0 F_time]) % integratoin of y (velocity) to get distance
s = xn-Dis - lc;
s_star = s0 + max(0,y*Th + y*Delta_v*k);
%-main system-- %
dy = a*(1 - (y/x0_dot).^delta - (s_star/s).^2);
end
end
Data for the leader car is attached (mytrafficdata5.mat)
Note: I believe there might an issue with the integration line (Dis = int(y,[0 F_time]) % integratoin of y (velocity) to get distance).
  1 个评论
Khalilullah Mayar
Khalilullah Mayar 2019-9-24
Following is an alternative version of the code with some fixings:
load mytrafficdata5;
someidmm(Time_t,Distance_n,Velocity_n)
function someidmm(Time_t,Distance_n,Velocity_n)
% y is distance for follower car
% t is time
% Using interpolant for distance and velocity
close all;
time_vector = Time_t;
y0=[2;2];
tspan=[0 100];
vel_vector = Velocity_n;
Dist_vector= Distance_n;
[t,y] = ode45(@idm8,tspan,y0);
plot(t,y(:,2),'b-',time_vector,vel_vector,'r--')
legend('By IDM','Real Velocity')
xlabel('Time')
ylabel('Velocity (m/sec)')
legend('Location','best')
function dydt = idm8(t,y)
dydt= zeros(2,1)
dydt(1)= y(2);
dydt(2)= a*(1 - (y(2)/x0_dot).^delta - (s_star/s).^2);
% parameters
x0_dot =30; % unit is m/sec
delta =4;
a=0.3;
b= 3;
s0=2;
Th=1.5; %time headway=1.5 sec
k = 1/(2*sqrt(a*b));
lc=5;
dist_interp = interp1(time_vector, Dist_vector, t);
vel_interp = interp1(time_vector, vel_vector, t);
xn = dist_interp;
Delta_v = y(2)-vel_interp;
s = xn-y(1) - lc;
s_star = s0 + max(0,y(2)*Th + y(2)*Delta_v*k);
end
end

请先登录,再进行评论。

采纳的回答

Ni Tao
Ni Tao 2019-10-1
load mytrafficdata5;
someidmm(Time_t,Distance_n,Velocity_n)
function someidmm(Time_t,Distance_n,Velocity_n)
% y is distance for follower car
% t is time
% Using interpolant for distance and velocity
close all;
time_vector = Time_t;
y0=[2;2];
tspan=[0 100];
vel_vector = Velocity_n;
Dist_vector= Distance_n;
[t,y] = ode45(@idm8,tspan,y0);
plot(t,y(:,2),'b-',time_vector,vel_vector,'r--')
legend('By IDM','Real Velocity')
xlabel('Time')
ylabel('Velocity (m/sec)')
legend('Location','best')
function dydt = idm8(t,y)
dydt= zeros(2,1)
dydt(1)= y(2);
a=0.3;
x0_dot =30; % unit is m/sec
delta =4;
b= 3;
s0=2;
Th=1.5; %time headway=1.5 sec
k = 1/(2*sqrt(a*b));
lc=5;
dist_interp = interp1(time_vector, Dist_vector, t);
vel_interp = interp1(time_vector, vel_vector, t);
xn = dist_interp;
Delta_v = y(2)-vel_interp;
s = xn-y(1) - lc;
s_star = s0 + max(0,y(2)*Th + y(2)*Delta_v*k);
dydt(2)= a*(1 - (y(2)/x0_dot).^delta - (s_star/s).^2);
% parameters
end
end

更多回答(1 个)

Mouncef
Mouncef 2023-6-10
can you explain this simulation ?

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by