function glpairs_test ( )

%*****************************************************************************80
%
%% GLPAIRS_TEST tests GLPAIRS.
%
%  Discussion:
%
%    Test the numerical integration of cos(1000 x) over the range [-1,1]
%    for varying number of Gauss-Legendre quadrature nodes l.
%    The fact that only twelve digits of accuracy are obtained is due to the 
%    condition number of the summation.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    06 January 2016
%
%  Author:
%
%    Original C++ version by Ignace Bogaert.
%    MATLAB version by John Burkardt.
%
%  Reference:
%
%    Ignace Bogaert,
%    Iteration-free computation of Gauss-Legendre quadrature nodes and weights,
%    SIAM Journal on Scientific Computing,
%    Volume 36, Number 3, 2014, pages A1008-1026.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'GLPAIRS_TEST:\n' );
  fprintf ( 1, '  integral ( -1 <= x <= 1 ) cos(1000 x) dx\n' );
  fprintf ( 1, '\n' );
  fprintf ( 1, '    Nodes           Estimate\n' );
  fprintf ( 1, '\n' );

  for l = 500 : 20 : 600

    q = 0.0;

    for k = 1 : l
      [ theta, weight, x ] = glpairs ( l, k );
      q = q + weight * cos ( 1000.0 * x );
    end

    fprintf ( 1, '  %7d  %24.16g\n', l, q );

  end

  fprintf ( 1, '\n' );
  fprintf ( 1, '    Exact  %24.16g\n', 0.002 * sin ( 1000.0 ) );

  return
end
