% plot solution to Burgers' equation u_t + u*u_x = 0 (including 
% the "solution" after the shock).

% f = inline('x.^0', 'x');                  % initial data, t=0
% f = inline('1-4*abs(x)','x');             % initial data, t=0
% f = inline('exp(-1.5*x.^2)', 'x');        % initial data, t=0
 f= inline('-2*x.*exp(-x.^2)', 'x');      % initial data, t=0

 x0 = linspace(-2,2,100);
 t = [0:.05:1.5];

 u = f(x0);
 yax = [min(u)-.1*(max(u)-min(u)) max(u)+.1*(max(u)-min(u))];
 U = []; X = []; T = [];

 stopshock = 0;
 for k=1:length(t)
     figure(1), clf
     xk = f(x0)*t(k)+x0;
     plot(xk, u,'b-','linewidth',2)
     ylim(yax), xlim([min(xk) max(xk)])
     xlabel('$x$','fontsize',16,'interpreter','latex')
     ylabel('$u(x,t)$','fontsize',16,'interpreter','latex')
     title('Burgers'' equation','fontsize',18,'interpreter','latex');
   
   if (min(diff(xk))<=0)&(stopshock),
        break
    else
        X(k,:) = xk;
        U(k,:) = u; 
        T(k,:) = t(k)*ones(size(u));
        pause(0.25)
    end
 end

 figure(2), clf
 plt=waterfall(X,T,U);
 set(plt,'edgecolor','k')       % make the lines black

