%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Driver for bvp1d which solves
%
%       u''(x) = f(x)  on  x = [0,1]; u(0) = u_L, u(1) = u_R
%
% using second-order finite difference techniques and sparse matrix
% operations.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

more off;

colours = {'*r' '+g' 'ob' 'm' 'k' 'c' 'r' 'g' 'b' 'm' 'c' 'r'};

levelmin = 7; levelmax = 13;

clf;
hold on;
for level = levelmin : levelmax
   [x{level}, u{level}, uexact{level}, e{level}] = bvp1d(level);
   plot(x{level}, u{level}, colours{level-levelmin+1});
   fprintf('Plotting level %d solution\n', level);
   input('Type ENTER to continue: ');
end

clf;
hold on;
for level = levelmin : levelmax - 1
   xl   = x{level};
   ul   = u{level};
   ulp1 = u{level+1};
   ulp1 = ulp1(1:2:length(ulp1));
   du   = 4^(level - levelmin) * (ul - ulp1);
   fprintf('Plotting scaled deviations level %d - level %d\n', ...
      level, level+1);
   plot(xl, du, colours{level-levelmin+1});
   input('Type ENTER to continue: ');
end
