function a = legendre01_to_bernstein_matrix ( n )

%*****************************************************************************80
%
%% legendre01_to_bernstein_matrix() returns the Legendre01-to-Bernstein matrix.
%
%  Discussion:
%
%    The Legendre polynomials are often defined on [-1,+1], while the
%    Bernstein polynomials are defined on [0,1].  For this function,
%    the Legendre polynomials have been shifted to share the [0,1]
%    interval of definition.
%
%  Example:
%
%    legendre01_to_bernstein_matrix(5):
%
%    1.0000   -1.0000    1.0000   -1.0000    1.0000   -1.0000
%    1.0000   -0.6000   -0.2000    1.4000   -3.0000    5.0000
%    1.0000   -0.2000   -0.8000    0.8000    2.0000  -10.0000
%    1.0000    0.2000   -0.8000   -0.8000    2.0000   10.0000
%    1.0000    0.6000   -0.2000   -1.4000   -3.0000   -5.0000
%    1.0000    1.0000    1.0000    1.0000    1.0000    1.0000
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    22 February 2024
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer N, the maximum degree of the polynomials.
%
%  Output:
%
%    real A(N+1,N+1), the matrix.
%
  a = zeros ( n + 1, n + 1 );

  for i = 0 : n
    for j = 0 : n
      for k = max ( 0, i + j - n ) : min ( i, j )
        a(i+1,j+1) = a(i+1,j+1) ...
          + ( -1.0 ) ^ ( j + k ) * nchoosek ( j, k ) ^ 2 ...
          * nchoosek ( n - j, i - k );
      end
      a(i+1,j+1) = a(i+1,j+1) / nchoosek ( n, i );
    end
  end

  return
end
