bernstein_polynomial, a Python code which evaluates the Bernstein polynomials.
The k-th Bernstein basis polynomial of degree n is defined by
B(n,k)(x) = C(n,k) * (1-x)^(n-k) * x^kfor k = 0 to n and C(n,k) is the combinatorial function "N choose K" defined by
C(n,k) = n! / k! / ( n - k )!
For an arbitrary value of n, the set B(n,k) forms a basis for the space of polynomials of degree n or less.
Every basis polynomial B(n,k) is nonnegative in [0,1], and may be zero only at the endpoints.
Except for the case n = 0, the basis polynomial B(n,k)(x) has a unique maximum value at
x = k/n.
For any point x, (including points outside [0,1]), the basis polynomials for an arbitrary value of n sum to 1:
sum ( 1 <= k <= n ) B(n,k)(x) = 1
For 0 < n, the Bernstein basis polynomial can be written as a combination of two lower degree basis polynomials:
B(n,k)(x) = ( 1 - x ) * B(n-1,k)(x) + x * B(n-1,k-1)(x) +where, if k is 0, the factor B(n-1,k-1)(x) is taken to be 0, and if k is n, the factor B(n-1,k)(x) is taken to be 0.
A Bernstein basis polynomial can be written as a combination of two higher degree basis polynomials:
B(n,k)(x) = ( (n+1-k) * B(n+1,k)(x) + (k+1) * B(n+1,k+1)(x) ) / ( n + 1 )
The derivative of B(n,k)(x) can be written as:
d/dx B(n,k)(x) = n * B(n-1,k-1)(x) - B(n-1,k)(x)
A Bernstein polynomial can be written in terms of the standard power basis:
B(n,k)(x) = sum ( k <= i <= n ) (-1)^(i-k) * C(n,k) * C(i,k) * x^i
A power basis monomial can be written in terms of the Bernstein basis of degree n where k <= n:
x^k = sum ( k-1 <= i <= n-1 ) C(i,k) * B(n,k)(x) / C(n,k)
Over the interval [0,1], the n-th degree Bernstein approximation polynomial to a function f(x) is defined by
BA(n,f)(x) = sum ( 0 <= k <= n ) f(k/n) * B(n,k)(x)As a function of n, the Bernstein approximation polynomials form a sequence that slowly, but uniformly, converges to f(x) over [0,1].
By a simple linear process, the Bernstein basis polynomials can be shifted to an arbitrary interval [a,b], retaining their properties.
The computer code and data files described and made available on this web page are distributed under the MIT license
bernstein_polynomial is available in a C version and a C++ version and a FORTRAN90 version and a MATLAB version and a Python version.
chebyshev_polynomial, a python code which considers the chebyshev polynomials t(i,x), u(i,x), v(i,x) and w(i,x). functions are provided to evaluate the polynomials, determine their zeros, produce their polynomial coefficients, produce related quadrature rules, project other functions onto these polynomial bases, and integrate double and triple products of the polynomials.
gegenbauer_polynomial, a python code which evaluates the gegenbauer polynomial and associated functions.
legendre_polynomial, a python code which evaluates the legendre polynomial and associated functions.
legendre_shifted_polynomial, a python code which evaluates the shifted legendre polynomial, with domain [0,1].