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 commentaire

Khalilullah Mayar
Khalilullah Mayar le 24 Sep 2019
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

Connectez-vous pour commenter.

 Réponse acceptée

Ni Tao
Ni Tao le 1 Oct 2019
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 commentaire

Anirudh
Anirudh le 3 Jan 2023
If I were to do this in Simulink, how can I go about it?

Connectez-vous pour commenter.

Plus de réponses (1)

Mouncef
Mouncef le 10 Juin 2023

0 votes

can you explain this simulation ?

Catégories

En savoir plus sur Programming dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by