Está en la página 1de 25

UNIVERSIDAD NACIONAL DEL CENTRO DEL PERÚ

“AÑO DE LA DIVERSIFICACION PRODUCTIVA Y DEL


FORTALECIMIENTO DE LA EDUCACIÓN”

E.P.I.Q.A. - E.P.I.Q.G.N.E.

EJERCICIOS DE MATLAB

ASIGNATURA : LENGUAJE DE PROGRAMACION

CATEDRÀTICO : ING.Helmer Lopez

INTEGRANTE :
Curi Gutierrez Keithy (IQGNE)

FECHA : 23 de Junio del 2016

HUANCAYO-PERU
2016
clc
c=0
disp('========================')
disp(' CONTADOR')
disp('========================')
for n=1:10
c=c+1;
disp(c)
end

c=

========================

CONTADOR

========================

10
clc
c=0;
s=0;
disp('=================')
disp('CONTADOR ACUMULADOR')
disp('====================')
for n=1:10 % for es el bucle
c=c+1; % c es el contador
s=s+n; % s es el acumulador
disp([c s])
end

=================

CONTADOR ACUMULADOR

====================

1 1

2 3

3 6

4 10

5 15

6 21

7 28

8 36

9 45

10 55

>>
%programa para determinar el numero de divisores
clc
n=input('ingrese valor:');
c=0;%contador para el numero de divisores
for g=(1:n);
if mod(n,g)==0%bucle solo para resto 0
d=n;
c=c+1;
end
end
'el numero de divisores es '
disp([c])
ingrese valor:7

ans =

el numero de divisores es

%programa para convertir de grados celsius a grados kelvin


clc
n=input('ingrese n:');%grados celsius
d=n-5;
for n=d:n+5;
kelvin=n+273;%grados kelvin
disp([n kelvin])
end

ingrese n:10

5 278

6 279

7 280

8 281

9 282

10 283

11 284
12 285

13 286

14 287

15 288
%programa para hallar la grafica de cualquier ecuacion ecuacion con una
%sola variable
clc
x=linspace(-10,10,200);
a=input('ingrese
ecuacion :','s')
fplot(a,[-100 100])

ingrese ecuacion :x^2-5

a=

x^2-5

%programa para ordenar 3 numeros en forma ascendente


clc
n1=input('ingrese el primer numero:');
n2=input('ingrese el segundo numero:');
n3=input('ingrese el tercer numero:');
if n1~= n2 & n2 ~= n3;%restriccion para numeros iguales
if n1>=n2 & n2>=n3;
disp([n3 n2 n3])
end
if n1>=n2 & n3>=n2 &n1>=n3;
disp([n2 n3 n1])
end
if n2>=n1 & n1>=n3;
disp([n3 n1 n2])
end
if n2>=n1 & n3>=n1 & n2>=n3;
disp([n1 n3 n2])
end
if n3>=n1 & n1>=n2;
disp([n2 n1 n3])
end
if n3>=n1 & n2>=n1 & n3>=n2;
dis([n1 n2 n3])
end
else
disp([n1 n2 n3])%en caso contrario si son iguales
end

ingrese el primer numero:45

ingrese el segundo numero:15

ingrese el tercer numero:13

13 15 13
%programa que ejecuta sentencias con valores de :x de 1 hasta 9.
for x=1:2:9
y=x.^2-1;
disp([x,y]);
end

1 0

3 8

5 24

7 48

9 80

%programa que ejecuta sentencias con valores de :x de 1 hasta 9.


clear all
clc
for n=1:5
x(n)=sin(n*pi/10)
end

x=

0.3090

x=

0.3090 0.5878
x=

0.3090 0.5878 0.8090

x=

0.3090 0.5878 0.8090 0.9511

x=

0.3090 0.5878 0.8090 0.9511 1.0000

clc
clear memory
clf
disp('=================================================================='
)
disp(' PROGRAMA ecuacion lineal vs temperatura ')
disp('=================================================================='
)
x=input('ingrese las observaciones de tiempo tomadas en minutos ejemplo:
[0,1,3,5,6,9]:');
y=input('ingrese las temperaturas tomadas en las observaciones ejemplo:
[0,10,15,25,35,40,68,74,89,91,102,115,130,]:');
coef=polyfit(x,y,1)
a=coef(1);
b=coef(2);
y=a.* x + b;
'holdon'
grid
plot (x, y, x, y,'r*'), title('grafico de la ecuacion
y=4.4643*x+2.9762:')
xlabel ('TIEMPO EN minutos')
ylabel ('TEMPERATURA')
disp('ejecutando el programa')
fprintf('la ecuacion es :')
disp([num2str(a) '*x+' num2str(coef(2))])

==================================================================

PROGRAMA ecuacion lineal vs temperatura

==================================================================

ingrese las observaciones de tiempo tomadas en minutos ejemplo:[0,1,3,5,6,9]:[0,1,3,5,6,9]


ingrese las temperaturas tomadas en las observaciones ejemplo:
[0,10,15,25,35,40,68,74,89,91,102,115,130,]:[0,10,15,25,35,40]

coef =

4.4643 2.9762

ans =

holdon

ejecutando el programa

la ecuacion es :4.4643*x+2.9762

clc,clear all
n=input('ingrese el numero de datos:');
s=0;
c=0;
for y=1:n
'holdon';'gridon'
c=c+1;
m=input('ingrese la temperatura:');
s=s+m;
plot(y,m,'r*')
title('CONTADOR VS TEMPERATURA')
xlabel('CONTADOR')
ylabel('TEMPERATURA')
end
disp('===========================')
disp('CONTADOR ACUMULADO')
disp('===========================')
disp([c s])

ingrese el numero de datos:10


ans =

gridon

ingrese la temperatura:8

ans =

gridon

ingrese la temperatura:10

ans =

gridon

ingrese la temperatura:14

ans =

gridon

ingrese la temperatura:17

ans =

gridon

ingrese la temperatura:20

ans =

gridon
ingrese la temperatura:25

ans =

gridon

ingrese la temperatura:33

ans =

gridon

ingrese la temperatura:48

ans =

gridon

ingrese la temperatura:70

ans =

gridon

ingrese la temperatura:100

===========================

CONTADOR ACUMULADO

===========================

10 345
clc
clear memory
clf
disp('================================================================')
disp(' PROGRAMA ecuacion cuadratica vs temperatura ')
disp('================================================================')
x=input('ingrese las observaciones de tiempo tomadas en minutos ejemplo:
[0,1,3,5,6,9]:');
y=input('ingrese las temperaturas tomadas en las observaciones ejemplo:
[0,10,15,25,35,40,68,74,89,91,102,115,130,]:');
coef=polyfit(x,y,2)
a=coef(1);
b=coef(2);
c=coef(3);
y=a.* x.^2 + b*x+c;
'holdon'
grid
plot (x, y, x, y,'r*'), title('grafico de la ecuacion y=-
0.19765*^2+6.1937*x+1.0656:')
xlabel ('TIEMPO EN minutos')
ylabel ('TEMPERATURA')
disp('ejecutando el programa')
fprintf('la ecuacion es :')
disp([num2str(a) '*x^2+' num2str(b) '*x+' num2str(c) ''])
================================================================

PROGRAMA ecuacion cuadratica vs temperatura

================================================================

ingrese las observaciones de tiempo tomadas en minutos ejemplo:[0,1,3,5,6,9]:[0,1,3,5,6,9]

ingrese las temperaturas tomadas en las observaciones ejemplo:


[0,10,15,25,35,40,68,74,89,91,102,115,130,]:[0,10,15,25,35,40]

coef =

-0.1977 6.1937 1.0656

ans =

holdon

ejecutando el programa

la ecuacion es :-0.19765*x^2+6.1937*x+1.0656

>>
clc
clear memory
clf
disp('================================================================')
disp(' PROGRAMA ecuacion cubica vs temperatura ')
disp('================================================================')
x=input('ingrese las observaciones de tiempo tomadas en minutos ejemplo:
[0,1,3,5,6,9]:');
y=input('ingrese las temperaturas tomadas en las observaciones ejemplo:
[0,10,15,25,35,40,68,74,89,91,102,115,130,]:');
coef=polyfit(x,y,3)
a=coef(1);
b=coef(2);
c=coef(3);
d=coef(4);
y=a.* x.^3 + b*x.^2+c.*x+d;
'holdon'
grid
plot (x,y, x, y,'r*'), title('grafico de la ecuacion cubica es :-
0.04645x^3+ 0.44298* x^2+ 4.0488*x+ 1.9166:')
xlabel ('TIEMPO EN minutos')
ylabel ('TEMPERATURA')
disp('ejecutando el programa')
fprintf('la ecuacion es :')
disp([num2str(a) 'x^3+ ' num2str(coef(2)) '*x^2+' num2str(coef(3)) '*x+'
num2str(coef(4))])

================================================================

PROGRAMA ecuacion cubica vs temperatura

================================================================

ingrese las observaciones de tiempo tomadas en minutos ejemplo:[0,1,3,5,6,9]:[0,1,3,5,6,9]


ingrese las temperaturas tomadas en las observaciones ejemplo:
[0,10,15,25,35,40,68,74,89,91,102,115,130,]:[0,10,15,25,35,40]

coef =

-0.0465 0.4430 4.0488 1.9166

ans =

holdon

ejecutando el programa

la ecuacion es :-0.04645x^3+ 0.44298*x^2+4.0488*x+1.9166

>>

clc
clear memory
clf
syms x y z t
disp('------------------------------------------------------------------'
)
disp('-* PROGRAMA PARA HALLAR LA ECUACION DE LA VELOCIDAD*-')
disp('------------------------------------------------------------------'
)
d=input('INGRESE LA ALTURA DE LA TORRE (p):');
ve=input('INGRESE LA VELOIDAD (p/s):');
f=input('INGRESE LA FUNCION DE LA ACELERACION (p/s^2) =','s');
a=input('INGRESE EL LIMITE INFERIOR:');
b=input('INGRESE EL LIMITE SUPERIOR:');
A=input('f,a,b');
qw='eval(A)';
disp('LA PRIMERA INTEGRAL ES :');
disp(A)
v=ve+ A;
disp('PASAMOS A SUMAR LA VELOCIDAD Y NOS DE LA ECUACION DE LA
VELOCIDAD:');
disp(v);
disp('------------------------------------------------------------------'
);
disp('-*PROGRAMA PARA HALLAR LA ECUACION DEL RECORRIDO INTEGRAMOS DE
NUEVO*-')
disp('------------------------------------------------------------------'
)
a=input('ingrese el limite inferior :');
b=input('ingrese el limite superior:');
B=input('A+ve,a,b');
qw='eval(B)';
disp('LA INTEGRAL ES de:');
disp(B)
v=B+d;
disp('PASAMOS A SUMAR LA ALTURA Y OBTENEMOS LA ECUACION DE LA
DISTANCIA');
disp(v);
disp('B) LA PELOTA ALCANZA SU ALTURA MAXIMA CUANDO V=0 Y OBTENEMOS EL
TIEMPO EN SEGUNDOS')
disp('40-32.2t=0')
disp('CON ESTA ECUACION OBTENEMOS EL VALOR DE t')
h=32.2;
H=h/2
D=ve/h;
disp(D)
disp('REMPLAZAMOS t EN LA ECUACION DEL RECORRIDO Y HALLAMOS LA ALTURA
MAXIMA EN PIES')
W=60-D*(16.1*D-40);
disp(W)
disp('C)TIEMPO EN QUE LA PELOTA TOCA EL SUELO EL RECORRIDO ES IGUAL A
0:');
disp(v)
disp('CON ESTO OBTENEMOS DOS RAICES QUE NOS DARAN EL TIEMPO EN EL QUE
OCURRE ESTO :');
t1=(-ve+sqrt(ve^2-4*-H*60))/(-h);
t2=(-ve-sqrt(ve^2-4*-H*60))/(-h);
disp('el tiempo t1 si es positivo vale :');
disp(t1);
disp(' el tiempo t2 si es positivo vale :');
disp(t2);
disp('REEMPLAZAMOS LA RAIZ POSITIVA EN LA ECUACION Y NOS DARA EL VALOR DE
LA VELOSCIDAD (p/s) :');
disp(v)
S=ve-h*t2;
disp(S)
for t=0:35;
ve=40-32.2.*t;
s=60+40.*t-16.1.*t.^2;
figure(1)
plot(t,ve,'o')
title('GRAFICO 1')
xlabel('TIEMPO')
ylabel('VELOCIDA')
hold off
hold on
figure(2)
plot(t,s,'+')
title('GRAFICO 2')
xlabel('TIEMPO')
ylabel('DISTANCIA')
hold off
hold on
end

------------------------------------------------------------------

-* PROGRAMA PARA HALLAR LA ECUACION DE LA VELOCIDAD*-

------------------------------------------------------------------

INGRESE LA ALTURA DE LA TORRE (p):15

INGRESE LA VELOIDAD (p/s):16

INGRESE LA FUNCION DE LA ACELERACION (p/s^2) =3

INGRESE EL LIMITE INFERIOR:25

INGRESE EL LIMITE SUPERIOR:26

f,a,b

LA PRIMERA INTEGRAL ES :

PASAMOS A SUMAR LA VELOCIDAD Y NOS DE LA ECUACION DE LA VELOCIDAD:

------------------------------------------------------------------

-*PROGRAMA PARA HALLAR LA ECUACION DEL RECORRIDO INTEGRAMOS DE NUEVO*-

------------------------------------------------------------------

ingrese el limite inferior :28

ingrese el limite superior:29

A+ve,a,b

LA INTEGRAL ES de:

PASAMOS A SUMAR LA ALTURA Y OBTENEMOS LA ECUACION DE LA DISTANCIA

B) LA PELOTA ALCANZA SU ALTURA MAXIMA CUANDO V=0 Y OBTENEMOS EL TIEMPO EN SEGUNDOS

40-32.2t=0

CON ESTA ECUACION OBTENEMOS EL VALOR DE t

H=

16.1000
0.4969

REMPLAZAMOS t EN LA ECUACION DEL RECORRIDO Y HALLAMOS LA ALTURA MAXIMA EN PIES

75.9006

C)TIEMPO EN QUE LA PELOTA TOCA EL SUELO EL RECORRIDO ES IGUAL A 0:

CON ESTO OBTENEMOS DOS RAICES QUE NOS DARAN EL TIEMPO EN EL QUE OCURRE ESTO :

el tiempo t1 si es positivo vale :

-1.4965

el tiempo t2 si es positivo vale :

2.4903

REEMPLAZAMOS LA RAIZ POSITIVA EN LA ECUACION Y NOS DARA EL VALOR DE LA VELOSCIDAD (p/s) :

-64.1872

clc
clear memory
format bank
'symst'
w=input('ingrese la ecuaionde la tayectoria en funcion de "t"(1.5*t^3-
13.5*t^2+22.5*t)=','s');
a=input('tiempo que se utiliza:');
E=1.5*a^3-13.5*a^2+22.5*a;
F=1.5*(a/6)^3-13.5*(a/6)^2+22.5*(a/6);
G=1.5*(5*a/6)^3-13.5*(5*a/6)^2+22.5*(5*a/6);
fprintf('la distancia ecorida en 6 segundos es.')
disp(['num2srt(E)' 'ft'])
fprintf('si la derivamos la distanciaobtendremos la velocidad que es
iguala :')
a=diff('W','t');
disp(a)
fprintf('si la derivamos la velocidad obtendremos la aceleracion que es
iguala:')
Q=diff('a','t');
disp(Q)
disp('la posicion de la particula en el t=0')
disp(0/E)
disp('la posicion de la particula en el t=1')
disp(F)
disp('la posicion de la partcula en el t=5')
disp(G)
fprintf('la distancia total es :')
disp(['num2srt(F+F+F-G)' -'ft'])
disp('=======================================================')
disp(' tiempo recorrido velocidad
aceleracion ')
disp('===================================================================
=============')

for H=0:0.2:6;
S=1.5*H^3-13.5*H^2+22.5*H;
V=4.5*H^2-27.0*H+22.5;
D=9.0*H-27.0;
disp([H S V D ])
figure (1)%primer grafico
hold on
plot (H,S,'ro')
title('Y=1.5*t^3-13.5*t^2+22.5*t')
xlabel('tiempo (S)')
ylabel(' RECORRIDO(fp)')
hold off
figure(2)%segundo grafico
hold on
plot(H,V,'ro')
title('Y=4.5*t^2-27.0*t+22.5')
xlabel('tiempo (S)')
ylabel('velocidad (fp/s)')
hold off
figure(3)%tercer grafico
hold on
plot(H,D,'ro')
title('y=9.0*t-27.0')
xlabel('tiempo (s)')
ylabel('Aceleracion (fp/s^2)')
hold off
end
ans =

symst

ingrese la ecuaionde la tayectoria en funcion de "t"(1.5*t^3-13.5*t^2+22.5*t)=1.5*t^3-13.5*t^2+22.5*t

tiempo que se utiliza:4

la distancia ecorida en 6 segundos es.num2srt(E)ft

si la derivamos la distanciaobtendremos la velocidad que es iguala :0

si la derivamos la velocidad obtendremos la aceleracion que es iguala:0

la posicion de la particula en el t=0

la posicion de la particula en el t=1

9.44

la posicion de la partcula en el t=5

-19.44

la distancia total es :Warning: Out of range or non-integer values truncated during conversion to character.

num2srt(F+F+F-G)

=======================================================

tiempo recorrido velocidad aceleracion

================================================================================

0 0 22.50 -27.00

0.20 3.97 17.28 -25.20

0.40 6.94 12.42 -23.40


0.60 8.96 7.92 -21.60

0.80 10.13 3.78 -19.80

1.00 10.50 0 -18.00

1.20 10.15 -3.42 -16.20

1.40 9.16 -6.48 -14.40

1.60 7.58 -9.18 -12.60

1.80 5.51 -11.52 -10.80

2.00 3.00 -13.50 -9.00

2.20 0.13 -15.12 -7.20

2.40 -3.02 -16.38 -5.40

2.60 -6.40 -17.28 -3.60

2.80 -9.91 -17.82 -1.80

3.00 -13.50 -18.00 0

3.20 -17.09 -17.82 1.80

3.40 -20.60 -17.28 3.60

3.60 -23.98 -16.38 5.40


3.80 -27.13 -15.12 7.20

4.00 -30.00 -13.50 9.00

4.20 -32.51 -11.52 10.80

4.40 -34.58 -9.18 12.60

4.60 -36.16 -6.48 14.40

4.80 -37.15 -3.42 16.20

5.00 -37.50 0 18.00


PROGRAMAS LP
1. %este programa sirve para hallar el siguiente la siguiente integral
%definida:
disp('=============================================================')
disp('---programa para hallar la integral de sen(lnx)---')
disp('=============================================================')
a=input('ingrese el limite superior:');
b=input('ingrese el limite inferior:');
if a>b
r=cos(log(a))-cos(log(b));
disp('el resultado de la integral es:');
disp(r)
else
r=tan(a)-tan(b);
disp('el resultado de la integral es:')
disp(r)
end

=============================================================

---programa para hallar la integral de sen(lnx)---

=============================================================

ingrese el limite superior:8

ingrese el limite inferior:3

el resultado de la integral es:

-0.9418
2. %PROGRAMA PARA HALLAR DERIVADAS PARCIALES Y SU GRAFICA
disp('=============================================================')
disp('---------obtencion de la derivada---')
disp('---------parcial respecto a x e y---')
disp('=============================================================')
syms x y z
A=input('ingrese la funcion:');
B=diff(A,x)
C=diff(A,y)
disp('la derivada respecto a x es:');
disp(diff(A,x))
disp('la derivada respecto a y es;');
disp(diff(A,y))
subplot(1,2,1),ezplot(z-B)
subplot(1,2,2),ezplot(z-C)

=============================================================
---------obtencion de la derivada---
---------parcial respecto a x e y---
=============================================================
ingrese la funcion:x^2+y^3

B =

2*x

C =

3*y^2

la derivada respecto a x es:


2*x

la derivada respecto a y es;


3*y^2
3. %programa para graficar tiempo espacio ,velocidad,aceleracion
clc
clear all
%x(x)=t^4+2t^2-200
%x=[1 0 2 0 -200]
%polyder(x)
%polyder(x,t)
x=[1 0 2 0 -200]
v=polyder(x);
a=polyder(v);
for t=1;10
m(t)=polyval(x,t);
n(t)=polyval(v,t);
K(t)=polyval(a,t);
hold on;grid on;
subplot(2,2,1);plot(t,m(t),'m*'),title('tiempo-
espacio');xlabel('tiempo');ylabel('espacio');
hold on;grid on;
subplot(2,2,2);plot(t,n(t),'kx'),title('tiempo-
velocidad');xlabel('tiempo');ylabel('velocidad');
hold on;grid on;
end
disp('================================================================')
disp(' Tiempo-espacio-velocidad-aceleracion ')
disp('================================================================')
fpritf('tiempo%d\t');fpritf('%5s\t','');
fpritf('espacio%d\n');fpritf('%5s\t','');
fpritf('velocidad%d\t');fpritf('%5s\t','');
fpritf('aceleracion%s\n','n');
disp('-----------------------------------------')
for h=1:10
fpritf('%s\t','');
fpritf('%d\t',h);
fpritf('%15.of\t',m(h));
fpritf('%15.of\t',n(h))
fpritf('%15.of\t',k(h))
end

x=

1 0 2 0 -200

ans =

10

================================================================

Tiempo-espacio-velocidad-aceleracion

También podría gustarte