function demoEulerPlot(h,y0,tn)
% demoEulerPlot  Use odeEuler to solve dy/dt = t - 2*y;  y(0) = 1
%
% Synopsis:  demoEulerPlot
%            demoEulerPlot(h)
%            demoEulerPlot(h,y0)
%            demoEulerPlot(h,y0,tn)
%
% Input: h = (optional) stepsize.  Default:  h=0.2
%        y0 = (optional) initial condition, y(t=0). Default:  y0 = 1
%        tn = (optional) end of time interval.  Default: tn = 2
%
% Output:  Plot comparing numerical and analytical solution, and a
%          value of the global discretization error

if nargin<1, h = 0.2;   end
if nargin<2, y0 = 1.0;  end
if nargin<3, tn = 2.0;  end

   % -- Embedded function to define the right hand side of the ode
   function dydt = rhs(t,y)
       dydt = t - 2*y;
   end

% -- Numerical solution with Euler's method
[t,y] = odeEuler( @rhs, tn, h, y0 );

% -- Compute the exact solution.  Use anonymous function so that yexact
%    can be defined once, but used in two places
yexact = @(t) ( 2*t - 1 + 5*exp(-2*t) )/4;
err = norm( y - yexact(t), Inf);
fprintf('\nh = %7.4f   Max error = %12.4e\n',h,err)

% -- Plot numerical solution and smooth version of exact solution 
te = linspace(min(t),max(t));
ye = yexact(te);
plot(t,y,'o',te,ye,'r--');  xlabel('t');  ylabel('y(t)');  ylim([0 1]);
legend(sprintf('odeEuler, h = %g',h),'Exact','Location','northeast')

end