a symbolic expression or function
g returns the
Bernstein polynomial, evaluated at the point
This syntax regards
g as a univariate function
of the variable determined by
If any argument is symbolic,
all arguments except a function handle to symbolic, and converts a
function handle’s results to symbolic.
Approximation of Sine Function Specified as Function Handle
Approximate the sine function by the 10th- and 100th-degree Bernstein polynomials.
syms t b10 = bernstein(@(t) sin(2*pi*t), 10, t); b100 = bernstein(@(t) sin(2*pi*t), 100, t);
sin(2*pi*t) and its approximations.
fplot(sin(2*pi*t),[0,1]) hold on fplot(b10,[0,1]) fplot(b100,[0,1]) legend('sine function','10th-degree polynomial',... '100th-degree polynomial') title('Bernstein polynomials') hold off
Approximation of Exponential Function Specified as Symbolic Expression
Approximate the exponential function by the
second-order Bernstein polynomial in the variable
syms x t bernstein(exp(x), 2, t)
ans = (t - 1)^2 + t^2*exp(1) - 2*t*exp(1/2)*(t - 1)
Approximate the multivariate exponential function. When you
approximate a multivariate function,
it as a univariate function of the default variable determined by
The default variable for the expression
syms x y t symvar(y*exp(x*y), 1)
ans = x
bernstein treats this expression as a univariate
bernstein(y*exp(x*y), 2, t)
ans = y*(t - 1)^2 + t^2*y*exp(y) - 2*t*y*exp(y/2)*(t - 1)
y*exp(x*y) as a function of the
y, specify the variable explicitly:
bernstein(y*exp(x*y), y, 2, t)
ans = t^2*exp(x) - t*exp(x/2)*(t - 1)
Approximation of Linear Ramp Specified as Symbolic Function
a linear ramp by the fifth-order Bernstein polynomials in the variable
syms f(t) f(t) = triangularPulse(1/4, 3/4, Inf, t); p = bernstein(f, 5, t)
p = 7*t^3*(t - 1)^2 - 3*t^2*(t - 1)^3 - 5*t^4*(t - 1) + t^5
Simplify the result:
ans = -t^2*(2*t - 3)
Numerical Stability of Simplified Bernstein Polynomials
When you simplify a high-order symbolic Bernstein polynomial, the result often cannot be evaluated in a numerically stable way.
Approximate this rectangular pulse function by the 100th-degree Bernstein polynomial, and then simplify the result.
f = @(x)rectangularPulse(1/4,3/4,x); b1 = bernstein(f, 100, sym('t')); b2 = simplify(b1);
Convert the polynomial
b1 and the simplified polynomial
b2 to MATLAB® functions.
f1 = matlabFunction(b1); f2 = matlabFunction(b2);
Compare the plot of the original rectangular pulse function, its numerically stable Bernstein representation
f1, and its simplified version
f2. The simplified version is not numerically stable.
t = 0:0.001:1; plot(t, f(t), t, f1(t), t, f2(t)) hold on legend('original function','Bernstein polynomial',... 'simplified Bernstein polynomial') hold off
f — Function to be approximated by a polynomial
Function to be approximated by a polynomial, specified as a
f must accept one scalar input
argument and return a scalar value.
g — Function to be approximated by a polynomial
symbolic expression | symbolic function
Function to be approximated by a polynomial, specified as a symbolic expression or function.
n — Bernstein polynomial order
Bernstein polynomial order, specified as a nonnegative number.
t — Evaluation point
number | symbolic number | symbolic variable | symbolic expression | symbolic function
Evaluation point, specified as a number, symbolic number, variable,
expression, or function. If
t is a symbolic function,
the evaluation point is the mathematical expression that defines
To extract the mathematical expression defining
var — Free variable
Free variable, specified as a symbolic variable.
A Bernstein polynomial is a linear combination of Bernstein basis polynomials.
A Bernstein polynomial of degree
n is defined
are the Bernstein basis polynomials, and is a binomial coefficient.
The coefficients are called Bernstein coefficients or Bezier coefficients.
f is a continuous function on the interval
is the approximating Bernstein polynomial, then
t on the interval
Symbolic polynomials returned for symbolic
tare numerically stable when substituting numerical values between
If you simplify a symbolic Bernstein polynomial, the result can be unstable when substituting numerical values for the curve parameter
Introduced in R2013b