You are on page 1of 17

TEMA

PROGRAMAS MATLAB

INTEGRANTES:

JOHNN PUCA
ROBERTO PUJOS
CHRISTIAN HUANCA

PERIODO: OCTUBRE 2017- FEBRERO 2018


1. Graficar la serie: (1+i^n)
Código

%grafica de la serie (1+i^n)


clc, clear all,

n=1:0.5:10;
zn=((1i.^n)+1);

fprintf('\t\tGráfica de la Serie: (1+i^n)\n\n');


fprintf('Los valores son: \n');
fprintf('\t\tn zn\n');
disp([n zn]')
plot(zn,'b*','LineWidth',3);

Gráfica
2. Graficar la serie (i^n+1/n)

%grafica serie (i^n+1/n)


clc, clear all,
n=1:0.5:10;
zn=((1i.^(n+1))./n);

fprintf('\t\tGráfica de la Serie: (i^n+1/n)\n\n');


fprintf('Los valores son: \n');
fprintf('\t\tn zn\n');
disp([n zn]')
plot(zn,'r*','LineWidth',3);
3. Operaciones con complejos

%Programa: Operación entre números complejos


clc, clear all, clf
fprintf('\t Operación con números complejos \n')
while true
fprintf('\t MENÚ \n')
disp('1.-Suma')
disp('2.-Producto')
disp('3.-Potenciación')
disp('4.-Radicación')
disp('5.-Conjugada')
disp('6.-Logaritmo')
disp('7.-Norma')
disp('8.-Ángulo')
disp('9.-SALIR')
n=input('Ingrese la opción: ','s');
nx=str2num(n);
disp('')
switch nx
case 1
ints=2;
while (ints>=0)
z1=input('Ingrese los valores de z1= ','s');
[zx,tf] = str2num(z1);
if (tf==0)
disp('ingresa números complejos')
cont=['Tienes ', num2str(ints), ' intentos'];
disp(cont)
ints= ints-1;
if (ints==-1)
return
end
else
ints=-1;
end

end
ints=2;
while (ints>=0)
z2=input('Ingrese los valores de z2= ','s');
[zy,tf] = str2num(z2);
if (tf==0)
disp('ingresa números complejos')
cont=['Tienes ', num2str(ints), ' intentos'];
disp(cont)
ints= ints-1;
if (ints==-1)
return
end
else
ints=-1;
end

end

suma=zx+zy;
fprintf('La suma es: ')
disp(suma)
case 2
ints=2;
while (ints>=0)
z1=input('Ingrese los valores de z1= ','s');
[zx,tf] = str2num(z1);
if (tf==0)
disp('ingresa números complejos')
cont=['Tienes ', num2str(ints), ' intentos'];
disp(cont)
ints= ints-1;
if (ints==-1)
return
end
else
ints=-1;
end

end
ints=2;
while (ints>=0)
z2=input('Ingrese los valores de z2= ','s');
[zy,tf] = str2num(z2);
if (tf==0)
disp('ingresa números complejos')
cont=['Tienes ', num2str(ints), ' intentos'];
disp(cont)
ints= ints-1;
if (ints==-1)
return
end
else
ints=-1;
end

end
prod=zx*zy;
fprintf('EL producto es: ')
disp(prod)
case 3
ints=2;
while (ints>=0)
m=input('Ingrese el indice de potencia','s');
[zx,tf] = str2num(m);
if (tf==0)
disp('Ingresa un indice entero positivo')
cont=['Tienes ', num2str(ints), ' intentos'];
disp(cont)
ints= ints-1;
if (ints==-1)
return
end
else
ints=-1;
end

end
ints=2;
while (ints>=0)
z1=input('Ingrese los valores de z1= ','s');
[zy,tf] = str2num(z1);
if (tf==0)
disp('ingresa números complejos')
cont=['Tienes ', num2str(ints), ' intentos'];
disp(cont)
ints= ints-1;
if (ints==-1)
return
end
else
ints=-1;
end

end

poten=zy^zx;
fprintf('la potencia es: ')
disp(poten)
case 4
ints=2;
while (ints>=0)
m=input('Ingrese el indice de la raiz','s');
[zx,tf] = str2num(m);
if (tf==0)
disp('Ingresa un indice entero positivo')
cont=['Tienes ', num2str(ints), ' intentos'];
disp(cont)
ints= ints-1;
if (ints==-1)
return
end
else
ints=-1;
end

end
ints=2;
while (ints>=0)
z1=input('Ingrese los valores de z1= ','s');
[zy,tf] = str2num(z1);
if (tf==0)
disp('ingresa números complejos')
cont=['Tienes ', num2str(ints), ' intentos'];
disp(cont)
ints= ints-1;
if (ints==-1)
return
end
else
ints=-1;
end

end
rai=zy^(1/zx);
fprintf('la raiz es: ')
disp(rai)
case 5
ints=2;
while (ints>=0)
z1=input('Ingrese los valores de z1= ','s');
[zx,tf] = str2num(z1);
if (tf==0)
disp('ingresa números complejos')
cont=['Tienes ', num2str(ints), ' intentos'];
disp(cont)
ints= ints-1;
if (ints==-1)
return
end
else
ints=-1;
end

end
conju=conj(zx);
fprintf('la conjugada de z1 es ')
disp(conju)
case 6
ints=2;
while (ints>=0)
z1=input('Ingrese los valores de z1= ','s');
[zx,tf] = str2num(z1);
if (tf==0)
disp('Ingresa número complejos')
cont=['Tienes ', num2str(ints), ' intentos'];
disp(cont)
ints= ints-1;
if (ints==-1)
return
end
else
ints=-1;
end

end
ln=log(zx);
fprintf('El logaritmo de z1 es: ')
disp(ln)
case 7
ints=2;
while (ints>=0)
z1=input('Ingrese los valores de z1= ','s');
[zx,tf] = str2num(z1);
if (tf==0)
disp('Ingresa número complejos')
cont=['Tienes ', num2str(ints), ' intentos'];
disp(cont)
ints= ints-1;
if (ints==-1)
return
end
else
ints=-1;
end

end
norma=abs(zx);
fprintf('la norma de z1 es: ')
disp(norma)
case 8
ints=2;
while (ints>=0)
z1=input('Ingrese los valores de z1= ','s');
[zx,tf] = str2num(z1);
if (tf==0)
disp('Ingresa número complejos')
cont=['Tienes ', num2str(ints), ' intentos'];
disp(cont)
ints= ints-1;
if (ints==-1)
return
end
else
ints=-1;
end

end
ang=(angle(zx)*180)/pi;
fprintf('El ángulo de z1 es: ')
disp(ang)
case 9
return
otherwise
error('Seleccione un número del menú')

end
end

4. Operaciones con complejos

function varargout = fig1(varargin)


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

% Last Modified by GUIDE v2.5 23-Oct-2017 22:41:51

% Begin initialization code - DO NOT EDIT


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


function fig1_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 fig1 (see VARARGIN)

% Choose default command line output for fig1


handles.output = hObject;

% Update handles structure


guidata(hObject, handles);

% UIWAIT makes fig1 wait for user response (see UIRESUME)


% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.
function varargout = fig1_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 x1_Callback(hObject, eventdata, handles)
% hObject handle to x1 (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 x1 as text


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

% --- Executes during object creation, after setting all properties.


function x1_CreateFcn(hObject, eventdata, handles)
% hObject handle to x1 (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 y1_Callback(hObject, eventdata, handles)


% hObject handle to y1 (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 y1 as text


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

% --- Executes during object creation, after setting all properties.


function y1_CreateFcn(hObject, eventdata, handles)
% hObject handle to y1 (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 x2_Callback(hObject, eventdata, handles)


% hObject handle to x2 (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 x2 as text


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

% --- Executes during object creation, after setting all properties.


function x2_CreateFcn(hObject, eventdata, handles)
% hObject handle to x2 (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 y2_Callback(hObject, eventdata, handles)


% hObject handle to y2 (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 y2 as text


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

% --- Executes during object creation, after setting all properties.


function y2_CreateFcn(hObject, eventdata, handles)
% hObject handle to y2 (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 ry_Callback(hObject, eventdata, handles)


% hObject handle to ry (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 ry as text


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


% hObject handle to rx (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 rx as text


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

% --- Executes during object creation, after setting all properties.


function rx_CreateFcn(hObject, eventdata, handles)
% hObject handle to rx (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 radiobutton1.


function radiobutton1_Callback(hObject, eventdata, handles)
% hObject handle to radiobutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
clc
a1=get(handles.x1,'string')
a1=str2num(a1)
a2=get(handles.y1,'string')
a2=str2num(a2)
b1=get(handles.x2,'string')
b1=str2num(b1)
b2=get(handles.y2,'string')
b2=str2num(b2)
rx1=a1+b1
ry1=a2+b2
set(handles.rx,'string',rx1)
set(handles.ry,'string',ry1)
% Hint: get(hObject,'Value') returns toggle state of radiobutton1

% --- Executes on button press in resta.


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

% Hint: get(hObject,'Value') returns toggle state of resta

% --- Executes on button press in producto.


function producto_Callback(hObject, eventdata, handles)
% hObject handle to producto (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
clc
a1=get(handles.x1,'string')
a1=str2num(a1)
a2=get(handles.y1,'string')
a2=str2num(a2)
b1=get(handles.x2,'string')
b1=str2num(b1)
b2=get(handles.y2,'string')
b2=str2num(b2)
rx1=(a1*b1)+(a2*b2)
ry1=(a1*b2)+(a2*b1)
set(handles.rx,'string',rx1)
set(handles.ry,'string',ry1)
% Hint: get(hObject,'Value') returns toggle state of producto

% --- Executes on button press in salir.


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

% --- Executes on button press in norma.


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

% Hint: get(hObject,'Value') returns toggle state of norma

% --- Executes on button press in conj.


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

% Hint: get(hObject,'Value') returns toggle state of conj


% --- Executes on button press in graf.
function graf_Callback(hObject, eventdata, handles)
% hObject handle to graf (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of graf

5. Integración de un función compleja

%integracion compleja para cualquier función


clc, clear all;
syms t;
p=0;

fprintf('\t \t Cálculo de una Integral Compleja\n\n');

while(p ~= 2)
fprintf('\tMenú:\n 1.- Calcular\n 2.- Salir\n')
op=input('Seleccione una opción: ','s');
if((op>47 & op<58) & op~=105 & op~=106)
p=str2double(op);
end

switch p
case 1
z=input('Ingrese la curva C parametrizada z(t)=x(t)+jy(t):
');
disp(z)

dzt=diff(z,t);
fprintf('La diferencial de la curva es:\n');
disp(dzt)

fzt=input('Ingrese la Función f(z) a Integrar: ');


li=input('Ingrese el límite inferior de la integral: ');
ls=input('Ingrese el límite superior de la integral: ');

fz1=fzt*dzt;
sol=int(fz1,t,li,ls);
fprintf('El resultado de la integral es:\n');
disp(sol);
pause;

case 2
fprintf('\n\tFIN DEL PROGRAMA\n\n');

otherwise
fprintf('\tOPCIÓN INCORRECTA\n\n');
end
end
6. Grafica de una función exponencial

Grafica de la función exponencial


clc, clear all;
syms x;
p=0;
while(p~=2)
fprintf('\t\tGráfica de la Función
Exponencial\n\n');
fprintf('\tMenú:\n 1.- Graficar \n 2.-
Salir\n')
op=input('Seleccione una opción: ','s');
if((op>47 & op<58) & op~=105 & op~=106)
p=str2double(op);
end
switch p
case 1
t=input('Ingrese el número de términos
de la serie: ','s');
if((t>47 & t<58))
v=str2double(t);
end
r=0;
for n=0:v-1
ex=(x^n)/factorial(n);
r=r+ex;
fplot(r,'b','linewidth',3),
title('Gráfica de la Serie de Potencia de la
Función Exponencial');
end
fprintf('La serie resultante es:\n');
pretty(r);
pause;
case 2
fprintf('\n\tFIN DEL PROGRAMA\n\n');
otherwise
fprintf('\tOPCIÓN INCORRECTA\n\n');
end
end

You might also like