function A = gegenbauer_to_monomial_matrix ( n, alpha )

%*****************************************************************************80
%
%% gegenbauer_to_monomial_matrix(): Gegenbauer to monomial conversion matrix.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    04 April 2024
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer N: the order of A.
%
%    real alpha: the parameter.
%
%  Output:
%
%    real A(N,N): the matrix.
%
  A = zeros ( n, n );

  if ( n <= 0 )
    return
  end

  A(1,1) = 1.0;

  if ( n == 1 )
    return
  end

  A(2,2) = 2.0 * alpha;
%
%  Perform convex sum.
%  Translating "(n+1) C(n+1) = 2 (n+alpha) x C(n) - ( n + 2 alpha - 1 ) C(n-1)"
%  drove me nuts, between indexing at 1 rather than 0, and dealing with
%  the interpretation of "n+1", because I now face the rare "off by 2" error!
%
  for j = 3 : n
    nn = j - 2; 
    c1 = ( 2 * nn + 2 * alpha     ) / ( nn + 1 );
    c2 = (   - nn - 2 * alpha + 1 ) / ( nn + 1 );
    A(2:j,j)   =              c1 * A(1:j-1,j-1);
    A(1:j-2,j) = A(1:j-2,j) + c2 * A(1:j-2,j-2);
  end

  return
end
