function v = r8poly_legendre_value ( d, x )

%*****************************************************************************80
%
%% r8poly_legendre_value() evaluates the Legendre polynomial P(d,x).
%
%  Licensing:
%
%    This code is distributed under the MIT license. 
%
%  Modified:
%
%    24 October 2019
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer D: the degree of the polynomial.
%
%    real X(M): the evaluation points.
%
%  Output:
%
%    real V(M), the value of the Legendre polynomial at X.
%
  if ( d < 0 )
    v = [];
    return
  end

  v = ones ( size ( x ) );
  if ( d == 0 )
    return
  end

  vnm1 = v;
  v = x;

  for k = 2 : d
 
    vnm2 = vnm1;
    vnm1 = v;
    v = ( ( 2 * k - 1 ) * x .* vnm1   ...
       -  (     k - 1 ) *      vnm2 ) ...
       /  (     k     );
 
  end
 
  return
end
