function dwdx = r8poly_lagrange_1 ( npol, xpol, xval )

%*****************************************************************************80
%
%% r8poly_lagrange_1() evaluates the first derivative of the Lagrange factor.
%
%  Discussion:
%
%    The power sum form of a polynomial is:
%
%      p(x) = c(0) + c(1) * x + ... + c(n-1) * x^(n-1) + c(n) * x^(n)
%
%    Because MATLAB doesn't allow 0 indexing, we use an adjusted formula:
%
%      p(x) = c(1) + c(2) * x + ... + c(n) * x^(n-1) + c(n+1) * x^(n)
%
%
%    W(XPOL(1:NPOL))(X) = Product ( 1 <= I <= NPOL ) ( X - XPOL(I) )
%
%    W'(XPOL(1:NPOL))(X)
%      = Sum ( 1 <= J <= NPOL ) Product ( I /= J ) ( X - XPOL(I) )
%
%    We also have the recursion:
%
%      W'(XPOL(1:NPOL))(X) = d/dX ( ( X - XPOL(NPOL) ) * W(XPOL(1:NPOL-1))(X) )
%                    = W(XPOL(1:NPOL-1))(X)
%                    + ( X - XPOL(NPOL) ) * W'(XPOL(1:NPOL-1))(X)
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    30 April 2004
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer NPOL, the number of abscissas.
%
%    real XPOL(NPOL), the abscissas, which should be distinct.
%
%    real XVAL, the evaluation point.
%
%  Output:
%
%    real DWDX, the derivative of W with respect to XVAL.
%
  dwdx = 0.0;
  w = 1.0;

  for i = 1 : npol

    dwdx = w + ( xval - xpol(i) ) * dwdx;
    w = w * ( xval - xpol(i) );

  end

  return
end
