function mit18086_traffic %MIT18086_TRAFFIC % Solves a traffic model equation by a characteristic % particle method. % 02/2007 by Benjamin Seibold % Feel free to modify for teaching and learning. n = 400; % number of space gridpoints without boundaries dt = 2e-2; % time step tf = 8e-0; % final time nc = 80; % number of cars x = linspace(-12,4,n)'; x0 = x; h = x(2)-x(1); u = f(x); u0 = u; cu = cumsum(u); cu = cu/cu(end); c = interp1(cu,x,linspace(0,1,nc)); for tn = 1:ceil(tf/dt) x = x+dt*(1-2*u); c = c+dt*interp1(x,1-u,c); [mv,mi] = min(diff(x)); while abs(mv)