function y=bernstein(n,x) % BERNSTEIN compute values of Bernstein polynomials % % y=bernstein(n,x) % % n: degree % x: abscissa vector % y: on return, contains values of the Bernstein % polynomials on the standard interval [0..1] in each row. % The Bernstein polynomials are defined as follows: % % b_{n,k}(x) = (n choose k) * x^k * (1-x)^(n-k) % % for k=0:n, and are stored in the (k+1)-th row of y. l = length(x); xx = reshape(x,1,l); y = zeros(n+1,l); for k=0:n y(k+1,:) = nchoosek(n,k) *xx.^k .* (1-xx).^(n-k); end