function c2 = r8poly_square ( d1, c1 )

%*****************************************************************************80
%
%% r8poly_square() squares 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:
%
%    20 October 2019
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer D1: the degree of the polynomial.
%
%    real C1(1:D1+1): the coefficients of the polynomial.
%
%  Output:
%
%    real C2(1:2*D1+1): the coefficients of the square of the polynomial.
%
  c1 = c1(:);

  d2 = 2 * d1;
  c2 = zeros ( d2 + 1, 1 );
  
  for i = 0 : d1
    c2(i+1:i+d1+1) = c2(i+1:i+d1+1) + c1(i+1) * c1(1:d1+1);
  end

  return
end
