Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Alumno
Luis Fernando Cogollo Cavadia
Profesor:
Abraham Jose Arenas Tawil
Doctor en Matemáticas
Análisis Numérico
1
Utilice el método de Euler para aproximar la solu-
ción de los siguientes PVI en el intervalo indicado:
Ejercicio 0.1
y 0 = −et y, [0, 1], y(0) = 3 con N = 10
Solución:
function fl
clc
close all
clear all;
format long;
global h1 h2 h3
%tamaño de paso
h1=0.1;
%h2=0.2;
%h3=0.3;
%tic
%initial conditions
y0=3;
% calculodel numero de iteraciones para cada h
maximoeuler1=(tfinal-tinicial)/h1;
%maximoeuler2=(tfinal-tinicial)/h2;
%maximoeuler3=(tfinal-tinicial)/h3;
x0euler1=y0;
x0euler2=y0;
x0euler3=y0;
%software de comparación
tic
[t1,Y1] = ode45(@fode45,[tinicial,tfinal],y0);
toc
tic
for m =1:maximoeuler1
x1euler1(m)=x0euler1+h1*f1(m*h1,x0euler1);
x0euler1=x1euler1(m);
vteuler1(m)=h1*m;
2
end
toc
tic
%for m =1:maximoeuler2
%k12= h2*f1(m*h2,x0euler2);
%x1euler2(m)=x0euler2+k12;
%x0euler2=x1euler2(m);
%vteuler2(m)=h2*m;
%end
toc
tic
%for m =1:maximoeuler3
%k13= h3*f1(m*h3,x0euler3);
%x1euler3(m)=x0euler3+k13;
%x0euler3=x1euler3(m);
%vteuler3(m)=h3*m;
%end
toc
% %euler implicito
%
% x0euleri=x0;
% tic
% for n=1:maximoeuler
%
% auxiliar1=x0euleri+h*f1(n*h,x0euleri);
%
% xeuler2(n)=x0euleri+h*f1(n*h,auxiliar1);
%
% x0euleri=xeuler2(n);
%
% %--------------------------------------------------
% vteuleri(n)=h*n;
%
% % --------------------------------------------------
%
% end
% toc
% x0euleri=x0;
% tic
% for n=1:maximoeuler
%
% auxiliar2=x0euleri+h*f1(n*h,x0euleri);
%
% crank(n)=x0euleri+0.5*h*(f1(n*h,x0euleri)+f1((n+1)*h,auxiliar2));
%
3
% x0euleri=crank(n);
%
% %--------------------------------------------------
% vtcrank(n)=h*n;
%
% % --------------------------------------------------
%
% end
% toc
% plot(t1,Y1(:,1),’k.’,vteuler,x1euler,’r’,vteuleri,xeuler2,’b’,vtcrank,crank,’g’)
plot(t1,Y1(:,1),’k’,vteuler1,x1euler1,’r.’)
ylabel(’x(t) La solución aproximada’)
xlabel(’t Tiempo de cálculo’)
legend(’EDO’,’Método de Euler h_1’);
title([’Gráficas con ’,’ h_1 = ’,num2str(h1)])
grid on;
% %%========================================================================
% % %we define the vector function for system x1,x2
% function ydot = fode45(t,x)
% ydot = zeros(1,1);
% ydot(1)=2*t-3*x+1
%
%
% function x1rg=f1(t,x0euler)
% x1rg=2*t-3*x0euler+1;
%
% % % %we define the vector function for system x1,x2
% function ydot = fode45(t,x)
% ydot = zeros(1,1);
% ydot(1)=2*x;
%
%
% function x1rg=f1(t,x0euler)
% x1rg=2*x0euler;
%
%
%
%function ydot = fode45(t,y)
%ydot = zeros(1,1);
%ydot(1)=y;
%function x1rg=f1(t,y0euler)
%x1rg=y0euler;
4
%ydot = zeros(1,1);
%ydot(1)=(exp(-t)-y)/2;
%
%
%function x1rg=f1(t,y0euler)
%x1rg=(exp(-t)-y0euler)/2;
% %%========================================================================
% % %we define the vector function for system x1,x2
%function ydot = fode45(t,x)
%ydot = zeros(1,1);
%ydot(1) =x;
%function x1rg=f1(t,x0euler)
%x1rg=x0euler;
% %%========================================================================
% % % %we define the vector function for system x1,x2
% function ydot = fode45(t,x)
% ydot = zeros(1,1);
% ydot(1) =x*x;
%
%
% function x1rg=f1(t,x0euler)
% x1rg=x0euler*x0euler;
5
L.Q.D.
6
y 0 = −4t3 y, [1, 2], y(1) = 1 con N = 10
Solución:
function fl
clc
close all
clear all;
format long;
global h1 h2 h3
%tamaño de paso
h1=0.1;
%h2=0.2;
%h3=0.3;
%tic
%initial conditions
y0=3;
% calculodel numero de iteraciones para cada h
maximoeuler1=(tfinal-tinicial)/h1;
%maximoeuler2=(tfinal-tinicial)/h2;
%maximoeuler3=(tfinal-tinicial)/h3;
x0euler1=y0;
x0euler2=y0;
x0euler3=y0;
%software de comparación
tic
[t1,Y1] = ode45(@fode45,[tinicial,tfinal],y0);
toc
tic
for m =1:maximoeuler1
x1euler1(m)=x0euler1+h1*f1(m*h1,x0euler1);
x0euler1=x1euler1(m);
vteuler1(m)=h1*m;
end
toc
tic
%for m =1:maximoeuler2
%k12= h2*f1(m*h2,x0euler2);
7
%x1euler2(m)=x0euler2+k12;
%x0euler2=x1euler2(m);
%vteuler2(m)=h2*m;
%end
toc
tic
%for m =1:maximoeuler3
%k13= h3*f1(m*h3,x0euler3);
%x1euler3(m)=x0euler3+k13;
%x0euler3=x1euler3(m);
%vteuler3(m)=h3*m;
%end
toc
% %euler implicito
%
% x0euleri=x0;
% tic
% for n=1:maximoeuler
%
% auxiliar1=x0euleri+h*f1(n*h,x0euleri);
%
% xeuler2(n)=x0euleri+h*f1(n*h,auxiliar1);
%
% x0euleri=xeuler2(n);
%
% %--------------------------------------------------
% vteuleri(n)=h*n;
%
% % --------------------------------------------------
%
% end
% toc
% x0euleri=x0;
% tic
% for n=1:maximoeuler
%
% auxiliar2=x0euleri+h*f1(n*h,x0euleri);
%
% crank(n)=x0euleri+0.5*h*(f1(n*h,x0euleri)+f1((n+1)*h,auxiliar2));
%
% x0euleri=crank(n);
%
% %--------------------------------------------------
% vtcrank(n)=h*n;
%
8
% % --------------------------------------------------
%
% end
% toc
% plot(t1,Y1(:,1),’k.’,vteuler,x1euler,’r’,vteuleri,xeuler2,’b’,vtcrank,crank,’g’)
plot(t1,Y1(:,1),’k’,vteuler1,x1euler1,’r.’)
ylabel(’x(t) La solución aproximada’)
xlabel(’t Tiempo de cálculo’)
legend(’EDO’,’Método de Euler h_1’);
title([’Gráficas con ’,’ h_1 = ’,num2str(h1)])
grid on;
% %%========================================================================
% % %we define the vector function for system x1,x2
% function ydot = fode45(t,x)
% ydot = zeros(1,1);
% ydot(1)=2*t-3*x+1
%
%
% function x1rg=f1(t,x0euler)
% x1rg=2*t-3*x0euler+1;
%
% % % %we define the vector function for system x1,x2
% function ydot = fode45(t,x)
% ydot = zeros(1,1);
% ydot(1)=2*x;
%
%
% function x1rg=f1(t,x0euler)
% x1rg=2*x0euler;
%
%
%
%function ydot = fode45(t,y)
%ydot = zeros(1,1);
%ydot(1)=y;
%function x1rg=f1(t,y0euler)
%x1rg=y0euler;
9
%x1rg=(exp(-t)-y0euler)/2;
% %%========================================================================
% % %we define the vector function for system x1,x2
%function ydot = fode45(t,x)
%ydot = zeros(1,1);
%ydot(1) =x;
%function x1rg=f1(t,x0euler)
%x1rg=x0euler;
% %%========================================================================
% % % %we define the vector function for system x1,x2
% function ydot = fode45(t,x)
% ydot = zeros(1,1);
% ydot(1) =x*x;
%
%
% function x1rg=f1(t,x0euler)
% x1rg=x0euler*x0euler;
10
L.Q.D.
11
Ejercicio 0.2 y 0 = −2y, [0, 1], y(0) = 4 con N = 10
Solución:
function fl
clc
close all
clear all;
format long;
global h1 h2 h3
%tamaño de paso
h1=0.1;
%h2=0.2;
%h3=0.3;
%tic
%initial conditions
y0=4;
% calculodel numero de iteraciones para cada h
maximoeuler1=(tfinal-tinicial)/h1;
%maximoeuler2=(tfinal-tinicial)/h2;
%maximoeuler3=(tfinal-tinicial)/h3;
x0euler1=y0;
x0euler2=y0;
x0euler3=y0;
%software de comparación
tic
[t1,Y1] = ode45(@fode45,[tinicial,tfinal],y0);
toc
tic
for m =1:maximoeuler1
x1euler1(m)=x0euler1+h1*f1(m*h1,x0euler1);
x0euler1=x1euler1(m);
vteuler1(m)=h1*m;
end
toc
tic
%for m =1:maximoeuler2
12
%k12= h2*f1(m*h2,x0euler2);
%x1euler2(m)=x0euler2+k12;
%x0euler2=x1euler2(m);
%vteuler2(m)=h2*m;
%end
toc
tic
%for m =1:maximoeuler3
%k13= h3*f1(m*h3,x0euler3);
%x1euler3(m)=x0euler3+k13;
%x0euler3=x1euler3(m);
%vteuler3(m)=h3*m;
%end
toc
% %euler implicito
%
% x0euleri=x0;
% tic
% for n=1:maximoeuler
%
% auxiliar1=x0euleri+h*f1(n*h,x0euleri);
%
% xeuler2(n)=x0euleri+h*f1(n*h,auxiliar1);
%
% x0euleri=xeuler2(n);
%
% %--------------------------------------------------
% vteuleri(n)=h*n;
%
% % --------------------------------------------------
%
% end
% toc
% x0euleri=x0;
% tic
% for n=1:maximoeuler
%
% auxiliar2=x0euleri+h*f1(n*h,x0euleri);
%
% crank(n)=x0euleri+0.5*h*(f1(n*h,x0euleri)+f1((n+1)*h,auxiliar2));
%
% x0euleri=crank(n);
%
% %--------------------------------------------------
% vtcrank(n)=h*n;
13
%
% % --------------------------------------------------
%
% end
% toc
% plot(t1,Y1(:,1),’k.’,vteuler,x1euler,’r’,vteuleri,xeuler2,’b’,vtcrank,crank,’g’)
plot(t1,Y1(:,1),’k’,vteuler1,x1euler1,’r.’)
ylabel(’x(t) La solución aproximada’)
xlabel(’t Tiempo de cálculo’)
legend(’EDO’,’Método de Euler h_1’);
title([’Gráficas con ’,’ h_1 = ’,num2str(h1)])
grid on;
% %%========================================================================
% % %we define the vector function for system x1,x2
% function ydot = fode45(t,x)
% ydot = zeros(1,1);
% ydot(1)=2*t-3*x+1
%
%
% function x1rg=f1(t,x0euler)
% x1rg=2*t-3*x0euler+1;
%
% % % %we define the vector function for system x1,x2
% function ydot = fode45(t,x)
% ydot = zeros(1,1);
% ydot(1)=2*x;
%
%
% function x1rg=f1(t,x0euler)
% x1rg=2*x0euler;
%
%
%
%function ydot = fode45(t,y)
%ydot = zeros(1,1);
%ydot(1)=y;
%function x1rg=f1(t,y0euler)
%x1rg=y0euler;
14
%function x1rg=f1(t,y0euler)
%x1rg=(exp(-t)-y0euler)/2;
% %%========================================================================
% % %we define the vector function for system x1,x2
%function ydot = fode45(t,x)
%ydot = zeros(1,1);
%ydot(1) =x;
%function x1rg=f1(t,x0euler)
%x1rg=x0euler;
% %%========================================================================
% % % %we define the vector function for system x1,x2
% function ydot = fode45(t,x)
% ydot = zeros(1,1);
% ydot(1) =x*x;
%
%
% function x1rg=f1(t,x0euler)
% x1rg=x0euler*x0euler;
15
L.Q.D.
16
Ejercicio 0.3 y 0 = − cos(t)y, [0, 1,2], y(0) = 2 con N = 12
Solución:
function fl
clc
close all
clear all;
format long;
global h1 h2 h3
%tamaño de paso
h1=0.1;
%h2=0.2;
%h3=0.3;
%tic
%initial conditions
y0=2;
% calculodel numero de iteraciones para cada h
maximoeuler1=(tfinal-tinicial)/h1;
%maximoeuler2=(tfinal-tinicial)/h2;
%maximoeuler3=(tfinal-tinicial)/h3;
x0euler1=y0;
x0euler2=y0;
x0euler3=y0;
%software de comparación
tic
[t1,Y1] = ode45(@fode45,[tinicial,tfinal],y0);
toc
tic
for m =1:maximoeuler1
x1euler1(m)=x0euler1+h1*f1(m*h1,x0euler1);
x0euler1=x1euler1(m);
vteuler1(m)=h1*m;
end
toc
tic
%for m =1:maximoeuler2
%k12= h2*f1(m*h2,x0euler2);
17
%x1euler2(m)=x0euler2+k12;
%x0euler2=x1euler2(m);
%vteuler2(m)=h2*m;
%end
toc
tic
%for m =1:maximoeuler3
%k13= h3*f1(m*h3,x0euler3);
%x1euler3(m)=x0euler3+k13;
%x0euler3=x1euler3(m);
%vteuler3(m)=h3*m;
%end
toc
% %euler implicito
%
% x0euleri=x0;
% tic
% for n=1:maximoeuler
%
% auxiliar1=x0euleri+h*f1(n*h,x0euleri);
%
% xeuler2(n)=x0euleri+h*f1(n*h,auxiliar1);
%
% x0euleri=xeuler2(n);
%
% %--------------------------------------------------
% vteuleri(n)=h*n;
%
% % --------------------------------------------------
%
% end
% toc
% x0euleri=x0;
% tic
% for n=1:maximoeuler
%
% auxiliar2=x0euleri+h*f1(n*h,x0euleri);
%
% crank(n)=x0euleri+0.5*h*(f1(n*h,x0euleri)+f1((n+1)*h,auxiliar2));
%
% x0euleri=crank(n);
%
% %--------------------------------------------------
% vtcrank(n)=h*n;
%
18
% % --------------------------------------------------
%
% end
% toc
% plot(t1,Y1(:,1),’k.’,vteuler,x1euler,’r’,vteuleri,xeuler2,’b’,vtcrank,crank,’g’)
plot(t1,Y1(:,1),’k’,vteuler1,x1euler1,’r.’)
ylabel(’x(t) La solución aproximada’)
xlabel(’t Tiempo de cálculo’)
legend(’EDO’,’Método de Euler h_1’);
title([’Gráficas con ’,’ h_1 = ’,num2str(h1)])
grid on;
% %%========================================================================
% % %we define the vector function for system x1,x2
% function ydot = fode45(t,x)
% ydot = zeros(1,1);
% ydot(1)=2*t-3*x+1
%
%
% function x1rg=f1(t,x0euler)
% x1rg=2*t-3*x0euler+1;
%
% % % %we define the vector function for system x1,x2
% function ydot = fode45(t,x)
% ydot = zeros(1,1);
% ydot(1)=2*x;
%
%
% function x1rg=f1(t,x0euler)
% x1rg=2*x0euler;
%
%
%
%function ydot = fode45(t,y)
%ydot = zeros(1,1);
%ydot(1)=y;
%function x1rg=f1(t,y0euler)
%x1rg=y0euler;
19
%x1rg=(exp(-t)-y0euler)/2;
% %%========================================================================
% % %we define the vector function for system x1,x2
%function ydot = fode45(t,x)
%ydot = zeros(1,1);
%ydot(1) =x;
%function x1rg=f1(t,x0euler)
%x1rg=x0euler;
% %%========================================================================
% % % %we define the vector function for system x1,x2
% function ydot = fode45(t,x)
% ydot = zeros(1,1);
% ydot(1) =x*x;
%
%
% function x1rg=f1(t,x0euler)
% x1rg=x0euler*x0euler;
20
L.Q.D.
21
Parte II
Conclusiones Generales
22