%
%  lect18.m -- fully-discrete one-way wave
%
%- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

movie = 1;

%  parameters

global c dx

N =  160;  L =   pi;  dx = 2*L/N;
M =  8*N; T = 2*pi;  dt = T/M;

%  set grids & coefficients

xg = 0:dx:2*L-dx;  x = [xg 2*L];
tg = 0:dt:T;
lambda = dt/dx/2;

c  = 1.0 + 0.0*sin(xg);
f  = 0.0;

%  row vector of IVs

IVs  = [exp(4*sin(xg) - 4)];

%  PDE solve with operation count

disp(' ')
disp(' fully-discrete one-way wave')
disp(' ')
figure(1);  clf 
flops(0);

u = IVs;  
plot(xg,u,'r');  hold on;  plot(xg,u,'kx');
axis([0 2*pi 0 1.25]);

for k=1:M

% centered diff in space
   u = u - lambda*c.*([u(2:end) u(1)] - [u(end) u(1:end-1)]) + f;

% upwind diff in space
%   u = u - 2*lambda*c.*(u - [u(end) u(1:end-1)]) + f;

% interval plotting
   if (mod(k,M/8)==0);  plot(xg,u,'k');  end
end

plot(xg,u,'b');  hold on;  plot(xg,u,'kx');

opcount = flops;  
disp(' ');  disp([' flops = ' num2str(opcount)]);  disp(' ')
xlabel('\bf x-axis');  ylabel('\bf u-axis')
title('\bf one-way wave (c=1,f=0)')


