a = .8;
t_end=.5;
N=70+1;
J=25;

tau = t_end /J;
h = 2.0 / (N-1);
CFL = a * tau/h

%%%

x = [-1.0:h:1.0];
u0 = (x+1.6).*( x<-0.7 ) ...
	+ (0.2-x).*( abs(x+.5)<0.2 ) ...
	+ 0.5 .*( abs(x+.15)<0.15 ) ...
	+ 0.5*(x-1).*(x-1).*( x>=0 );
U = u0;
UU= u0;

figure(1); clf;
plot(x,u0,'r-', x,U,'o-')
xlim([-1 1]); ylim([-0.1 1.2]);
xlabel('x'); ylabel('u');

pause

% u_t + a u_x = 0
% central difference in space
for t = tau:tau:t_end
	UU(2:N-1) = U(2:N-1) -a*tau/(2.0*h)* ( U(3:N) -U(1:N-2) );
	U = UU;

	plot(x,u0,'r-', x,U,'o-', x+a*t,u0,'g-')
	xlim([-1 1]); ylim([-0.1 1.2]);
	xlabel('x'); ylabel('u');
	drawnow
end
