function value = legendre_combo_value ( c, x )

%*****************************************************************************80
%
%% legendre_combo_value evaluates a linear combination of Legendre functions.
%
%  Input:
%
%    real c(d+1): the coefficients.
%
%    real x(n): the evaluation points.
%
%  Output:
%
%    real value(n): the value of the linear combination of Legendre functions
%    at x.
%
  d = length ( c ) - 1;

  value = zeros ( size ( x ) );

  v = ones ( size ( x ) );
  value = value + c(1) * v;
  if ( d == 0 )
    return
  end

  vkm1 = v;
  v = x;
  value = value + c(2) * v;

  for k = 2 : d
 
    vkm2 = vkm1;
    vkm1 = v;
    v = ( ( 2 * k - 1 ) * x .* vkm1   ...
       -  (     k - 1 ) *      vkm2 ) ...
       /  (     k     );
    value = value + c(k+1) * v;
 
  end
 
  return
end
