function A = companion_hermite ( p )

%*****************************************************************************80
%
%% companion_hermite() returns the Hermite basis companion matrix for a polynomial.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    31 March 2024
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    John Boyd,
%    Solving Transcendental Equations,
%    The legendre Polynomial Proxy and other Numerical Rootfinders,
%    Perturbation Series, and Oracles,
%    SIAM, 2014,
%    ISBN: 978-1-611973-51-8,
%    LC: QA:353.T7B69
%
%  Input:
%
%    real p(n+1): the polynomial coefficients, in order of increasing degree.
%
%  Output:
%
%    real A(n,n): the companion matrix.
%
  np1 = length ( p );
  n = np1 - 1;

  A = zeros ( n, n );

  for i = 1 : n - 1
    A(i,i+1) = 0.5;
  end

  for i = 2 : n
    A(i,i-1) = i - 1;
  end

  for j = 1 : n
    A(n,j) = A(n,j) - p(j) / 2.0 * p(n+1);
  end

  return
end

