Está en la página 1de 44

Instituto Politécnico Nacional

Unidad Profesional Interdisciplinaria en Ingeniería


y Tecnologías Avanzadas

Entrega Actividades
Segundo Departamental

Alvarado Gómez Ricardo

Herramientas Computacionales

1MV3

Prof. Juan Carlos Razo Ruíz

20/10/2019

P á g i n a 1 | 44
Índice
Tarea 3 ……………………………………………………………………………………… 3

Actividad 12 ………………………………………………………………………………. 6

Actividad 13 …………………………………………………………………………… 11

Actividad 14……………………………………………………………………………. 13

Actividad 15 …………………………………………………………………………… 18

Actividad 16 …………………………………………………………………………… 20

Actividad 17…………………………………………………………………………….. 23

Actividad 18…………………………………………………………………………….. 26

Actividad 19…………………………………………………………………………….. 28

Actividad 20…………………………………………………………………………….. 34

Actividad 21…………………………………………………………………………….. 39
P á g i n a 2 | 44
Tarea 3
Ejercicio 1

valorNumero=input('Ingresa un valor numerico: ');


valorPotencia=input('Ingresa un valor exponencial numerico: ');

resultado = (valorNumero.^(1/valorPotencia));
disp(resultado);

Ejercicio 2

valorNumero=input('Ingresa un valor numerico: ');


valorPotencia=input('Ingresa un valor exponencial numerico: ');

resultado = (exp((1/valorPotencia)*log(valorNumero)));
disp(resultado);

P á g i n a 3 | 44
Ejercicio 3

fprintf('\n Este programa obtiene las Funciones


Seno,Coseno,Tangente,Cotangente,Secante,Cosecante de 30°,45° y
60°.\n\n');
Angulo1=30; Angulo2=45; Angulo3=60;
%Ángulos Notables
Sen30=1/2;
Cos30=sqrt(3)/2;
Sen60=Cos30;
Cos60=Sen30;
Tan30=1/sqrt(3);
Tan60=sqrt(3);
Sen45=1/sqrt(2);
Cos45=Sen45;
Tan45=1;
%Cálculo Normal;
Cot30=1/Tan30;
Sec30=1/Cos30;
Csc30=1/Sen30;
Fun30=[Sen30 Cos30 Tan30 Cot30 Sec30 Csc30]
Cot60=1/Tan60;
Sec60=1/Cos60;
Csc60=1/Sen60;
Fun60=[Sen60 Cos60 Tan60 Cot60 Sec60 Csc60]
Cot45=1/Tan45;
Sec45=1/Cos45;
Csc45=1/Sen45;
Fun60=[Sen45 Cos45 Tan45 Cot45 Sec45 Csc45]

P á g i n a 4 | 44
P á g i n a 5 | 44
Actividad 12
Ejercicio 1
>> z=2-3i
z=
2.0000 - 3.0000i
>> U=-1+2i
U=
-1.0000 + 2.0000i
>> real(z)
ans =
2
>> imag(z)
ans =
-3
>> angle(U)
ans =
2.0344
>> abs(U)
ans =
2.2361
>> z+U
ans =
1.0000 - 1.0000i
>> z+U
ans =
1.0 - 1.0000i

Ejercicio 2
>>(2 + 3i) + (2 - (sqrt(2))*(i))
ans =
4.0000 + 1.5858i
>> (3-i)/(4+5i)
ans =
0.1707 - 0.4634i
>> (2-(sqrt(2))*(i))^3
ans =
-4.0000 -14.1421i
>> 2+3i+5-(1/2)*i
ans =
7.0000 + 2.5000i

Ejercicio 3
>> z1=3+4i
z1 =
P á g i n a 6 | 44
3.0000 + 4.0000i
>> z2=4+3i
z2 =
4.0000 + 3.0000i
>> i^2
ans =
-1
>> conj(z1)
ans =
3.0000 - 4.0000i
>> z1*z2
ans =
0.0000 +25.0000i
>> z1/z2
ans =
0.9600 + 0.2800i
>> (z1)^2
ans =
-7.0000 +24.0000i
>> abs(z1)
ans =
5
>> angle(z1)
ans =
0.9273
>> z1polar=abs(z1)*(cos(angle(z1))+i*sin(angle(z1)))
z1polar =
3.0000 + 4.0000i
>> z1exp=abs(z1)*exp(i*angle(z1))
z1exp =
3.0000 + 4.0000i
>> sin(z1)
ans =
3.8537 -27.0168i
>> cos(z1)
ans =
-27.0349 - 3.8512i

P á g i n a 7 | 44
P á g i n a 8 | 44
P á g i n a 9 | 44
P á g i n a 10 | 44
Actividad 13
Ejercicio 1
x=randi([20,200],4,2)
x=
167 134
183 37
42 70
185 118

P á g i n a 11 | 44
Ejercicio 2

importados=xlsread('c:\users\Ricardo AG\Documents\Matriz matlab')


importados =
1.0e+09 *
2.0161 0.0000 0.0000 0.0000
2.0161 0.0000 0.0000 0.0000
2.0141 0.0000 0.0000 0.0000
2.0181 0.0000 0.0000 NaN

P á g i n a 12 | 44
Actividad 14
>> A=[2 3 6 5;0 3 9 5;45 4 -6 8;1 1 2 1]
A=
2 3 6 5
0 3 9 5
45 4 -6 8
1 1 2 1
>> b=[3;8;3;2]
b=
3
8
3
2
>> x=inv(A)*b
x=
0.7228
-1.8812
2.1485
-1.1386
>> A=[3 -6 6;8 8 -1;3 -3 8]
A=
3 -6 6
8 8 -1
3 -3 8
>> b=[20;60;50]
b=
20
60
50
>> x=inv(A)*b
x=
3.0976
5.2862
7.0707
>> A=[1 2 1 4;2 4 2 8;7 4 -2 4;-9 1 2 1]
A=
1 2 1 4
2 4 2 8
7 4 -2 4
-9 1 2 1
>> b=[3;8;3;2]
b=
3
8
3
2
>> x=inv(A)*b

P á g i n a 13 | 44
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND =
6.041356e-18.
x=
1.0e+15 *
-0.7383
-2.5471
-3.1747
2.2518
>> %La matriz es casi singular y una matriz singular no tiene inversa, entonces la operación puede
fallar.
>> A=[1 1 0 3;2 1 -1 1;3 -1 -1 2; -1 2 3 -1]
A=
1 1 0 3
2 1 -1 1
3 -1 -1 2
-1 2 3 -1
>> b=[4;1;-3;4]
b=
4
1
-3
4
>> Ab=[A b]
Ab =
1 1 0 3 4
2 1 -1 1 1
3 -1 -1 2 -3
-1 2 3 -1 4
>> rref(Ab)
ans =
1 0 0 0 -1
0 1 0 0 2
0 0 1 0 0
0 0 0 1 1
>> x=inv(A)*b
x=
-1.0000
2.0000
-0.0000
1.0000
>> x=A\b
x=
-1.0000
2.0000
-0.0000
1.0000

P á g i n a 14 | 44
P á g i n a 15 | 44
P á g i n a 16 | 44
P á g i n a 17 | 44
Actividad 15
S=[1 -2 1 1 0; 3 0 2 -2 0; 0 4 -1 -1 0; 5 0 3 -1 0]
S=
1 -2 1 1 0
3 0 2 -2 0
0 4 -1 -1 0
5 0 3 -1 0
>> rref(S)
ans =
1 0 0 4 0
0 1 0 -2 0
0 0 1 -7 0
0 0 0 0 0
>> %Hay soluciones infinitas que en el último renglón queda 0=0.
>> S=[1 -2 1 1 0; 3 0 2 -1 0; 0 4 -1 -1 0; 5 0 3 -1 0]
S=
1 -2 1 1 0
3 0 2 -1 0
0 4 -1 -1 0
5 0 3 -1 0
>> rref(S)
ans =
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
>> %En el sistema todas las variables tienen una misma solución x1=x2=x3=x4=0.

P á g i n a 18 | 44
P á g i n a 19 | 44
Actividad 16
>> p = [-3 2 -17 0 25 0 ]*19
p=
-57 38 -323 0 475 0
>> polyval(p, [15 17 -5])
ans =
-42443625 -79336875 239875
>> p=[-11 0 0 2 -9]-[0 17 25 -32 0]
p=
-11 -17 -25 34 -9
>> polyval(p,33)
ans =
-13682172
>> [cociente, residuo]=deconv([7 -17 25 0 0],[-6 0])
cociente =
-1.1667 2.8333 -4.1667 0
residuo =
0 0 0 0 0
>> polyval(cociente,magic(3))
ans =
-449.3333 -2.5000 -175.0000
-18.5000 -95.8333 -290.5000
-46.0000 -658.5000 -6.3333
>> polyval(conv([6 -1 7 -12 6 -3],[0 0 6 2 12 7]),[-9 -6 -3 0 3 6 9])
ans =
1.0e+09 *
1.5828 0.0644 0.0003 -0.0000 0.0003 0.0672 1.6368
>> polyder([6 1 -2 5 -2])
ans =
24 3 -4 5
>> polyval(ans, -5)
ans =
-2900
>> polyint([6 5 -4 -2],3)
ans =
1.5000 1.6667 -2.0000 -2.0000 3.0000
>> polyval(ans,[2 4 6 8 10 12 14 16 18])
ans =
1.0e+05 *
0.0003 0.0045 0.0222 0.0686 0.1645 0.3367 0.6178 1.0459 1.6650

P á g i n a 20 | 44
P á g i n a 21 | 44
P á g i n a 22 | 44
Actividad 17
Ejercicio 1
disp('Dime tu edad y yo te recomendaré una película. \n\n');
Edad=input('Ingrese su edad: ');
if(Edad<4)
disp('Le recomiendo ver Buscando a Nemo');
elseif (Edad>=5 & Edad<16)
disp('Le recomiendo ver Toy Story');
elseif (Edad>=16 & Edad<28)
disp('Le recomiendo ver Harry Potter');
elseif (Edad>=28 & Edad<40)
disp('Le recomiendo ver Infinity War');
elseif (Edad>=40 & Edad<60)
disp('Le recomiendo ver Star Wars');
elseif (Edad>=60)
disp('Le recomiendo ver El Padrino');
end

Ejercicio 2
fprintf('Matriz aleatoria de 3x3.\n\n');
A=round(rand(3)*100);
disp(A);
D=sum(diag(A));
Ad=sum(diag(fliplr(A)));
fprintf(' Suma de diagonal: %d.',D);
fprintf('\n Suma de antidiagonal: %d.\n',Ad);
if(D>Ad)
fprintf('\n La Diagonal es mayor.');
elseif(Ad>D)

P á g i n a 23 | 44
fprintf('\n La Antidiagonal es mayor.');
else
fprintf('\n La Antidiagonal y la Diagonal son iguales.');
end;
fprintf('\n');
Tri=tril(A);
Stri=triu(A);
for i=1:3
for j=1:3
if(Tri(i,j)==0)
Tri(i,j)=1;
end
if(Stri(i,j)==0)
Stri(i,j)=1;
end
end
end
PT=prod(prod(Tri));
PsT=prod(prod(Stri));
format long;
fprintf('\n El producto del triángulo inferior es: %d.',PT);
fprintf('\n El producto del triángulo superior es: %d.\n',PsT);
if(PT>PsT)
fprintf('\n El triángulo inferior es mayor.');
elseif(PsT>PT)
fprintf('\n El triángulo superior es mayor.');
else
fprintf('\n El triángulo inferior y superior son iguales.');
end;
fprintf('\n');

P á g i n a 24 | 44
P á g i n a 25 | 44
Actividad 18
Ejercicio 1

fprintf('\n Este programa genera un vector con números pares de n


elementos positivos.\n\n');
V=[];
Elementos=input('Hasta que numero desea que llegue su vector: ');
x=1;
PoP=mod(Elementos,2);
if (PoP==0)
while(2*x<=Elementos)
V(1,x)=2+2*(x-1);
x=x+1;
end
else
while(2*x<=(Elementos-1))
V(1,x)=2+2*(x-1);
x=x+1;
end
end
fprintf('\n Su vector es: \n');
disp(V);

Ejercicio 2
fprintf('\n Este programa genera un vector que va de 1 a 45325 y muestra
su suma.\n');
Data=[1:45325];
%disp(Data);
x=1;
Suma=0;
P á g i n a 26 | 44
while(x~=45326)
Suma=Suma+Data(1,x);
x=x+1;
end
fprintf('\n La suma vector es: %d\n',Suma);

P á g i n a 27 | 44
Actividad 19
Ejercicio 1

fprintf('\n Este programa genera un vector con números primos de n


elementos positivos.\n\n');
V=[2];
Elementos=input('Hasta que numero desea que llegue su vector: ');
x=0;

for(i=2:Elementos)
for(j=(i-1):-1:2)
if (mod(i,j)==0)
break;
else
if(j==2)
V=[V,i];
end
end
end
end
fprintf('\n Su vector es: \n');

Ejercicio 2

fprintf('\n Este programa genera la tabla de multiplicar decualquier


número: .\n\n');
Num=input('Cual tabla desea: ');
fprintf('\n');
for (x=1:Num)
Mult=Num*x;

P á g i n a 28 | 44
fprintf('%d x %d = %d\n',Num,x,Mult);
end

P á g i n a 29 | 44
Ejercicio 3

fprintf('\n Este programa genera la tabla de multiplicar de cualquier


número: .\n\n');
Num=input('Cual tabla desea: ');
T=zeros(Num);
fprintf('\n');
for x=1:Num
for y=1:Num
T(x,y)=(x*y);
end
end
disp(T);

P á g i n a 30 | 44
Ejercicio 4
fprintf('\n Este programa genera un vector factorial.\n\n');
N=input('Hasta que número desea que llegue el vector: ');
Vect=[1:N]
Fact=[];
format long;
for (x=1:N)
Dat=1;
for (i=Vect(1,x):-1:1)
Dat=Dat*i;
P á g i n a 31 | 44
end
Fact(1,x)=Dat;
end
Fact

P á g i n a 32 | 44
P á g i n a 33 | 44
Actividad 20
Ejercicio 1

fprintf('\n Este programa genera una matriz de MxN introducida por el


usuario.\n\n');
MA=input(' ¿Su matriz es cuadrada (Sí=1/No=0)? R: ');
fprintf('\n');
Mat=[];
if(MA==1)
Orden=input('¿De que orden? R: ');
fprintf('\n Por favor introduzca los valores de la matriz: \n');
for(x=1:Orden)
for(y=1:Orden)
fprintf('Dato (%d,%d): ',x,y);
Mat(x,y)=input('');
end
end
Mat
elseif(MA==0)
Filas=input('¿De cuántas filas? R: ');
Columnas=input('¿De cuántas columnas? R: ');
fprintf('\n Por favor introduzca los valores de la matriz: \n');
for(x=1:Filas)
for(y=1:Columnas)
fprintf('Dato (%d,%d): ',x,y);
Mat(x,y)=input('');
end
end
Mat
end

P á g i n a 34 | 44
Ejercicio 2

clear;
fprintf('\n Este programa puede multiplicar dos matrices de cualquier
orden: .\n\n');
MatA=input('Introduzca la matriz A con formato [X X;X X]: ');
MatA
MatB=input('Introduzca la matriz B con formato [X X;X X]: ');
MatB
[RenA,ColA]=size(MatA);
[RenB,ColB]=size(MatB);
FlagR=0;FlagC=0;
if (RenA==RenB && ColA==ColB)
Mult=MatA.*MatB;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
elseif (RenA>=RenB && ColA>=ColB)
Mult=zeros(RenA,ColA);
if (RenA==RenB && ColA~=ColB)
FlagR=1;
elseif (RenA~=RenB && ColA==ColB)
FlagC=1;
end
for (x=1:RenB)
for (y=1:ColB)
Mult(x,y)=MatA(x,y)*MatB(x,y);
end
end
if(FlagR==1 && FlagC==0)
for(x=1:RenB)
for(y=(ColB+1):ColA)
Mult(x,y)=MatA(x,y);
end

P á g i n a 35 | 44
end
elseif(FlagR==0 && FlagC==1)
for(x=(RenB+1):RenA)
for(y=1:ColA)
Mult(x,y)=MatA(x,y);
end
end
elseif(FlagR==0 && FlagC==0)
for(x=1:RenA)
for(y=(ColB+1):ColA)
Mult(x,y)=MatA(x,y);
end
end
for(x=(RenB+1):RenA)
for(y=1:ColA)
Mult(x,y)=MatA(x,y);
end
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
elseif (RenA>=RenB && ColA<ColB)
Mult=zeros(RenA,ColB);
if (RenA==RenB && ColA~=ColB)
FlagR=1;
end
for (x=1:RenB)
for (y=1:ColA)
Mult(x,y)=MatA(x,y)*MatB(x,y);
end
end
if (FlagR==1)
for(x=1:RenA)
for(y=(ColA+1):ColB)
Mult(x,y)=MatB(x,y);
end
end
else
for(x=(RenB+1):RenA)
for(y=1:ColA)
Mult(x,y)=MatA(x,y);
end
end
for(x=1:RenB)
for(y=(ColA+1):ColB)
Mult(x,y)=MatB(x,y);
end
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
elseif (RenA<RenB && ColA>=ColB)
B=[MatA];C=[MatB];MatA=[C];MatB=[B];
[RenA,ColA]=size(MatA);
[RenB,ColB]=size(MatB);
Mult=zeros(RenA,ColB);
if (RenA==RenB && ColA~=ColB)
FlagR=1;
end
P á g i n a 36 | 44
for (x=1:RenB)
for (y=1:ColA)
Mult(x,y)=MatA(x,y)*MatB(x,y);
end
end
if (FlagR==1)
for(x=1:RenA)
for(y=(ColA+1):ColB)
Mult(x,y)=MatB(x,y);
end
end
else
for(x=(RenB+1):RenA)
for(y=1:ColA)
Mult(x,y)=MatA(x,y);
end
end
for(x=1:RenB)
for(y=(ColA+1):ColB)
Mult(x,y)=MatB(x,y);
end
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
else
B=[MatA];C=[MatB];MatA=[C];MatB=[B];
[RenA,ColA]=size(MatA);
[RenB,ColB]=size(MatB);
Mult=zeros(RenA,ColA);
if (RenA==RenB && ColA~=ColB)
FlagR=1;
elseif (RenA~=RenB && ColA==ColB)
FlagC=1;
end
for (x=1:RenB)
for (y=1:ColB)
Mult(x,y)=MatA(x,y)*MatB(x,y);
end
end
if(FlagR==1 && FlagC==0)
for(x=1:RenB)
for(y=(ColB+1):ColA)
Mult(x,y)=MatA(x,y);
end
end
elseif(FlagR==0 && FlagC==1)
for(x=(RenB+1):RenA)
for(y=1:ColA)
Mult(x,y)=MatA(x,y);
end
end
elseif(FlagR==0 && FlagC==0)
for(x=1:RenA)
for(y=(ColB+1):ColA)
Mult(x,y)=MatA(x,y);
end
end
P á g i n a 37 | 44
for(x=(RenB+1):RenA)
for(y=1:ColA)
Mult(x,y)=MatA(x,y);
end
end
end
end
Mult

P á g i n a 38 | 44
Actividad 21
Ejercicio 1

function [Suma] = SumaPosNeg(Arg)


%UNTITLED5 Summary of this function goes here
% Detailed explanation goes here
SPositivos=0; SNegativos=0;

[Ren,Col]=size(Arg);
for (x=1:Ren)
for (y=1:Col)
if (Arg(x,y)>0)
SPositivos=SPositivos+Arg(x,y);
elseif (Arg(x,y)<0)
SNegativos=SNegativos+Arg(x,y);
else
return;
end
end
end
Suma=[SPositivos,SNegativos]
End

Ejercicio 2

function [ Serie ] = FibonacciS( Terminos )


%UNTITLED Summary of this function goes here
% Detailed explanation goes here
Serie=[1,1];
x=1;
y=1;
P á g i n a 39 | 44
Valor=0;
for X=3:(Terminos+1)
Valor=x+y;
Serie(1,X)=Valor;
x=y;
y=Valor;
end
end

Ejercicio 3

function [ Binaria ] = Binariza( A,Umbral )


%UNTITLED3 Summary of this function goes here
% Detailed explanation goes here
Binaria=A;
[Fila,Columna]=size(A)
for x=1:Fila
for y=1:Columna
if (Binaria(x,y)>=Umbral)
Binaria(x,y)=0;
else
Binaria(x,y)=1;
end
end
end

end

P á g i n a 40 | 44
P á g i n a 41 | 44
Ejercicio 4

function [ Energia ] = TotalEnergy( Vect )


%UNTITLED5 Summary of this function goes here
% Detailed explanation goes here
E=Vect.^2;
Energia=sum(E);

end

Ejercicio 5

function [ IMCout ] = IMC( varargin )


%UNTITLED Summary of this function goes here
% Detailed explanation goes here
format bank;
format short;
IMCout=[];
L=nargin;
for x=1:L
z=varargin{x};
Altura=z(1,1);
Peso=z(1,2);
IndMC=Peso/(Altura^2);
IMCout(1,x)=IndMC;
fprintf('Su IMC de la persona %d es: %d ',x,IndMC);
if (IndMC<=18.5)
fprintf('por lo tanto esta bajo de Peso.\n');
elseif(18.5<IndMC && IndMC<25)
fprintf('por lo tanto esta bien de Peso.\n');
elseif(25<=IndMC && IndMC<30)
P á g i n a 42 | 44
fprintf('por lo tanto tine sobrepeso.\n');
elseif(IndMC>=30)
fprintf('por lo tanto padece obesidad.\n');
end
end

end

Ejercicio 6

function [ varargout ] = IMCvariante()


%UNTITLED4 Summary of this function goes here
% Detailed explanation goes here

for x=1:nargout
fprintf('\n\n');
Altura=input('Introduzca la Altura(m): ');
Peso=input('Indroduzca el Peso(kg): ');
IMCs=Peso/(Altura^2);
varargout{x}=IMCs;
end

end

P á g i n a 43 | 44
Conclusión.

Gracias a estas actividades pude aprender más de la programación en Matlab para poder
contestar problemas numéricos empleando fórmulas u otros métodos como matrices que
habíamos visto con anterioridad en la clase. A pesar de que la programación sea básica se
pueden resolver problemas de diferentes áreas y comunes como el cálculo del índice de
masa corporal.

Además, la creación de funciones nos permite trabajar de manera más sencilla en el


command window y evitar hacer tantas operaciones para ahorrar tiempo. Es importante
conocer el lenguaje en c ya que para programar en Matlab es muy parecido.

P á g i n a 44 | 44

También podría gustarte