function A = legendre_to_monomial_matrix ( n )

%*****************************************************************************80
%
%% legendre_to_monomial_matrix(): Legendre coefficient conversion matrix.
%
%  Discussion:
%
%    If PL(x) is a linear combination of Legendre polynomials
%    with coefficients CL, then PM(x) is a linear combination of
%    monomials with coefficients CM = A * CL.
%    
%    The coefficients are ordered with the constant term is first.
%
%  Example:
%
%    N = 11 (each column must be divided by factor at bottom)
%
%     1    .    -1     .      3     .     -5      .      35     .   -63
%     .    1     .    -3      .    15      .    -25       .   315     .
%     .    .     3     .    -30     .    105      .   -1260     .  3465
%     .    .     .     5      .   -70      .    315       . -4620     .
%     .    .     .     .     35     .   -315      .    6930     .-30030
%     .    .     .     .      .    63      .   -693       . 18018     .
%     .    .     .     .      .     .    231      .  -12012     . 90090
%     .    .     .     .      .     .      .    429       .-25740     .
%     .    .     .     .      .     .      .      .    6435     -109395
%     .    .     .     .      .     .      .      .       . 12155     .
%     .    .     .     .      .     .      .      .       .     . 46189
%
%    /1   /1    /2    /2     /8    /8    /16    /16    /128  /128  /256
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    19 February 2024
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer N, the order of A.
%
%  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) = 1.0;

  if ( n == 2 )
    return
  end

  for j = 3 : n
    for i = 1 : n
      if ( i == 1 )
        A(i,j) = - ( j - 2 ) * A(i,j-2) ...
                 / ( j - 1 );
      else
        A(i,j) = ( ( 2 * j - 3 ) * A(i-1,j-1) ...
                 + (   - j + 2 ) * A(i,j-2) ) ...
                 / (     j - 1 );
      end
    end
  end

  return
end
