Contents

Ejercicio 1

%a)

% function x=factr(n)
% if n==0
%     x=1;
% else
%     x=n.*factr(n-1);
% end
% %b)
% function x=combina(n,i)
% %(n i)=n!/(i!*(n-i)!)
% x=factr(n)/(factr(i)*factr(n-i));
% end
% function b=bernstein(n,i,t)
% %B(x)=(n i)t^i(1-t)^(n-i)
% b=combina(n,i)*t.^i.*(1-t).^(n-i);
% end
%
% c)
figure(1)
t=linspace(0,1);
n=3;%grado
for i=0:n
    b=bernstein(n,i,t);
    plot(t,b);
    hold on;
end
xlabel('t');
ylabel('Polinomio de Bernstein grado 3');
title('Polinomios de Bernstein');
legend('B_3,0','B_3,1','B_3,2','B_3,3');
%d)
%Q=sumatorio(Vi+1*Bn,i)
figure(2)
t=linspace(0,1);
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)
xlabel('t');
ylabel('Polinomio de Bernstein grado 3');

Ejercicio 2

Ej.2 apartado a)

figure(3)
[NUMEROS,TEXTO,RESTO]=xlsread('sotaventogaliciaanual.xlsx');

histogram(NUMEROS,0:25)

Ej.2 apartado b)

figure(4)
[NUMEROS,TEXTO,RESTO]=xlsread('sotaventogaliciaanual.xlsx');
k0=mean(NUMEROS);
c0=std(NUMEROS)^2;
y=histc(NUMEROS,0:25);
frecuencias=y/sum(y);
a0=[c0 k0];
x=0:25;
x=x';
f=@(a,x) (a(1)/a(2))*((x/a(2)).^(a(1)-1)).*exp(-(x/a(2)).^a(1));
af=nlinfit(x,frecuencias,f,a0);

xd=linspace(0,25);
yd=f(af,xd);
bar(0:25,frecuencias)
hold on
plot(xd,yd)

Ej.2 apartado c)

figure(5)
[NUMEROS,TEXTO,RESTO]=xlsread('sotavento_curva potencia.xlsx');
velocidad=NUMEROS(:,1);
pot=NUMEROS(:,2);
xd=linspace(0,25);
yd=interp1(velocidad,pot,xd,'pchip');
plot(velocidad,pot,'*')
hold on
plot(xd,yd)

Ej. 2 apartado d)

figure(6)
[NUMEROS,TEXTO,RESTO]=xlsread('sotaventogaliciaanual.xlsx');
k0=mean(NUMEROS);
c0=std(NUMEROS)^2;
BINS=0:25;
y=histc(NUMEROS,BINS);
frecuencias=y/sum(y);
a0=[c0 k0];
x=0:25;
x=x';
f=@(a,x) (a(1)/a(2))*((x/a(2)).^(a(1)-1)).*exp(-(x/a(2)).^a(1)); %distribución de weibull
af=nlinfit(x,frecuencias,f,a0);

%función de potencia
[NUMEROS,TEXTO,RESTO]=xlsread('sotavento_curva potencia.xlsx');
velocidad=NUMEROS(:,1);
pot=NUMEROS(:,2);
P=polyfit(velocidad,pot,3);
g=@(x) f(af,x).*polyval(P,x);
Potencia_media=quad(g,0,10)
Potencia_media =

  197.2897

Ejercicio 3

figure(7)
%Resolución de una ODE de segundo orden
%Método de "ode45"

m=20; %masa del cuerpo
k=20; %constanteelástica del muelle
%condiciones iniciales
x0=[1,0]; % 1 es posición inicial, 0 es velocidad inicial
tf=40; %tiempo final
figure(3)
for c=[5,40,20]
    f=@(t,x) [x(2);(-k*x(1)-c*x(2))/(m)]; % x(1) es el desplazamiento y x(2) es la velocidad
    [t,x]=ode45(f,[0,tf],x0);
    plot(t,x(:,1))
    hold on

end
legend('Cte de amortiguación 5','Cte de amortiguación 40','Cte de amortiguación 20')
grid on
xlabel('Tiempo (s)')
ylabel('Desplazamiento (m)');
title('Sistema masa-resorte-amortiguador')

Ejercicio 4

function varargout = Prototipo_gui(varargin) % PROTOTIPO_GUI MATLAB code for Prototipo_gui.fig % PROTOTIPO_GUI, by itself, creates a new PROTOTIPO_GUI or raises the existing % singleton*. % % H = PROTOTIPO_GUI returns the handle to a new PROTOTIPO_GUI or the handle to % the existing singleton*. % % PROTOTIPO_GUI('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in PROTOTIPO_GUI.M with the given input arguments. % % PROTOTIPO_GUI('Property','Value',...) creates a new PROTOTIPO_GUI or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before Prototipo_gui_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to Prototipo_gui_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help Prototipo_gui

% Last Modified by GUIDE v2.5 12-Jan-2019 17:10:26

% Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @Prototipo_gui_OpeningFcn, ... 'gui_OutputFcn', @Prototipo_gui_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end

if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT

% --- Executes just before Prototipo_gui is made visible. function Prototipo_gui_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to Prototipo_gui (see VARARGIN)

% Choose default command line output for Prototipo_gui handles.output = hObject;

% Update handles structure guidata(hObject, handles);

% UIWAIT makes Prototipo_gui wait for user response (see UIRESUME) % uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line. function varargout = Prototipo_gui_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure varargout{1} = handles.output;

% --- Executes on slider movement. function slider1_Callback(hObject, eventdata, handles) % hObject handle to barra (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'Value') returns position of slider % get(hObject,'Min') and get(hObject,'Max') to determine range of slider

% --- Executes during object creation, after setting all properties. function slider1_CreateFcn(hObject, eventdata, handles) % hObject handle to barra (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background. if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor',[.9 .9 .9]); end

function a_Callback(hObject, eventdata, handles) % hObject handle to a (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of a as text % str2double(get(hObject,'String')) returns contents of a as a double

% --- Executes during object creation, after setting all properties. function a_CreateFcn(hObject, eventdata, handles) % hObject handle to a (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end

function to_Callback(hObject, eventdata, handles) % hObject handle to to (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of to as text % str2double(get(hObject,'String')) returns contents of to as a double

% --- Executes during object creation, after setting all properties. function to_CreateFcn(hObject, eventdata, handles) % hObject handle to to (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end

function peso_Callback(hObject, eventdata, handles) % hObject handle to peso (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of peso as text % str2double(get(hObject,'String')) returns contents of peso as a double

% --- Executes during object creation, after setting all properties. function peso_CreateFcn(hObject, eventdata, handles) % hObject handle to peso (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end

function hmin_Callback(hObject, eventdata, handles) % hObject handle to hmin (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of hmin as text % str2double(get(hObject,'String')) returns contents of hmin as a double

% --- Executes during object creation, after setting all properties. function hmin_CreateFcn(hObject, eventdata, handles) % hObject handle to hmin (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end

function flecha_Callback(hObject, eventdata, handles) % hObject handle to flecha (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of flecha as text % str2double(get(hObject,'String')) returns contents of flecha as a double

% --- Executes during object creation, after setting all properties. function flecha_CreateFcn(hObject, eventdata, handles) % hObject handle to flecha (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end

function longitud_Callback(hObject, eventdata, handles) % hObject handle to longitud (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of longitud as text % str2double(get(hObject,'String')) returns contents of longitud as a double

% --- Executes during object creation, after setting all properties. function longitud_CreateFcn(hObject, eventdata, handles) % hObject handle to longitud (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end

% --- Executes on button press in pushbutton1. function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) a = eval(get(handles.a,'String')); vano=eval(get(handles.a,'String')); tension=eval(get(handles.to,'String')); peso=eval(get(handles.peso,'String')); hmin=eval(get(handles.hmin,'String')); x=linspace(0,vano); h=(tension/peso)*(cosh(peso*vano/(2*tension))-1); l=(tension/peso)*(sinh((peso*vano)/(tension))); y=(tension./peso).*(cosh((peso.*(2.*x-vano))./(2.*tension))-cosh((peso.*vano)./(2.*tension)))+h+hmin;

plot(x,y) ylim([0,max(y)*1.2]);

set(handles.flecha,'String',h); set(handles.long,'String',l);

% --- Executes on slider movement. function barra_Callback(hObject, eventdata, handles) % hObject handle to barra (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) s=get(handles.barra,'Value'); set(handles.a,'String',s);

% Hints: get(hObject,'Value') returns position of slider % get(hObject,'Min') and get(hObject,'Max') to determine range of slider

% --- Executes during object creation, after setting all properties. function barra_CreateFcn(hObject, eventdata, handles) % hObject handle to barra (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background. if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor',[.9 .9 .9]); end %% % MathWorks