function eval_exp_simple ( b )

%*****************************************************************************80
%
%% eval_exp_simple() evaluates Taylor polynomials for exp(x) about x = 0.
%
%  Discussion:
%
%    This function evaluates several Taylor polynomials and their errors
%    for increasing degrees.  
%
%    The particular function being approximated is exp(x) on [-b,b].  
%
%  Modified:
%
%    18 August 2022
%
%  Reference:
%
%    Kendall Atkinson, Weimin Han,
%    Elementary Numerical Analysis,
%    Wiley, 2004,
%    ISBN: 0471433373,
%    LC: QA297.A83.2004.
%
%  Input:
%
%    real b: the calculation will be done over the interval [-b,+b].
%

%
%  Initialize.
%
  h = b / 10;
  x = -b:h:b;
  max_deg = 4;
%
% Produce the Taylor coefficients for the function exp(x) when
% expanded about the point a = 0.  The coefficients are stored 
% in the array c, which will have length max_deg+1.
%
  c = ones(max_deg+1,1);
  fact = 1;
  for i = 1:max_deg
    fact = i*fact;
    c(i+1) = 1/fact;
  end
%
%  Calculate the Taylor polynomials
%
  expx = exp(x);
  p1 = polyeval(x,0,c,1);
  p2 = polyeval(x,0,c,2);
  p3 = polyeval(x,0,c,3);
  p4 = polyeval(x,0,c,4);
%
%  Plot.
%
  clf ( );
  hold ( 'on' );
  plot ( x, expx, 'linewidth', 3 );
  plot ( x, p1, 'linewidth', 2 );
  plot ( x, p2, 'linewidth', 2 );
  plot ( x, p3, 'linewidth', 2 );
  plot ( x, p4, 'linewidth', 2 );
  grid ( 'on' );
  xlabel ( '<-- X -->' );
  ylabel ( '<-- Y -->' );
  title ( 'Taylor polynomial approximations to y=exp(x)' );
  legend ( 'exp(x)', 'p1', 'p2', 'p3', 'p4' );
  filename = 'eval_exp_simple.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );
%
%  Calculate the errors in the Taylor polynomials
%
  err1 = expx-p1;
  err2 = expx-p2;
  err3 = expx-p3;
  err4 = expx-p4;

  fprintf ( 1, '\n' );
  fprintf ( 1, 'eval_exp_simple():' )
  fprintf ( 1, '  Taylor series for exp(x) over [%g,%g,]\n', -b, +b );
  fprintf ( 1, '\n' );
  disp('    x       exp(x)      err1          err2          err3          err4')
  [x',expx',err1',err2',err3',err4']

  return
end
