%ej1
t=linspace(0,1,100);
b=bernstein(3,0,t);
figure(1)
plot(t,b);
hold on;
b=bernstein(3,1,t);
plot(t,b);
hold on;
b=bernstein(3,2,t);
plot(t,b);
hold on;
b=bernstein(3,3,t);
plot(t,b);
xlabel('t')
ylabel('Polinomio de berstein')
title('Polinomio de berstein')
legend('B_3_,_0','B_3_,_1','B_3_,_2','B_3_,_3')
%ej2
b=xlsread('sotaventogaliciaanual.xlsx');
velocidad=b(:,1);
x=0.5:1:max(velocidad);
horas=hist(velocidad,x);
frec=horas/sum(horas);
modelfunc=@(a,x) (a(1)/a(2))*((x/a(2)).^(a(1)-1)).*exp(-(x/a(2)).^a(1));
beta0=[mean(velocidad) std(velocidad)];
beta=nlinfit(x,frec,modelfunc,beta0);
figure(2)
bar(x,frec,'b');grid on;hold on
x=linspace(0,max(velocidad),100);
y=modelfunc(beta,x);
plot(x,y)
hold off
%ej3
m=20;k=20;xv0=[1,0];tf=40;c1=5;c2=40;c3=200;
f1=@(t,x) [x(2);(-k*x(1)-c1*x(2))/m];
f2=@(t,x) [x(2);(-k*x(1)-c2*x(2))/m];
f3=@(t,x) [x(2);(-k*x(1)-c3*x(2))/m];
[t1,x1]=ode45(f1,[0,tf],xv0);
[t2,x2]=ode45(f2,[0,tf],xv0);
[t3,x3]=ode45(f3,[0,tf],xv0);
figure(3)
plot(t1,x1(:,1),t2,x2(:,1),t3,x3(:,1));grid on
xlabel('t');
ylabel('x');
legend('c=5','c=40', 'c=200');