Académique Documents
Professionnel Documents
Culture Documents
Ecuacion diferencial
dy
5 4y 2
dx
condición inicial:
y(0) =1
Procedimiento
1) Escribir en el editor un archivo .m
function dy=g2(x,y)
dy=(2-4*y)/5;
[x,y1]=ode45('g2',0,10,1);
y graficar con:
subplot(2,1,1),plot(x,y1,x,y,'o'),title('solucion de la ecuacion'),...
xlabel('x'),ylabel('y'),grid
[x,y1]=ode45('g2',0,10,1);
y=(1/2)+(1/2)*exp(-0.8*x);
subplot(2,1,1),plot(x,y1,'*',x,y,'o'),title('solucion de la
ecuacion'),...
xlabel('x'),ylabel('y'),grid
0.95
0.9
0.85
0.8
0.75
y
0.7
0.65
0.6
0.55
0.5
0 1 2 3 4 5 6 7 8 9 10
x
1000
800
600
y
400
200
-200
0 1 2 3 4 5 6 7 8 9 10
x
dy
2. 0.13 y
dx
solucion de la ecuacion
1
0.9
0.8
0.7
0.6
y
0.5
0.4
0.3
0.2
0 1 2 3 4 5 6 7 8 9 10
x
soluciones analíticas
y x 3 7.5
y e 0.13 x
Es una instrucción de selección que permite probar una condición para determinar que
pasos se ejecutaran a continuación.
if expresión lógica
instrucciones
end
ejemplo
a>b
b==c | b== 5.5
EjercicioA
%instruccionIF
g = input('escriba un número entre 30 y 70, g = ');
if g<50
%graficar la figura1
x=1:10;
subplot(2,1,1),plot(x.^2),title('figura 1')
end
%graficar la figura2
y=0.5:0.1:2.5;
subplot(2,1,2),plot(y.^(1/2)),title('figura 2')
figura 1
100
50
0
1 2 3 4 5 6 7 8 9 10
figura 2
2
1.5
0.5
0 5 10 15 20 25
Ejercicio B
%ifanidada
g = input('escriba un número entre 30 y 70, g = ');
a = input('escriba un número entre 30 y 70, a = ');
if g<50
%graficar la figura1
x=1:10;
subplot(2,1,1),plot(x.^2),title('figura 1')
if a>g
%graficar la figura2
y=0.5:0.1:2.5;
subplot(2,1,2),plot(y.^(1/2)),title('figura 2')
end
end
50
0
1 2 3 4 5 6 7 8 9 10
figura 2
2
1.5
0.5
0 5 10 15 20 25
Ejercicio C
% if y else if
temperatura = input('ingrese temperatura entre 30 y 120, temperatura
= ');
if temperatura > 100;
disp('Demasiado caliente- falla de equipo')
elseif temperatura > 90;
disp('intervalo operativo normal')
elseif temperatura >50;
disp('temperatura por debajo del intervalo operativo deseado')
else
disp('demasiado frio - apagar equipo')
end
>> sol
ingrese temperatura entre 30 y 120, temperatura = 120
Demasiado caliente- falla de equipo
>> sol
ingrese temperatura entre 30 y 120, temperatura = 90
temperatura por debajo del intervalo operativo deseado
>> sol
ingrese temperatura entre 30 y 120, temperatura = 40
demasiado frio - apagar equipo