L = 1; % length of road
% Set # of cars
N = 100;
xc = % start cars in random positions
xc = sort(xc);
CarInFront = [2:N 1];
allds = [];
allvs = [];
d = zeros(N,1);
dt = 1e-2;
Tf = 30;
stopcount = Tf/dt;
vels = zeros(N,1);
% Define dmin, dmax, vmax
% Test plot of v
dtest = linspace(0,2*dmax,100);
vtest = 0*dtest;
for iD=1:length(dtest)
    vtest(iD)=v(dtest(iD),dmin,dmax,vmax);
end
for iT=1:stopcount
    % Calculate velocity of each car (fill in the array vels)
    for iCar=1:N
    end
    % Update the car positions
    % Plot them in circle
    theta = mod(xc,L)/L*2*pi;
    plot(cos(theta),sin(theta),'o')
    hold on
    tpl = linspace(0,2*pi,1000);
    plot(cos(tpl),sin(tpl))
    drawnow
    hold off
    % Keep track of distance between car and that in front
    allds = [allds d];
    allvs = [allvs vels];
end
        

function vv = v(d,dmin,dmax,vmax)
    if (d < dmin)
      vv=0;
    elseif (d < dmax) 
      vv=vmax*log(d/dmin)/log(dmax/dmin);
    else
      vv=vmax;
    end
end