function c = r8poly_legendre ( d )

%*****************************************************************************80
%
%% r8poly_legendre() returns coefficients of the Legendre polynomial P(d,x).
%
%  First terms:
%
%     1
%     0     1
%    -1/2   0      3/2
%     0    -3/2    0     5/2
%     3/8   0    -30/8   0     35/8
%     0    15/8    0   -70/8    0     63/8
%    -5/16  0    105/16  0   -315/16   0    231/16
%     0   -35/16   0   315/16   0   -693/16   0    429/16
%
%     1.00000
%     0.00000  1.00000
%    -0.50000  0.00000  1.50000
%     0.00000 -1.50000  0.00000  2.5000
%     0.37500  0.00000 -3.75000  0.00000  4.37500
%     0.00000  1.87500  0.00000 -8.75000  0.00000  7.87500
%    -0.31250  0.00000  6.56250  0.00000 -19.6875  0.00000  14.4375
%     0.00000 -2.1875   0.00000  19.6875  0.00000 -43.3215  0.00000  26.8125
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    23 October 2019
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    Milton Abramowitz, Irene Stegun,
%    Handbook of Mathematical Functions,
%    US Department of Commerce, 1964.
%
%    Daniel Zwillinger, editor,
%    CRC Standard Mathematical Tables and Formulae,
%    30th Edition,
%    CRC Press, 1996.
%
%  Input:
%
%    integer D, the degree of the polynomial.
%
%  Output:
%
%    real C(1:D+1): the coefficients of the Legendre polynomial.
%
  if ( d < 0 )
    c = [];
    return
  end

  c = [ 1.0 ];
  if ( d == 0 )
    return
  end

  ckm1 = c;
  c = [ 0.0; 1.0 ];
 
  for k = 2 : d
    ckm2 = ckm1;
    ckm1 = c;
    c = zeros ( k + 1, 1 );
    c(1:k-1) =            (   - k + 1 ) * ckm2(1:k-1) / ( k );
    c(2:k+1) = c(2:k+1) + ( 2 * k - 1 ) * ckm1(1:k  ) / ( k );
  end
 
  return
end
