function bern = bp01 ( n, x )

%*****************************************************************************80
%
%% bp01() evaluates the Bernstein basis polynomials for [0,1] at a point X.
%
%  Discussion:
%
%    For any N greater than or equal to 0, there is a set of N+1 Bernstein
%    basis polynomials, each of degree N, which form a basis for
%    all polynomials of degree N on [0,1].
%
%  Formula:
%
%    BERN(N,I,X) = [N!/(I!*(N-I)!)] * (1-X)^(N-I) * X^I
%
%    N is the degree;
%
%    0 <= I <= N indicates which of the N+1 basis polynomials
%    of degree N to choose;
%
%    X is a point in [0,1] at which to evaluate the basis polynomial.
%
%  First values:
%
%    B(0,0,X) = 1
%
%    B(1,0,X) =      1-X
%    B(1,1,X) =                X
%
%    B(2,0,X) =     (1-X)**2
%    B(2,1,X) = 2 * (1-X)    * X
%    B(2,2,X) =                X**2
%
%    B(3,0,X) =     (1-X)**3
%    B(3,1,X) = 3 * (1-X)**2 * X
%    B(3,2,X) = 3 * (1-X)    * X**2
%    B(3,3,X) =                X**3
%
%    B(4,0,X) =     (1-X)**4
%    B(4,1,X) = 4 * (1-X)**3 * X
%    B(4,2,X) = 6 * (1-X)**2 * X**2
%    B(4,3,X) = 4 * (1-X)    * X**3
%    B(4,4,X) =                X**4
%
%  Special values:
%
%    B(N,I,1/2) = C(N,K) / 2**N
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    12 February 2004
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    Kahaner, Moler, and Nash,
%    Numerical Methods and Software,
%    Prentice Hall, 1989.
%
%  Input:
%
%    integer N, the degree of the Bernstein basis polynomials.
%
%    real X, the evaluation point.
%
%  Output:
%
%    real BERN(0:N), the values of the N+1 Bernstein basis
%    polynomials at X.
%
  if ( n == 0 )

    bern(1) = 1.0E+00;

  elseif ( 0 < n )

    bern(1) = 1.0E+00 - x;
    bern(2) = x;

    for i = 2 : n
      bern(i+1) = x * bern(i);
      for j = i-1 : -1 : 1
        bern(j+1) = x * bern(j) + ( 1.0E+00 - x ) * bern(j+1);
      end
      bern(1) = ( 1.0E+00 - x ) * bern(1);
    end

  end

  return
end
