bernstein
Bernstein polynomial approximation of a function on [0, 1].
Category: Mathematics > Polynomials
Syntax
B = bernstein(f, n, t)
Evaluates the degree-n Bernstein polynomial of f at t.
Description
The Bernstein polynomial of f is B_n(t) = sum over k of f(k/n)*nchoosek(n,k)*t^k*(1 - t)^(n - k). It samples f at the points k/n of [0, 1] and blends the samples with binomial weights. As n grows, B_n converges uniformly to f for any continuous f on [0, 1], which gives a constructive proof of the Weierstrass approximation theorem.
It always reproduces f exactly at t = 0 and t = 1, and it reproduces constants and linear functions exactly for every n.
Input arguments
f- Function handle of one variable, or a symbolic expression (a number is a constant).
n- Degree of the polynomial, a nonnegative integer.
t- Point or points of evaluation, or a symbolic variable for the polynomial itself.
Output arguments
B- Numeric values, or a symbolic polynomial in
t.
Examples
Approximate t^2 and sin
bernstein(@(t) t^2, 2, [0 0.5 1])
bernstein(@(t) sin(t), 3, 0.5)
sin(0.5)
Output
ans = 1×3
0 0.3750 1.0000
ans = 0.4598
ans = 0.4794
The polynomial itself
syms x
bernstein(@(t) t^2, 3, x)
Output
ans = x^3 - (4*x^2*(x - 1))/3 + (x*(x - 1)^2)/3