function c2 = r8poly_deriv_coef ( d, c1, p )

%*****************************************************************************80
%
%% r8poly_deriv_coef() returns the coefficients of the derivative of a polynomial.
%
%  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)
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    24 May 2005
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer D: the degree of the polynomial.
%
%    real C1(1:D+1): the polynomial coefficients.
%
%    integer P: the order of the derivative.
%    0 means no derivative is taken.
%    1 means first derivative,
%    2 means second derivative and so on.
%    Values of P less than 0 are meaningless.  Values of P greater
%    than D are meaningful, but the code will behave as though the
%    value of P was D.
%
%  Output:
%
%    real C2(1:D+1-P): the coefficients of the derivative polynomial.
%
  if ( d+1 <= p )
    c2(1) = 0.0;
    return
  end

  c2_temp(1:d+1) = c1(1:d+1);

  for j = 1 : p
    for i = 0 : d - j
      c2_temp(i+1) = ( i + 1 ) * c2_temp(i+2);
    end
    c2_temp(d-j+2) = 0.0;
  end

  c2 = c2_temp(1:d+1-p);

  return
end
