function [ x, w ] = legendre_set_cos ( n )

%*****************************************************************************80
%
%% legendre_set_cos() sets a Gauss-Legendre rule for COS(X) * F(X) on [-PI/2,PI/2].
%
%  Discussion:
%
%    The integral:
%
%      integral ( -pi/2 <= x <= pi/2 ) cos(x) * f(x) dx
%
%    The quadrature rule:
%
%      sum ( 1 <= i <= n ) w(i) * f ( x(i) )
%
%    The integral:
%
%      integral ( 0 <= x <= pi ) sin(x) * f(x) dx
%
%    the quadrature rule:
%
%      Sum ( 1 <= I <= N ) W(I) * F ( X(I) + PI/2 )
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    13 October 2005
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    Gwynne Evans,
%    Practical Numerical Integration,
%    Wiley, 1993, QA299.3E93, page 310.
%
%  Input:
%
%    integer N, the order.
%    N must be between 1, 2, 4, 8 or 16.
%
%  Output:
%
%    real X(N), the abscissas.
%
%    real W(N), the weights.
%
  x = zeros ( n, 1 );
  w = zeros ( n, 1 );

  if ( n == 1 )

    x(1) = 0.0;

    w(1) = 2.0;

  elseif ( n == 2 )

    x(1) = - 0.68366739008990304094;
    x(2) =   0.68366739008990304094;

    w(1) = 1.0;
    w(2) = 1.0;

  elseif ( n == 4 )

    x(1) = - 1.1906765638948557415;
    x(2) = - 0.43928746686001514756;
    x(3) =   0.43928746686001514756;
    x(4) =   1.1906765638948557415;

    w(1) = 0.22407061812762016065;
    w(2) = 0.77592938187237983935;
    w(3) = 0.77592938187237983935;
    w(4) = 0.22407061812762016065;

  elseif ( n == 8 )

    x(1) = - 1.4414905401823575701;
    x(2) = - 1.1537256454567275850;
    x(3) = - 0.74346864787549244989;
    x(4) = - 0.25649650741623123020;
    x(5) =   0.25649650741623123020;
    x(6) =   0.74346864787549244989;
    x(7) =   1.1537256454567275850;
    x(8) =   1.4414905401823575701;

    w(1) = 0.027535633513767011149;
    w(2) = 0.14420409203022750950;
    w(3) = 0.33626447785280459621;
    w(4) = 0.49199579660320088314;
    w(5) = 0.49199579660320088314;
    w(6) = 0.33626447785280459621;
    w(7) = 0.14420409203022750950;
    w(8) = 0.027535633513767011149;

  elseif ( n == 16 )

    x( 1) = - 1.5327507132362304779;
    x( 2) = - 1.4446014873666514608;
    x( 3) = - 1.3097818904452936698;
    x( 4) = - 1.1330068786005003695;
    x( 5) = - 0.92027786206637096497;
    x( 6) = - 0.67861108097560545347;
    x( 7) = - 0.41577197673418943962;
    x( 8) = - 0.14003444424696773778;
    x( 9) =   0.14003444424696773778;
    x(10) =   0.41577197673418943962;
    x(11) =   0.67861108097560545347;
    x(12) =   0.92027786206637096497;
    x(13) =   1.1330068786005003695;
    x(14) =   1.3097818904452936698;
    x(15) =   1.4446014873666514608;
    x(16) =   1.5327507132362304779;

    w( 1) = 0.0024194677567615628193;
    w( 2) = 0.014115268156854008264;
    w( 3) = 0.040437893946503669410;
    w( 4) = 0.083026647573217742131;
    w( 5) = 0.13834195526951273359;
    w( 6) = 0.19741148870253455567;
    w( 7) = 0.24763632094635522403;
    w( 8) = 0.27661095764826050408;
    w( 9) = 0.27661095764826050408;
    w(10) = 0.24763632094635522403;
    w(11) = 0.19741148870253455567;
    w(12) = 0.13834195526951273359;
    w(13) = 0.083026647573217742131;
    w(14) = 0.040437893946503669410;
    w(15) = 0.014115268156854008264;
    w(16) = 0.0024194677567615628193;

  else

    fprintf ( 1, '\n' );
    fprintf ( 1, 'LEGENDRE_SET_COS - Fatal error!\n' );
    fprintf ( 1, '  Illegal value of N = %d\n', n );
    error ( 'LEGENDRE_SET_COS - Fatal error!' );

  end

  return
end
