function test_interp_fun_test04 ( )

%*****************************************************************************80
%
%% TEST_INTERP_FUN_TEST04 uses Bernstein polynomial approximation on functional problems.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    15 February 2012
%
%  Author:
%
%    John Burkardt
%
  max_tab = 21;

  fprintf ( 1, '\n' );
  fprintf ( 1, 'TEST_INTERP_FUN_TEST04\n' );
  fprintf ( 1, '  Bernstein polynomial approximation.\n' );
  fprintf ( 1, '  Evaluate the function at N equally spaced points.\n' );
  fprintf ( 1, '  Determine the N-1 degree Bernstein polynomial approximant.\n' );
  fprintf ( 1, '  Estimate the maximum difference between the function\n' );
  fprintf ( 1, '  and the approximant.\n' );

  prob_num = p00_prob_num ( );

  for prob = 1 : prob_num

    title = p00_title ( prob );
    [ a, b ] = p00_lim ( prob );

    fprintf ( 1, '\n' );
    fprintf ( 1, '  Problem %d\n', prob );
    fprintf ( 1, '  %s\n', title );
    fprintf ( 1, '\n' );
    fprintf ( 1, '     N   Max ||Error||\n' );
    fprintf ( 1, '\n' );

    for n = 1 : 4 : max_tab
%
%  Evaluate the function at N equally spaced points.
%
      xdata = zeros ( n, 1 );
      ydata = zeros ( n, 1 );

      for i = 1 : n

        if ( n == 1 )
          xdata(i) = 0.5 * ( a + b );
        else
          xdata(i) = ( ( n - i     ) * a    ...
                     + (     i - 1 ) * b  ) ...
                     / ( n     - 1 );
        end

        ydata(i) = p00_fun ( prob, xdata(i) );

      end
%
%  Now examine the approximation error.
%
      error_max = 0.0;
      imax = 100;

      for i = 0 : imax

        if ( imax == 0 )
          xval = 0.5 * ( a + b );
        else
          xval = ( ( imax - i ) * a    ...
                 + (        i ) * b  ) ...
                 / ( imax     );
        end

        ytrue = p00_fun ( prob, xval );

        yval = bpab_approx ( n - 1, a, b, ydata, xval );

        error_max = max ( error_max, abs ( ytrue - yval ) );

      end

      fprintf ( 1, '  %4d  %14g\n', n, error_max );

    end

  end

  return
end
