function c3 = r8poly_add ( d1, c1, d2, c2 )

%*****************************************************************************80
%
%% r8poly_add() adds two polynomials.
%
%  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:
%
%    22 October 2019
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer D1, the degree of polynomial C1.
%
%    real C1(1:D1+1), the first polynomial.
%
%    integer D2, the degree of polynomial C2.
%
%    real C2(1:D2+1), the second polynomial.
%
%  Output:
%
%    real C3(1:max(D1,D2)+1), the coefficients of C1 + C2.
%
  c3 = zeros ( max ( d1, d2 ) + 1, 1 );

  if ( d2 == d1 )
    c3(1:d1+1) = c1(1:d1+1) + c2(1:d1+1);
  elseif ( d2 < d1 )
    c3(1:d2+1) = c1(1:d2+1) + c2(1:d2+1);
    c3(d2+2:d1+1) = c1(d2+2:d1+1);
  elseif ( d1 < d2 )
    c3(1:d1+1) = c1(1:d1+1) + c2(1:d1+1);
    c3(d1+2:d2+1) = c2(d1+2:d2+1);
  end

  return
end
