function smoothingdemo(method)
%SMOOTHINGDEMO Graphical demonstration of the smoothing property
%
% Shows the action of Gauss-Seidel or Jacobi iteration for the 3-pt
% difference operator for the 1D Dirichlet problem, acting on the
% highest frequency mode of a uniform mesh.
%
% Call with no arguments to get Gauss-Seidel, or with an argument to get Jacobi.
%
% Douglas N. Arnold, 2011-10-14

clf
n = 20;
x = (0:n)/n;
u = sin((n-1)*pi*x);
%u = sin(pi*x);
plot(x,u,'o-','linewidth',3)
axis([0,1,-1,1])

if nargin == 0  % Gauss-Seidel
  for iter = 1:10
    for i = 2:n
      pause
      u(i) = (u(i-1)+u(i+1))/2 ;
      plot(x,u,'o-','linewidth',3)
      axis([0,1,-1,1])
    end
  end
else % Jacobi
  for iter = 1:10
    uold = u;
    for i = 2:n
      pause
      clf
      plot(x,uold,'ro-','linewidth',1)
      hold on
      u(i) = (uold(i-1)+uold(i+1))/2 ;
      plot(x,u,'o-','linewidth',3)
      axis([0,1,-1,1])
    end
  end
end