function approx_bernstein_test ( )

%*****************************************************************************80
%
%% approx_bernstein_test() tests approx_bernstein().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    09 August 2019
%
%  Author:
%
%    John Burkardt
%
  addpath ( '../approx_bernstein' );

  timestamp ( );
  fprintf ( 1, '\n' );
  fprintf ( 1, 'approx_bernstein_test():\n' );
  fprintf ( 1, '  MATLAB/Octave version %s\n', version ( ) );
  fprintf ( 1, '  Test approx_bernstein().\n' );

  a = 0.0;
  b = 1.0;
  for n = [ 5, 11, 31 ]
    [ xp, yp, maxerr ] = approx_bernstein ( 'abs(x-0.5)', a, b, n );
    clf ( );
    hold ( 'on' );
    fp = abs ( xp - 0.5 );
    plot ( xp, fp, 'b-', 'linewidth', 3 );
    plot ( xp, yp, 'r-', 'linewidth', 3 );
    label = sprintf ( '%d-point Bernstein Approximation', n );
    title ( label, 'fontsize', 16 );
    grid ( 'on' );
    hold ( 'off' )
    pause ( 4.0 )
  end

  a = 0.0;
  b = 2.0;

  m = 101;
  xp = linspace ( a, b, m );
  xp = xp';
  fp = humps_fun ( xp );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  N  Maxerr\n' );
  fprintf ( 1, '\n' );
  for n = 1 : 20
    [ xp, yp, maxerr ] = approx_bernstein ( 'humps_fun(x)', a, b, n );
    fprintf ( '  %2d  %14.6g\n', n, maxerr );
  end

  for n = [ 1, 3, 5, 9, 17, 33, 65, 129 ]
    [ xp, yp, maxerr ] = approx_bernstein ( 'humps_fun(x)', a, b, n );
    clf ( );
    hold ( 'on' );
    plot ( xp, fp, 'b-', 'linewidth', 3 );
    plot ( xp, yp, 'r-', 'linewidth', 3 );
    label = sprintf ( '%d-point Bernstein Approximation', n );
    title ( label, 'fontsize', 16 );
    grid ( 'on' );
    hold ( 'off' )
    pause ( 4.0 )
  end

  filename = 'humps_bernstein.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'approx_bernstein_test():\n' );
  fprintf ( 1, '  Normal end of execution.\n' );
  timestamp ( );

  rmpath ( '../approx_bernstein' );

  return
end
function timestamp ( )

%*****************************************************************************80
%
%% timestamp() prints the current YMDHMS date as a timestamp.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    14 February 2003
%
%  Author:
%
%    John Burkardt
%
  t = now;
  c = datevec ( t );
  s = datestr ( c, 0 );
  fprintf ( 1, '%s\n', s );

  return
end

