Contents
%%Tarea Matlab %Sandu Tigira Tigira t=linspace(0,1);n=3; figure(1); for i=0:n, y=bernstein(t,n,i); plot(t,y) hold on end grid on title('Bernstein grado 3') hold off %d t=linspace(0,1); v=[1 2 4 4.6;1 3 -1 1.5]; plot(v(1,:),v(2,:)); hold on n=size(v); n=n(2); k=size(t); Qx=zeros(n,k(2)); Qy=zeros(n,k(2)); for i=1:n Qx(i,:)=bernstein(t,n-1,i-1)*v(1,i); Qy(i,:)=bernstein(t,n-1,i-1)*v(2,i); end qx=sum(Qx); qy=sum(Qy); figure(2); hold on plot(qx,qy) hold off
Ejercicio 2
Sandu Tigira Tigira
%a) [SGA]=xlsread('sotaventogaliciaanual.xlsx','B:B'); figure(3); hist(SGA) title('Histograma de frecuencias') %b) SGA=xlsread('sotaventogaliciaanual.xlsx','B:B'); x1=0.5:1:max(SGA); figure(4); vi=hist(SGA,x1); frec=vi/sum(vi); f=@(a,x) (a(1)/a(2))*((x/a(2)).^(a(1)-1)).*exp(-(x/a(2)).^a(1)); y1=std(SGA); c=mean(SGA); A0=[y1 c]; %valor inicial Af=nlinfit(x1,frec,f,A0) hold on %diagrama bar(x1,frec,'c'); %curva de ajuste x1=linspace(0,max(SGA),100); y=f(Af,x1); figure(5); plot(x1,y,'r') title('Ajuste Weibull') xlabel('Velocidad') ylabel('Frecuencia') hold off %c) Xa=xlsread('sotavento_curva potencia.xlsx','A:A'); Yb=xlsread('sotavento_curva potencia.xlsx','B:B'); title('Curva de potencia interpolada') x=linspace(0,25); v = interp1(Xa,Yb,x,'pchip'); figure(6) plot(Xa,Yb,'o',x,v,':.'); title('Interpolación de la curva de potencia'); legend('Valores de la curva de potencia','Interpolación de los valores','Location','southeast'); grid on
Ejercicio 3
Sandu Tigira Tigira
%Condiciones iniciales: % m=20 Kg k=20N/m V0=0 m/s X0=1m m=20; k=20; V=[1,0]; %1 es posicion inicial y 0 es velocidad inicial tf=40; %tiempo final c1=5; c2=40; c3=200; %Indico cual es la funcion %x(1) es x y x(2) es v %Luego el punto y coma sirve como separador de ambos miembros (funciones a integrar) fa=@(t,x) [x(2);(-k*x(1)-c1*x(2))/m]; fb=@(t,x) [x(2);(-k*x(1)-c2*x(2))/m]; fc=@(t,x) [x(2);(-k*x(1)-c3*x(2))/m]; [ta,xa]=ode45(fa,[0,tf],V); [tb,xb]=ode45(fb,[0,tf],V); [tc,xc]=ode45(fc,[0,tf],V); %Dibujo la grafica de x en funcion de t para c=5 figure(7) plot(ta,xa(:,1)) grid on xlabel('t'); ylabel('x'); title('Masa-Resorte-Amortiguador'); hold on; %Grafica para c=40 plot(tb,xb(:,1)) %Grafica para c=200 plot(tc,xc(:,1)) legend('c=5','c=40', 'c=200')
Ejercicio 4
Sandu Tigira Tigira function varargout = Ejercicio4(varargin) % EJERCICIO4 MATLAB code for Ejercicio4.fig % EJERCICIO4, by itself, creates a new EJERCICIO4 or raises the existing % singleton*. % % H = EJERCICIO4 returns the handle to a new EJERCICIO4 or the handle to % the existing singleton*. % % EJERCICIO4('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in EJERCICIO4.M with the given input arguments. % % EJERCICIO4('Property','Value',...) creates a new EJERCICIO4 or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before Ejercicio4_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to Ejercicio4_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 Ejercicio4
% Last Modified by GUIDE v2.5 13-Jan-2019 21:11:05
% Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @Ejercicio4_OpeningFcn, ... 'gui_OutputFcn', @Ejercicio4_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 Ejercicio4 is made visible. function Ejercicio4_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 Ejercicio4 (see VARARGIN)
% Choose default command line output for Ejercicio4 handles.output = hObject;
% Update handles structure guidata(hObject, handles);
% UIWAIT makes Ejercicio4 wait for user response (see UIRESUME) % uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line. function varargout = Ejercicio4_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 slider2_Callback(hObject, eventdata, handles) % hObject handle to slider2 (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 % obtiene valor del slider slidev = get(handles.slider2,'Value'); % asigna valor del slider en edit text set(handles.Valorbarra,'String',num2str(slidev)); % actualiza la estructura handle guidata(hObject,handles);
% --- Executes during object creation, after setting all properties. function slider2_CreateFcn(hObject, eventdata, handles) % hObject handle to slider2 (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 Valorbarra_Callback(hObject, eventdata, handles) % hObject handle to Valorbarra (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 Valorbarra as text % str2double(get(hObject,'String')) returns contents of Valorbarra as a double slidev = get(handles.Valorbarra,'String'); % convierte string a numero slidevn = str2num(slidev); % comprueba si no es un numero o si esta fuera de rango 50-1050 if (isempty(slidev) slidevn <50 slidevn >1050) set(handles.slider2,'Value',50); set(handles.Valorbarra,'String','50'); else set(handles.slider2,'Value',slidevn); end
% --- Executes during object creation, after setting all properties. function Valorbarra_CreateFcn(hObject, eventdata, handles) % hObject handle to Valorbarra (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 Tension_Callback(hObject, eventdata, handles) % hObject handle to Tension (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 Tension as text % str2double(get(hObject,'String')) returns contents of Tension as a double
% --- Executes during object creation, after setting all properties. function Tension_CreateFcn(hObject, eventdata, handles) % hObject handle to Tension (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
% --- Executes on button press in Calcula. function Calcula_Callback(hObject, eventdata, handles) % hObject handle to Calcula (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) axes(handles.axes1) f = get(handles.Valorbarra,'String'); b = get(handles.Tension,'String'); c = get(handles.Peso,'String'); d = get(handles.Hmin,'String'); a = str2num(f); T = str2num(b); P= str2num(c); Hmi = str2num(d); h=(T/P)*(cosh((P*a)/(2*T))-1); L=(T/P)*sinh((P*a)/(2*T)); x=linspace(0,a); y=(T/P)*(cosh((P/(2*T))*(2*x-a))-cosh((P*a)/(2*T)))+h+Hmi; axis on plot(x,y); title('Axes 1'); guidata(hObject,handles);
% --- Executes on button press in Limpia. function Limpia_Callback(hObject, eventdata, handles) % hObject handle to Limpia (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) cla(handles.axes1,'reset') guidata(hObject,handles);