function a = bernstein_to_monomial_matrix ( n )

%*****************************************************************************80
%
%% bernstein_to_monomial_matrix() returns Bernstein to monomial matrix.
%
%  Discussion:
%
%    The Bernstein-to-Power matrix of degree N is an N+1xN+1 matrix A which can 
%    be used to transform the N+1 coefficients of a polynomial of degree N
%    from a vector B of Bernstein basis polynomial coefficients ((1-x)^n,...,x^n).
%    to a vector P of coefficients of the power basis (1,x,x^2,...,x^n).
%
%    If we are using N=4-th degree polynomials, the matrix has the form:
%
%      1  -4   6  -4  1
%      0   4 -12  12 -4
%      0   0   6 -12  6
%      0   0   0   4 -4
%      0   0   0   0  1
%
%   and a polynomial with the Bernstein basis representation
%     p(x) = 3/4 * b(4,1) + 1/2 b(4,2)
%   whose Bernstein coefficient vector is
%     B = ( 0, 3/4, 1/2, 0, 0 )
%   will have the power basis coefficients 
%     P = A * B = ( 0, 3, -6, 3, 0 )
%     P(x) = 3x - 6x^2 + 3x^3
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    20 February 2024
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer N, the 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 : i
      a(n-i+1,n-j+1) = ( -1 ) ^ ( i - j ) * nchoosek ( n - j, i - j ) ...
        * nchoosek ( n, j );
    end
  end

  return
end
