function [ p, dp ] = poly_and_derivative ( c, x )

%*****************************************************************************80
%
%% poly_eval() evaluates a polynomial naively.
%
%  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)
%
%    Because we want to use max() on the result, and for moronic reasons,
%    max returns a scalar value for a row vector but a vector value for
%    a column vector, we reluctantly define our result here as a row vector.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    12 January 2026
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    complex C(D+1): the polynomial coefficients.  
%
%    complex X(N): the evaluation point.
%
%  Output:
%
%    complex VALUE: the polynomial value.
%
  d = length ( c ) - 1;
  n = length ( x );

  dp = zeros ( 1, n );
  p  = zeros ( 1, n );
  for i = d + 1 : -1 : 1 
    dp = dp .* x + p;
    p =  p  .* x + c(i);
  end

  return
end

