function a = bernstein_to_legendre01_matrix ( n )

%*****************************************************************************80
%
%% bernstein_to_legendre01_matrix() returns the Bernstein-to-Legendre01 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:
%
%    bernstein_to_legendre01_matrix ( 5 ):
%
%    0.1667    0.1667    0.1667    0.1667    0.1667    0.1667
%   -0.3571   -0.2143   -0.0714    0.0714    0.2143    0.3571
%    0.2976   -0.0595   -0.2381   -0.2381   -0.0595    0.2976
%   -0.1389    0.1944    0.1111   -0.1111   -0.1944    0.1389
%    0.0357   -0.1071    0.0714    0.0714   -0.1071    0.0357
%   -0.0040    0.0198   -0.0397    0.0397   -0.0198    0.0040
%
%  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 Bernstein-to-Legendre matrix.
%
  a = zeros ( n + 1, n + 1 );

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

  return
end
