%Ej 1
%a)
type factr.m
 function x=factr(n)
 if n<=1
     x=1;    
 else
     x=n.*factr(n-1) ;
 end
 end
%b)
type combina.m
function com=combina(n,i);
com=factr(n)/(factr(i)*factr(n-i));
end
%c)
type bernstein.m
function br=bernstein(n,i,t);
br=combina(n,i).*(t.^i).*(1-t).^(n-i);
end
%d)
t=0:0.01:1;
V=[1 2 4 4.6;1 3 -1 1.5]; %vectores
plot(V(1,:),V(2,:),'-*');
hold on
v=size(V);
v=v(2);
l=size(t);
x=zeros(v,l(2));
y=zeros(v,l(2));

for i=1:v; %bernstein para todos los valores
    x(i,:)=bernstein(v-1,i-1,t)*V(1,i);
    y(i,:)=bernstein(v-1,i-1,t)*V(2,i);
end

a=sum(x);
b=sum(y);
plot(a,b,'Linewidth',2);grid on %spline
title('Curva Bézier');xlabel('Eje x');ylabel('Eje y')
hold off