function test_interp_fun_test03 ( )

%*****************************************************************************80
%
%% test_interp_fun_test03() uses equally spaced polynomial interpolation.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    24 August 2011
%
%  Author:
%
%    John Burkardt
%
  max_tab = 21;

  fprintf ( 1, '\n' );
  fprintf ( 1, 'test_interp_fun_test03\n' );
  fprintf ( 1, '  Equally spaced polynomial interpolation.\n' );
  fprintf ( 1, '  Evaluate the function at N equally spaced points.\n' );
  fprintf ( 1, '  Determine the N-1 degre polynomial interpolant.\n' );
  fprintf ( 1, '  Estimate the maximum difference between the function\n' );
  fprintf ( 1, '  and the interpolant.\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.
%
      for i = 1 : n

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

        ytab(i) = p00_fun ( prob, xtab(i) );

      end
%
%  Construct the interpolating polynomial via finite differences.
%
      diftab = data_to_dif ( n, xtab, ytab );
%
%  Now examine the approximation error.
%
      error_max = 0.0;
      imax = 100;

      for i = 0 : imax

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

        ytrue = p00_fun ( prob, x );
        yapprox = dif_val ( n, xtab, diftab, x );
        error_max = max ( error_max, abs ( ytrue - yapprox ) );

      end

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

    end

  end

  return
end
