Contents

Ejercicio 1

Una curva de tipo param�trica muy utilizada en CAD es la de B�zier. Una curva de B�zier de grado n se define en t�rminos de los polinomios de Bernstein Funciones empleadas: function c=combina(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 t=linspace(0,1,20); n=3; for i=0:n b=bernstein(n,i,t); hold on;grid on plot(t,b) end legend('b0','b1','b2','b3') title('Gr�fica polinomio Bernstein: n=3') function b=bernstein(n,i,t) b=combina(n,i)*t.^i.*(1-t).^(n-i); end

t=linspace(0,1,100);
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)

An�lisis de la velocidad del viento

%Histograma datos viento
datos_viento=xlsread('sotaventogaliciaanual.xlsx');
intervalos=0:1:25;
figure;
hist(datos_viento,intervalos);
title('Histograma datos viento');
xlabel('Velocidad (m/s)');
ylabel('Frecuencia');
hold off;

%Ajuste a la funcion Weibull
velocidad=xlsread('sotaventogaliciaanual.xlsx');
%interpolar si es necesario
if any(isnan(velocidad)) %si hay alg�n NaN
    x=1:length(velocidad);
    i=find(~isnan(velocidad));
    velocidad=interp1(x(i),velocidad(i),x);
end
%histograma
x=0.5:1:max(velocidad);
horas=hist(velocidad,x);

%convierte a frecuencias y ajusta a la funci�n de Weibull
frec=horas/sum(horas);
f=@(a,x) (a(1)/a(2))*((x/a(2)).^(a(1)-1)).*exp(-(x/a(2)).^a(1));
a0=[2 8];  %valor inicial de los par�metros
af=nlinfit(x,frec,f,a0);

%diagrama de frecuencias
figure;
bar(x,frec,'c');
hold on;

%representa la curva de ajuste
x=linspace(0,max(velocidad),100);
y=f(af,x);
plot(x,y,'r')

title('Ajuste a la funci�n Weibull')
xlabel('Velocidad (m/s)')
ylabel('Frecuencia')
hold off

%APARTADO C
%Interpolar la curva de potencia del generador

Pr=1300; x0=3.0;xr=20;x1=25; %datos de la curva de potencia
potencia=xlsread('sotavento_curva potencia.xlsx','B2:B27');
x=0:1:25;
pot=potencia(x>=x0 & x<=xr);
x=x0:1:xr;
figure;
plot(x,pot,'ro','markersize',3,'markerfacecolor','r')
title('Ajuste de la curva de potencia de un generador');
axis([0 22 0 1400]);
xlabel('Velocidad (m/s)');
ylabel('Potencia (MW)');
grid on;
hold on;

%ajuste
p=polyfit(x,pot',3); %ajuste a un polinomio de tercer grado
yp=polyval(p,x);
plot(x,yp,'k')
hold off
%c�lculo de la potencia media
k=2.3849; c=6.0208; %Par�metro de wwibull calculados antes
f=@(x) (k/c)*((x/c).^(k-1)).*exp(-(x/c).^k); %funci�n de Weibull
h=@(x) f(x).*polyval(p,x);
power=quad(h,x0,xr)+Pr*quad(f,xr,x1);
fprintf('La potencia media (MW) es: %3.1f\n',power)
clear all
La potencia media (MW) es: 203.4

Movimiento muelle

[t1, xx1]=ode45(@muelle, [0,40], [1,0],[ ], 5);
plot(t1,xx1(:,1))

hold on

[t2, xx2]=ode45(@muelle, [0,40], [1,0],[ ], 40);
plot(t2,xx2(:,1))
grid on;
[t3, xx3]=ode45(@muelle, [0,40], [1,0],[ ], 200);
plot(t3,xx3(:,1))
xlabel('Tiempo (s)');
ylabel('x (m)');
title('x(t) para distintos c (coef. amortiguamiento)');
legend('c=5','c=40','c=200');

% funcion muelle
% function x=muelle(t,x,c)
% x=[x(2); (-c*x(2)-20*x(1))/20];
% end

catenaria

catenaria