%% Lax
% Example Lax Method

dx=0.05;
x=[-1.0:dx:4.0];
dt=0.25;
Tf=10;
time=[0:dt:Tf];
N=Tf/dt;
f=zeros(length(x),N+1);
g=f;
u=0.2;
c=u*dt/dx;
f(:,1)=200.*(x-1).*(x>1.0).*(x<=1.5)+200.*(2-x).*(x>1.5).*(x<2.0);
for j=1:N+1;
    for i=2:length(x)-1
        f(i,j+1)=(1/2)*(f(i-1,j)+f(i+1,j))-(c/2)*(g(i+1,j)-g(i-1,j));
        g(i,j+1)=(1/2)*(g(i-1,j)+g(i+1,j))-(c/2)*(f(i+1,j)-f(i-1,j));
    end;
end;
figure(10); imagesc(x,time,f'); axis xy; xlabel('Position (cm)'); ylabel('Time (s)');
title('Lax Method Time Evolution Temp. (C)');
figure(11); plot(x,f(:,1),x,f(:,21),x,f(:,41)); xlabel('Position (cm)'); ylabel('Temp. (C)');
title('Lax Method Wave Equation f');
legend('t=0','t=5','t=10');
figure(12); plot(x,g(:,1),x,g(:,21),x,g(:,41)); xlabel('Position (cm)'); ylabel('Temp. (C)');
title('Lax Method Wave Equation g');
legend('t=0','t=5','t=10');
