function stirling_estimate_test ( )

%*****************************************************************************80
%
%% stirling_estimate_test() tests stirling_estimate(). 
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    28 May 2022
%
%  Author:
%
%    Paul Nahin
%
%  Reference:
%
%    Paul Nahin,
%    Dueling Idiots and Other Probability Puzzlers,
%    Princeton, 2012,
%    ISBN: 978-0691155005.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'stirling_estimate_test():\n' );
  fprintf ( 1, '  stirling_estimate() uses Stirling''s approximation\n' );
  fprintf ( 1, '  to estimate log(n!).\n' );

  for n = 1 : 150
    f(n) = gammaln ( n + 1 );
    s(n) = stirling_estimate ( n );
  end
%
%  Graphics.
%
  clf ( );

  subplot ( 1, 2, 1 );
  semilogy ( f - s, 'linewidth', 3 );
  grid ( 'on' );
  xlabel ( 'n' );
  ylabel ( 'Absolute Error' );
  title ( 'log(n!) - Stirling' );

  subplot ( 1, 2, 2 );
  plot ( f ./ s, 'linewidth', 3 );
  grid ( 'on' );
  xlabel ( 'n' );
  ylabel ( 'Relative Error' );
  title ( 'log(n!) / Stirling' );

  filename = 'stirling_estimate.png';
  print ( '-dpng', filename );
  fprintf ( '  Graphics saved as "%s"\n', filename );

  return
end
