function c2 = r8poly_shift ( d1, c1, scale, shift )

%*****************************************************************************80
%
%% r8poly_shift() adjusts the coefficients of a polynomial for a new argument.
%
%  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)
%
%    Assume that Z is related to X by the formula:
%
%      Z = SCALE * X + SHIFT
%
%    then this routine computes coefficients C for the polynomial Q(Z):
%
%      Q(Z) =
%          C(N+1) * Z^(N)
%        + ...
%        + C(2) * Z
%        + C(1)
%
%    so that:
%
%      Q(Z(X)) = P(X)
%
%  Example:
%
%    P(X) = 2 * X^2 - X + 6
%
%    Z = 2.0 * X + 3.0
%
%    Q(Z) = 0.5 *         Z^2 -  3.5 * Z + 12
%
%    Q(Z(X)) = 0.5 * ( 4.0 * X^2 + 12.0 * X +  9 )
%            - 3.5 * (              2.0 * X +  3 )
%                                            + 12
%
%            = 2.0         * X^2 -  1.0 * X +  6
%
%            = P(X)
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    30 September 2006
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer D1: the degree of the polynomial.
%
%    real C1(D1+1): the coefficient array in terms of the X variable.
%
%    real SHIFT, SCALE: the shift and scale applied to X,
%    so that Z = SCALE * X + SHIFT.
%
%  Output:
%
%    real C2(D1+1): the coefficient array in terms of the Z variable.
%
  for i = 1 : d1 + 1
    c2(i+1:d1+1) = c1(i+1:d1+1) / scale;
  end

  for i = 1 : d1 + 1
    for j = d1 : -1 : i
      c2(j) = c2(j) - shift * c2(j+1);
    end
  end

  return
end
