You are on page 1of 18

Codigo:

x=linspace(-1,3,1000);
y=(sqrt(3-x)./(x-3)).*((0<=x)&(x<3)) + (sqrt(1+x)./
(x-3)).*((-1<=x)&(x<0));
plot(x,y);
grid on;
title('Funcion ejercicio 31');
Código:
function [x] = tib(n)
%UNTITLED2 Summary of this function goes here
% Detailed explanation goes here
x(1) = 1;
x(2) = 2;
for k=3:n
x(k)=2*x(k-1)+x(k-2);
end

end

n k X(k-2) X(k-1) X(k)


3 3 1 2 5
4 4 2 5 12
5 5 5 12 29
6 6 12 29 70
7 7 29 70 169
8 8 70 169 408
Codigo:
function [I] = caninpares(x)
n = length(x);
I = 0;
for k=1:n
if rem(x(k),2)~=0
I=I+1;
end
end
end

x=[2 4 3 6 7 2 8]

x=

2 4 3 6 7 2 8

>> caninpares(x)

ans =

2
POLIGONO DE 5 LADOS:
Código:

function varargout = poligono1(varargin)


% POLIGONO1 MATLAB code for poligono1.fig
% POLIGONO1, by itself, creates a new POLIGONO1
or raises the existing
% singleton*.
%
% H = POLIGONO1 returns the handle to a new
POLIGONO1 or the handle to
% the existing singleton*.
%
%
POLIGONO1('CALLBACK',hObject,eventData,handles,...)
calls the local
% function named CALLBACK in POLIGONO1.M with the
given input arguments.
%
% POLIGONO1('Property','Value',...) creates a new
POLIGONO1 or raises the
% existing singleton*. Starting from the left,
property value pairs are
% applied to the GUI before poligono1_OpeningFcn
gets called. An
% unrecognized property name or invalid value
makes property application
% stop. All inputs are passed to
poligono1_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


poligono1

% Last Modified by GUIDE v2.5 08-Sep-2019 21:04:55

% Begin initialization code - DO NOT EDIT


gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton,
...
'gui_OpeningFcn',
@poligono1_OpeningFcn, ...
'gui_OutputFcn',
@poligono1_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 poligono1 is made visible.


function poligono1_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 poligono1 (see
VARARGIN)

% Choose default command line output for poligono1


handles.output = hObject;

% Update handles structure


guidata(hObject, handles);

% UIWAIT makes poligono1 wait for user response (see


UIRESUME)
% uiwait(handles.figure1);

% --- Outputs from this function are returned to the


command line.
function varargout = poligono1_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;

function Ang1_Callback(hObject, eventdata, handles)


% hObject handle to Ang1 (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


Ang1 as text
% str2double(get(hObject,'String')) returns
contents of Ang1 as a double
% --- Executes during object creation, after setting
all properties.
function Ang1_CreateFcn(hObject, eventdata, handles)
% hObject handle to Ang1 (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 Long1_Callback(hObject, eventdata, handles)


% hObject handle to Long1 (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


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

% --- Executes during object creation, after setting


all properties.
function Long1_CreateFcn(hObject, eventdata, handles)
% hObject handle to Long1 (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 Ang5_Callback(hObject, eventdata, handles)
% hObject handle to Ang5 (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


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

% --- Executes during object creation, after setting


all properties.
function Ang5_CreateFcn(hObject, eventdata, handles)
% hObject handle to Ang5 (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 Ang2_Callback(hObject, eventdata, handles)


% hObject handle to Ang2 (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


Ang2 as text
% str2double(get(hObject,'String')) returns
contents of Ang2 as a double
% --- Executes during object creation, after setting
all properties.
function Ang2_CreateFcn(hObject, eventdata, handles)
% hObject handle to Ang2 (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 Long2_Callback(hObject, eventdata, handles)


% hObject handle to Long2 (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


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

% --- Executes during object creation, after setting


all properties.
function Long2_CreateFcn(hObject, eventdata, handles)
% hObject handle to Long2 (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 Ang3_Callback(hObject, eventdata, handles)
% hObject handle to Ang3 (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


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

% --- Executes during object creation, after setting


all properties.
function Ang3_CreateFcn(hObject, eventdata, handles)
% hObject handle to Ang3 (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 Long3_Callback(hObject, eventdata, handles)


% hObject handle to Long3 (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


Long3 as text
% str2double(get(hObject,'String')) returns
contents of Long3 as a double
% --- Executes during object creation, after setting
all properties.
function Long3_CreateFcn(hObject, eventdata, handles)
% hObject handle to Long3 (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 Long5_Callback(hObject, eventdata, handles)


% hObject handle to Long5 (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


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

% --- Executes during object creation, after setting


all properties.
function Long5_CreateFcn(hObject, eventdata, handles)
% hObject handle to Long5 (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 b1.
function b1_Callback(hObject, eventdata, handles)
% hObject handle to b1 (see GCBO)
% eventdata reserved - to be defined in a future
version of MATLAB
% handles structure with handles and user data (see
GUIDATA)
limpia=' ';
set(handles.Ang1,'string',limpia);
set(handles.Ang2,'string',limpia);
set(handles.Ang3,'string',limpia);
set(handles.Ang4,'string',limpia);
set(handles.Ang5,'string',limpia);
set(handles.Long1,'string',limpia);
set(handles.Long2,'string',limpia);
set(handles.Long3,'string',limpia);
set(handles.Long4,'string',limpia);
set(handles.Long5,'string',limpia);

% --- Executes on button press in b2.


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

% --- Executes on button press in b3.


function b3_Callback(hObject, eventdata, handles)
% hObject handle to b3 (see GCBO)
% eventdata reserved - to be defined in a future
version of MATLAB
% handles structure with handles and user data (see
GUIDATA)
% Argumentos de las rectas
angulo1=str2num(get(handles.Ang1,'string'));
angulo2=str2num(get(handles.Ang2,'string'));
angulo3=str2num(get(handles.Ang3,'string'));
angulo4=str2num(get(handles.Ang4,'string'));
longitud1=str2num(get(handles.Long1,'string'));
longitud2=str2num(get(handles.Long2,'string'));
longitud3=str2num(get(handles.Long3,'string'));
longitud4=str2num(get(handles.Long4,'string'));
% Valor del vértice inicial
x(1)=0;
y(1)=0;
%Argumentos en forma matricial
lineas=[angulo1,longitud1;angulo2,longitud2;angulo3,lo
ngitud3;angulo4,longitud4];
for i=1:4
angr=lineas(i,1)*pi/180;
m(i)=tan(angr);
x(i+1)=x(i)+lineas(i,2)*cos(angr);
y(i+1)=y(i)+lineas(i,2)*sin(angr);
delta=(x(i+1)-x(i))/100;
mx=x(i):delta:x(i+1);
my=m(i)*(mx-x(i))+y(i);
plot(mx,my,'r')
vertice=['A';'B';'C';'D';'E'];
text(x(i),y(i),vertice(i))
title('ENCONTRAR UN LADO DEL PARALELOGRAMO')
hold on
end
% Argumentos de la quinta recta
m=(y(1)-y(i+1))/(x(1)-x(i+1));
angr=atan(m);
ang=angr*180/pi;
d=sqrt((y(1)-y(i+1))^2+(x(1)-x(i+1))^2);
delta=(x(1)-x(i+1))/100;
mx=x(i+1):delta:x(1);
my=m*(mx-x(i+1))+y(i+1);
plot(mx,my,'r')
text(x(i+1),y(i+1),vertice(i+1))
hold off
% Poner la respuesta de la cuarta recta
angulo=num2str(ang);

set(handles.Ang5,'string',angulo);
longitud=num2str(d);
set(handles.Long5,'string',longitud);

function Ang4_Callback(hObject, eventdata, handles)


% hObject handle to Ang4 (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
Ang4 as text
% str2double(get(hObject,'String')) returns
contents of Ang4 as a double

% --- Executes during object creation, after setting


all properties.
function Ang4_CreateFcn(hObject, eventdata, handles)
% hObject handle to Ang4 (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 Long4_Callback(hObject, eventdata, handles)


% hObject handle to Long4 (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


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

% --- Executes during object creation, after setting


all properties.
function Long4_CreateFcn(hObject, eventdata, handles)
% hObject handle to Long4 (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

You might also like