t=linspace(0,1);
n=3;
figure(1);
for i=0:n
b=Bernstein(n,i,t);
plot(t,b);
hold on
end
figure(2)
V=[1 2 4 4.6; 1 3 -1 1.5];
plot(V(1,:),V(2,:),'-o')
n=size(V);
n=n(2);
s=size(t);
x=zeros(n,s(2));
y=zeros(n,s(2));
for i=1:n
x(i,:)=Bernstein(n-1,i-1,t)*V(1,i);
y(i,:)=Bernstein(n-1,i-1,t)*V(2,i);
end
a=sum(x);
b=sum(y);
hold on
plot(a,b)
function b=Bernstein(n,i,t)
b=comb(n,i).*t.^i.*(1-t).^(n-i);
end
function c = comb(n,i)
c=factr(n)/(factr(i)*factr(n-i));
end
function f = factr(n)
if n == 0
f = 1;
else
f = n * factr(n-1);
end
end