Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Ejercicios de Matlab
Ejercicios de Matlab
E.P.I.Q.A. - E.P.I.Q.G.N.E.
EJERCICIOS DE MATLAB
INTEGRANTE :
Curi Gutierrez Keithy (IQGNE)
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
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])
a=
x^2-5
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
x=
0.3090
x=
0.3090 0.5878
x=
x=
x=
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))])
==================================================================
==================================================================
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])
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) ''])
================================================================
================================================================
coef =
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))])
================================================================
================================================================
coef =
ans =
holdon
ejecutando el programa
>>
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
------------------------------------------------------------------
------------------------------------------------------------------
f,a,b
LA PRIMERA INTEGRAL ES :
------------------------------------------------------------------
------------------------------------------------------------------
A+ve,a,b
LA INTEGRAL ES de:
40-32.2t=0
H=
16.1000
0.4969
75.9006
CON ESTO OBTENEMOS DOS RAICES QUE NOS DARAN EL TIEMPO EN EL QUE OCURRE ESTO :
-1.4965
2.4903
-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
9.44
-19.44
la distancia total es :Warning: Out of range or non-integer values truncated during conversion to character.
num2srt(F+F+F-G)
=======================================================
================================================================================
0 0 22.50 -27.00
=============================================================
=============================================================
-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
x=
1 0 2 0 -200
ans =
10
================================================================
Tiempo-espacio-velocidad-aceleracion