Asked by Khalilullah Mayar
on 18 Sep 2019

Hi everyone,

Can someone help with modeling the following Gazis–Herman–Rothery (GHR) model in Matlab:

I have the data for the leader car stored in mytrafficdata5 files as folllows:

I have edited the following code from a similar model (OVM). A difference here is the time lag (tau=1 sec) between the leader and follower vehicles. I was unable to run the code and wonder if someone can help to fix it as per the given model. Thanks

function basic_ghr

% y is velocity

% t is time

% Using interpolant for distance

close all;

load mytrafficdata5;

time_vector = Time_t;

init_speed = 0;

dist_vector = Distance_n;

vel_vector = Velocity_n

% dist_interp = interp1(time_vector, dist_vector,);

% vel_interp = interp1(time_vector, vel_vector,);

F_time = time_vector(end);

[T,Y] = ...

ode45( @(t,y) ...

some_system(t,y,time_vector,dist_vector),[0,F_time],init_speed);

plot(T,Y(:,1),'b-',time_vector,vel_vector,'r--')

legend('By GHR','Real Velocity')

title('Comparisam of velocity with time bewteen Real Data Set VS. GHR model')

xlabel('Time')

ylabel('Velocity (m/sec)')

function dy = some_system(t,y,time_vector,dist_vector, vel_vector)

c = 125;

m = 0.2;

l = 1.6;

%%%%%%%%%%%%%%%%%

% Using interpolant for distance and velocity

dist_interp = interp1(time_vector, dist_vector, t);

vel_interp = interp1(time_vector, vel_vector, t);

dy = c *((y)^m)/(vel_interp)^l))*(dist_interp);

Answer by Stephan
on 18 Sep 2019

Edited by Stephan
on 18 Sep 2019

Accepted Answer

This code runs, but still has a problem:

load mytrafficdata5;

basic_ghr(Distance_n,Time_t,Velocity_n)

function basic_ghr(Distance_n,Time_t,Velocity_n)

% y is velocity

% t is time

% Using interpolant for distance

close all;

time_vector = Time_t;

init_speed = 0;

dist_vector = Distance_n;

vel_vector = Velocity_n;

% dist_interp = interp1(time_vector, dist_vector,);

% vel_interp = interp1(time_vector, vel_vector,);

F_time = time_vector(end);

[T,Y] = ode45(@(t,y)some_system(t,y),[0,F_time],init_speed);

plot(T,Y(:,1),'b-',time_vector,vel_vector,'r--')

legend('By GHR','Real Velocity')

title('Comparisam of velocity with time bewteen Real Data Set VS. GHR model')

xlabel('Time')

ylabel('Velocity (m/sec)')

function dy = some_system(t,y)

c = 125;

m = 0.2;

l = 1.6;

%%%%%%%%%%%%%%%%%

% Using interpolant for distance and velocity

dist_interp = interp1(time_vector, dist_vector, t);

vel_interp = interp1(time_vector, vel_vector, t);

dy = c *(y^m)/(vel_interp)^l*(dist_interp);

end

end

The result of Y(:,1) is a vector of one zero and then all NaN - so you will have to check your equation.

Stephan
on 19 Sep 2019

You are using the wrong dataset i guess. I attached a modified .mat-file taking the delta-values for X and V from your Excel file. Those are introduced to the function as S and V. This appears to be more logic to me if i look at your equation:

load mytrafficdata5;

basic_ghr(S,Time_t,V,Distance_n,Velocity_n)

function basic_ghr(S,Time_t,V,Distance_n,Velocity_n)

% y is velocity

% t is time

% Using interpolant for distance

close all;

time_vector = Time_t;

init_speed = 0.2;

dist_vector = S;

vel_vector = V;

% dist_interp = interp1(time_vector, dist_vector,);

% vel_interp = interp1(time_vector, vel_vector,);

F_time = time_vector(end);

[T,Y] = ode45(@(t,y)some_system(t,y),[0,F_time],init_speed);

plot(T,Y(:,1),'b-',time_vector,Velocity_n,'r--')

legend('By GHR','Real Velocity')

title('Comparisam of velocity with time bewteen Real Data Set VS. GHR model')

xlabel('Time')

ylabel('Velocity (m/sec)')

legend('Location','best')

function dy = some_system(t,y)

c = 125;

m = 0.2;

l = 1.6;

%%%%%%%%%%%%%%%%%

% Using interpolant for distance and velocity

dist_interp = interp1(time_vector, dist_vector, t);

vel_interp = interp1(time_vector, vel_vector, t);

dy = c *(y^m)/(dist_interp)^l*(vel_interp);

end

end

With this values and the initial value of 0.2 m/s it appears to be correct:

I can only repeat myself: It is not a Matlab problem, but a problem of a correct equation and the usage of the correct data...

If my help was useful, dont miss to accept this answer ;-)

Khalilullah Mayar
on 23 Sep 2019

Thanks Stephan, that was helpul.

Khalilullah Mayar
on 25 Sep 2019

Hi Stephan,

Any comment on this would be appreciated:

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 2 Comments

## Stephan (view profile)

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/480904-ode45-modeling-ghr-microspic-car-following-model#comment_747162

## Khalilullah Mayar (view profile)

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/480904-ode45-modeling-ghr-microspic-car-following-model#comment_747192

Sign in to comment.