%
%  w02wave.m - characteristic solution (djm: 16 sept 2010)
%   - define initial data in w02waveF.m

demo = 2;

%  coordinates & parameters
cc = 1;
dt = 1/8;
dx = cc*dt;

xL = 8;  xx = -xL:dx:xL;

Tf = 4;

switch demo
    case{1}
       func = @w02waveF1;
       lims = [-xL xL -0.1 2.2];
    case{2}
       func = @w02waveF2;
       lims = [-xL xL -1.1 1.1];
end

figure(10);  clf;
for tt = -Tf:dt:Tf
    u1 = feval(func,xx+cc*tt,1);
    u2 = feval(func,xx-cc*tt,2);
    
    subplot(2,1,1)
    plot(xx,u1+u2,'r');  hold on
    plot(xx,u1+u2,'k.');
    axis(lims)
    hold off
    title(['\bf u(x,t) at t = ' num2str(tt)])
    xlabel('\bf x-axis')
    
    subplot(2,1,2)
    plot(xx,u1,'c');  hold on    
    plot(xx,u2,'m');
    axis(lims)
    hold off
    xlabel('\bf x-axis')
    
    drawnow
    pause(0.2)
end