Sei sulla pagina 1di 39

UNIVERSIDAD POLITCNICA DE TULANCINGO

MTODOS NUMRICOS
EVIDENCIA DE APRENDIZAJE
UNIDAD DE APRENDIZAJE: INTEGRACIN Y DIFERENCIACIN NUMRICA,
MTODOS NUMRICOS PARA LA SOLUCIN DE ECUACIONES DIFERENECIALES
NOMBRE DEL ALUMNO:Ezequiel Pastor Mendoza GRUPO:______H551____
FECHA DE ENTREGA: 19-04-16

Instrucciones: Resuelve los siguientes ejercicios y realice la comprobacin de los resultados


usando los algoritmos desarrollados en Matlab
1. Calcule las aproximaciones por diferencias hacia delante y hacia atrs y aproximaciones por
diferencia central para la primera derivada de y = cos x, en x = p/4, con el uso de un valor de h
= p/12. Estime el error absoluto.
2. Repita el problema 23.1, pero para y = log x evaluada en x= 25 con h = 2.
3. Use aproximaciones por diferencias centradas para estimar las derivadas primera y segunda
de y = ex en x = 2 para h = 0.1.
4. Calcule las aproximaciones por diferencia central de primer orden para cada una de las
funciones siguientes en la ubicacin y con el tamao de paso que se especifica:

UNIVERSIDAD POLITCNICA DE TULANCINGO


MTODOS NUMRICOS
EVIDENCIA DE APRENDIZAJE
UNIDAD DE APRENDIZAJE: INTEGRACIN Y DIFERENCIACIN NUMRICA,
MTODOS NUMRICOS PARA LA SOLUCIN DE ECUACIONES DIFERENECIALES
NOMBRE DEL ALUMNO:Ezequiel Pastor Mendoza GRUPO:______H551____
FECHA DE ENTREGA: 19-04-16

5. Usar las formulas cerradas Newton-Cotes (regla del trapecio, regla del trapecio de aplicacin
mltiple, regla de Simpson 1/3, regla de Simpson 3/8 de aplicacin mltiple) para evaluar las
siguientes integrales con n = 4 y h=0.1.

Compare sus resultados con las soluciones analticas.


6. Usando el mtodo de Euler mejorado y RK4 obtener la solucin de las siguientes ecuaciones
diferenciales, considere h=0.1, en el intervalo de x=0 a 1. Adems realice una grfica en Matlab
donde se observe la solucin exacta y aproximada.

Compare sus resultados con las soluciones analticas

EJERCICIO 1
(Hacia delante)

F ' (x )=

xi=

F (Xi +2)+ 4 F (Xi+ 1)3 F ( Xi )


2h

= 0.7071

xi+ 1=

xi+ 2=

5
12

F ' (x )=

= 0.5

= 0.2588

(0.2588)+4 (0.5)3 (0.7071)

2( )
12

F' ( x ) =0.7260

(Hacia atrs)

F ' (x )=

Xi =

3 F ( Xi )4 F ( Xi1 ) + F( Xi2)
2h

= 0.7071

Xi-1 =

Xi-2 = 12

F '(x )=

= 0.8660

= 0.9659

3 ( 0.7071 )4 ( 0.8660 ) +( 0.9659)

2( )
12

'
F ( x ) =0.7201

(En medio)

F ' (x )=

F ( Xi+2 )+ 8 F ( Xi+1 ) 8 F ( Xi1 ) + F( Xi2)


12 h

xi+ 1=

xi+ 2=

5
12

F '(x )=x=

Xi-1 =

Xi-2 = 12

= 0.5

= 0.2588

0.2588+8 ( 0.5 )8 ( 0.8660 ) +0.9659

= 0.8660

= 0.9659

F' ( x ) =0.7069

Ejercicio 2
Repita el problema 23.1, pero para y = log x evaluada en x= 25 con h = 2.

y=logx x=25 h=2

Hacia delante:
'

f ( xi )
h=2

f ( x i+2 ) + 4 f ( x i+1 ) 3 f ( x i )
2h

x i=25
x i+1=x i +h=27
x i+2=29
f ( x i+2 ) =29=log ( 29 )=1.46
f ( x i+1 ) =27=log ( 27 )=1.43
f ( x i )=25=log ( 25 ) =1.39

1.46+ 4 ( 1.43 )3 (1.39)


2(2)

0.0225

Hacia atrs:
'

f ( x i )=

3 f ( x i )4 f ( x i1 ) + f (x i2 )
2h

x i=25
x i1 =xi h=23
x i2 =xi 2 h=21
f ( x i )=1.39
f ( x i1 )=log ( 23 )=1.36
f ( x i2 )=log ( 21 ) =1.32

f ( x i )=1.39

3 ( 1.39 )4 ( 1.36 )+1.32


2( 2)

0.0125
Centrada:
f ' ( x i )=

f ( x i+2 ) +8 f ( x i +1) 8 f ( x i1 ) + f (x i2 )
12 h

x i=25
x i2 =xi 2 h=21
x i1 =xi h=23
x i+1=x i +h=27
x i+2=29

f ( x i+2 ) =log ( 29 )=1.46


f ( x i+1 ) =log ( 27 )=1.43
f ( x i1 )=log ( 23 )=1.36
f ( x i2 )=log ( 21 ) =1.32

1.46+8 ( 1.43 ) 8 ( 1.36 ) +1.32


12(2)

0.42
=0.0175
24

n=1:18;
h=10.^(-n);
a=1;
x=a+h;
valorfn=exp(x);
numerador=valorfn-exp(a);
Dn=numerador./h;
format long
disp([' Incremento Numerador Aproximacin'])
disp([h' numerador' Dn'])
t=[0 0.02 0.04 0.06 0.08 0.1];
q=[100 81.87 67.03 54.88 44.93 36.76];
plot(t,q)
%Posicin de instante a estudiar en el vector t
num=3;
num1=num+1;
num2=num-1;
%Diferencia progresiva
disp('Diferencia progresiva')
difProgresiva=(q(num1)-q(num))/(t(num1)-t(num))
disp('Diferencia regresiva')
difRegresiva=(q(num)-q(num2))/(t(num)-t(num2))
disp('Diferencia central')
difCentral=(q(num1)-q(num2))/(t(num1)-t(num2))
%Calculo de Q'(t)
syms x
derivada=subs(diff(exp(4.6053-10.055*x)),t(num))
%Ajuste a una funcin exponencial
coeficientes=polyfit(t,log(q),1)
%coeficientes es un vector con los coeficientes de la recta
%Si coeficientes=(m n) entonces la recta es log(q)=m*t+n
ye=exp(coeficientes(1)*t+coeficientes(2));
plot(t,ye,'g')
%Comparacin
diferencias=[difProgresiva difRegresiva difCentral];
porcentaje=abs((diferencias-derivada)/derivada)*100;
disp('-------------------------------------')
disp('Comparacin')
titulos=['Progresiva Regresiva Central']
disp([ diferencias ; porcentaje])

Ejercicio 3
Use aproximaciones por diferencias centradas para estimar las derivadas
primera y segunda de

y=ex en x=2 para h=0.1

h=0.1 f (Xi +1)=e (2.1)=8.1661


Xi=2

f (Xi+2)=e(2.2)=9.0250

Xi+1=2.1

f (Xi)=e(2)=7.3890

Xi-1=1.9

f ( Xi1)=e (1.9)=6.6858

Xi+2=2.2

f (Xi2)=e (1.8)=6.0496

Xi-2=1.8
Primera derivada

f ' ( Xi )=

9.1250+ 8 ( 8.1661 )8 ( 6.6858 ) +6.0496


12 ( 0.1 )

f ( Xi )=

9.0250+65.328853.4864 +6.0496
1.2

f ( Xi )=

8.867
=7.3891
1.2

Segunda derivada

error=e ( 0.1 )=1.1051

0.1 2
12
9.0250+16 ( 8.1661 )30 ( 7.3890 ) +16 ( 6.6858 )6.0496
f ( Xi )=

f ( Xi ) =

9.0250+130.6576221.67+106.97286.0496
12 ( 0.01 )

f ' ' ( Xi ) =

0.8858
=7.381666
0.12

''

Ejercicio 4
Calcular las aproximaciones por diferencia central de primer orden.
A)

y=x 3 +4 x 15 x =0 y h=0.25

Xi+1 = 0+0.25 = 0.25, X i+2 = 0.25 + 0.25 = 0.5, X i-1 = -0.25, Xi-2 = -0.5.
f ( xi+1 )=( 0.5 )3 + 4 ( 0.5 ) 15=.13 .94
f ( xi+2 )=(0.5 )3 + 4 (0.5 )15=12.87
f ( xi1 ) =(0.25 )3+ 4 (0.25 )15=140.1
f ( xi2 ) =(0.5 )3+ 4 (0.5 )15=17.12
f ' ( xi )=
B)

f (12.87 )+ 8 f (13.94 )8 f (14.01 )17.12


=18.01
12(0.25)

y=x 2 +cosx x=0 y h=0.1


(xi+1)=0.4+0.1=0.5,( xi+2)=0.5+0.1=0.6,(xi1)=0.40.=0.3, xi2=0.30.1=0.2

f ( xi+1 )=( 0.5 )2 +cos ( 0.5 )=1.24


f ( xi+2 )=( 0.6 )2+ cos ( 0.6 ) = 1.35
f ( xi1 ) =( 0.3 )2 +cos ( 0.3 ) =1.089
f ( xi2 ) =( 0.2 )2+ cos ( 0.2 )=1.03
f ' ( x )=

f (1.35 )+ 8 f ( 1.24 )8 (1.08 )+ f ( 1.03 )


=0.78
12 ( 0.1 )

C)

y=tan

( 3x ) x=3 y h=0.5

xi=3, ( xi+1 ) =3+0.5=3.5, ( xi+2 )=3.5+ 0.5=4, ( xi1 )=30.5=2.5, ( xi2 )=2.50.5=2

( 33 )=0.017
5
f ( xi+1 )=tan ( 3. )=0.020
3
4
f ( xi+2 )=tan ( )=0.23
4
5
f ( xi1 ) =tan ( 2. ) =0.014
3
2
f ( xi2 ) =tan ( )=0.011
3
f ( xi )=tan

f ' ( x )=

D)

f ( 0.023 )+ 8 f ( 0.020 )8 f ( 0.014 )+ f ( 0.011 )


=0.026
12 ( 0.5 )

y=sin

( 0.5 x )
x

x=1 y h=0.2

xi=1, ( xi+1 ) =1+ 0.2=1.02, ( xi+2 )=1.2+0.2=1.4, ( xi1 )=11.02=0.8, ( xi2 )=0.80.2=0.6
f ( xi+1 )=sen

0.5 1 .2
=0.0079
1.2

f ( xi+2 )=sen

0.5 1 .4
=0.0073
1.4

f ( xi1 ) =sen

0.5 0.8
=0.0097
0.8

f ( xi2 ) =sen

0.5 0.6
=0.011
0.6

f ' ( xi )=
E)

f ( 0.0073 )+ 8 f ( 0.0079 )8 f ( 0.0097 ) + f (0.011)


=0.0025
12(0.2)

y=e x + x x=2 y h=0.2


xi=2, ( xi+1 )=2+0.2=2.2, ( xi+ 2 )=2.2+0.2=2.4

( xi1 )=20.2=1.8, ( xi2 )=1.80.2=1.6


f ( xi+1 )=e 2 .2+2.2=11.22
f ( xi+2 )=e2.2 +2.4=13.42
f ( xi2 ) =e 1.8+ 1.8=7.84
f ( xi1 ) =e1.6 + 1.6=6.55
f ( xi+2 )=

f ( 13.42 )+ 8 f ( 11.22 )8 f ( 7.84 ) +6.55


=16.34
12(0.2)

Cdigo en Matlab.
clc; clear all;
fprintf('Programa para efectuar la derivacion de un set de datos\n\n');
fprintf('El programa le brindar la 1,2,3 y 4 derivada\n\n');
fprintf('Ingrese datos de variable independiente:\n');
fprintf('(RECUERDE QUE ESTOS DATOS DEBEN SER REGULARMENTE ESPACIADOS\n');
x=input('Ej.[0 1 2 3 4 5 6 7 8 9 10])');
n=length(x);
e=0;
for i=1:n-3%este bucle verificar que el tamao de paso sea el mismo
if (x(1,i+1)-x(1,i))~=(x(1,i+2)-x(1,i+1))
e=e+1;
break;
end
end
if e>0,error ('Los datos deben ser igualmente espaciados');end

fprintf('Ingrese datos de la variable dependiente: \n');


y=input('(Ej.[1.4 2.1 3.3 4.8 6.8 6.6 8.6 7.5 8.9 10.9 10])');
h=x(1,2)-x(1,1);
n=length(x);
pridrv=zeros(1,n);
%Desde el segundo dato hasta el penltimo, Direncias finitas centradas
for i=2:n-1
pridrv(1,i)=(y(1,i+1)-y(1,i-1))/(2.*h);
end
%Ahora Desarrollaremos la segunda derivada
segdrv=zeros(1,n);
if n<3
fprintf('No se puede calcular la segunda derivada con solo 2 datos\n');
else
segdrv(1,1)=(y(1,3)-2.*y(1,2)+y(1,1))/h.^2;
for i=2:n-1
segdrv(1,i)=(y(1,i+1)-2.*y(1,i)+y(1,i-1))/h.^2;
end
segdrv(1,n)=(y(1,n)-2.*y(1,n-1)+y(1,n-2))/h.^2;
fprintf('Las segundas derivadas para los datos ingresados son,
respectivamente: \n');
disp(segdrv);
end
%Tercera derivada:

if n<5
if n<4
fprintf('No se puede hallar la tercera derivada con menos de 4 datos\n');
else

fprintf('Con cuatro datos solo podemos hallar terceras derivadas en los


extremos');
fprintf('\n');
exterdrv=zeros(1,2);
exterdrv(1,1)=(y(1,4)-3.*y(1,3)+3.*y(1,2)-y(1,1))/h.^3;
exterdrv(1,2)=(y(1,n)-3.*y(1,n-1)+3.*y(1,n-2)-y(1,n-3))/h.^3;
fprintf('Estas son: ');
disp(exterdrv);
end
else
terdrv=zeros(1,n);
terdrv(1,1)=(y(1,4)-3.*y(1,3)+3.*y(1,2)-y(1,1))/h.^3;
terdrv(1,2)=(y(1,5)-3.*y(1,4)+3.*y(1,3)-y(1,2))/h.^3;
for i=3:n-2
terdrv(1,i)=(y(1,i+2)-2.*y(1,i+1)+2.*y(1,i-1)-y(1,i-2))/(2*h.^3);
end
terdrv(1,n-1)=(y(1,n-1)-3.*y(1,n-2)+3.*y(1,n-3)-y(1,n-4))/h.^3;
terdrv(1,n)=(y(1,n)-3.*y(1,n-1)+3.*y(1,n-2)-y(1,n-3))/h.^3;
fprintf('Las terceras derivadas para los datos ingresados son,
respectivamente: \n');
disp(terdrv);
end
%Cuarta derivada
if n<6
if n<5
fprintf('No se puede hallar la cuarta derivada con menos de 5 datos\n');
else

fprintf('Con cinco datos solo podemos hallar cuartas derivadas en los


extremos\n');
excuadrv(1,1)=(y(1,5)-4.*y(1,4)+6.*y(1,3)-4.*y(1,2)+y(1))/h.^4;
excuadrv(1,2)=(y(1,n)-4.*y(1,n-1)+6.*y(1,n-2)-4.*y(1,n-3)+y(n-4))/h.^4;
fprintf('Estas son:');
disp(excuadrv);
end
else
cuadrv=zeros(1,n);
cuadrv(1,1)=(y(1,5)-4.*y(1,4)+6.*y(1,3)-4.*y(1,2)+y(1))/h.^4;
cuadrv(1,2)=(y(1,6)-4.*y(1,5)+6.*y(1,4)-4.*y(1,3)+y(2))/h.^4;
for i=3:n-2
cuadrv(1,i)=(y(1,i+2)-4.*y(1,i+1)+6.*y(1,i)-4.*y(1,i-1)+y(1,i-2))/h.^4;
end
cuadrv(1,n)=(y(1,n)-4.*y(1,n-1)+6.*y(1,n-2)-4.*y(1,n-3)+y(n-4))/h.^4;
cuadrv(1,n-1)=(y(1,n-1)-4.*y(1,n-2)+6.*y(1,n-3)-4.*y(1,n-4)+y(n-5))/h.^4;
fprintf('Las cuartas derivadas para los datos ingresados son,
respectivamente: \n');
disp(cuadrv);
end

Ejercicio 5

1)

f(x)=1-e^-2x = (x+(1/2)e^-2x) evaluado 4,0 =3.000167731

METODO DEL TRAPECIO


a=0 b=4
f(x)=1-e^-2x
f(x)=(b-a)(f(a)+f(b))
2

f(x)=(4-0)(0+0.99966) = 4(0.49983) =1.999


2

METODO DEL TRAPECIO APLICACIN MULTIPLE


f(x)=1-e^-2x
a=0 b=4

n=4

h=0.1

I=(b-a)(f(xo)+2 (f(x1)+f(x2)+f(x3))+f(xn)
2n
x0=0

f(xo)=0

x1=0.1 f(x1)=1.1812
x2=0.2 f(x2)=0.3296
x3=0.3 f(x3)=0.4511
x4=0.4 f(x4)=0.5506
I=(4-0)(0+2 (1.1812+0.3296+0.4511)+0.5506
2n
I=4(4.4744) =2.2372
8

METODO DE SIMPSON

1/3

f(x)=1-e^-2x
xo=0

x1=2

x2=4

I=(b-a)(f(xo)+4 f(x1)+f(x2)
6
I=(4-0)(0+4(0.9816)+0.9996 = 3.284
6

METODO DE SIMPSON
f(x)=1-e^-2x
xo=0

x1=1

3/8 APLICACIN MULTIPLE

n=4
x2=2

x3=3

x4=4

I=(b-a)(f(xo)+4 (f(x1)+f(x2)+f(x3))+f(x4)
3n

I=(4-0)(0+4 (0.8646+0.9816+0.9975)+0.9996 =4.1248


12
2) f(x)=6+3cos x =6x+sen x evaluado de pi medios a 0= 12.4987

METODO DEL TRAPECIO


a=0 b=1.5708
f(x)=6+3cos x
f(x)=(b-a)(f(a)+f(b))
2
f(x)=(1.5708-0)(9+8.9990) = 1.5798(8.9995) =14.21
2
METODO DEL TRAPECIO APLICACIN MULTIPLE
f(x)=6+3cos x
a=0 b=1.5708

n=4

h=0.1

I=(b-a)(f(xo)+2 (f(x1)+f(x2)+f(x3))+f(xn)
2n
x0=0

f(xo)=9

x1=0.1 f(x1)=8.9999
x2=0.2 f(x2)=8.9999
x3=0.3 f(x3)=8.9999
x4=0.4 f(x4)=8.9999
I=(1.5708-0)(9+2 (8.999+8.9999+8.9999)+8.9999
2n
I=1.5708(71.9993) =14.1370
8

METODO DE SIMPSON

1/3

f(x)=6+3cos x
xo=0

x1=0.7854

x2=1.5708

I=(b-a)(f(xo)+4 f(x1)+f(x2)

6
I=(1.5708-0)(9+4(8.9997)+8.9990 = 14.1366
6

METODO DE SIMPSON
f(x)=6+3cos x
xo=0

3/8 APLICACIN MULTIPLE

n=4

x1=0.3927

x2=0.7854

x3=1.1781

x4=1.5708

I=(b-a)(f(xo)+4 (f(x1)+f(x2)+f(x3))+f(x4)
3n
I=(1.5708-0)(9+4 (8.9999+8.9997+8.9994)+8.9990 =16.4927
12
3) f(x)=(x+2/x)^2 =((x^2)+(4/x^2)+4)dx=8.33

METODO DEL TRAPECIO


a=1 b=2
f(x)=(x+2/x)^2
f(x)=(b-a)(f(a)+f(b))
2
f(x)=(2-1)(9+9) = 1(9) =9
2

METODO DEL TRAPECIO APLICACIN MULTIPLE


f(x)= (x+2/x)^2
a=1 b=2

n=4

h=0.1

I=(b-a)(f(xo)+2 (f(x1)+f(x2)+f(x3))+f(xn)
2n
x0=1

f(xo)=9

x1=1.1 f(x1)=7.9421
x2=1.2 f(x2)=8.2177
x3=1.3 f(x3)=8.0568

x4=1.4 f(x4)=8.0008

I=(2-1)(9+2 (7.9421+8.2177+8.0568)+8.0008
2n
I=1(65.434) =8.1792
8

METODO DE SIMPSON

1/3

f(x)= (x+2/x)^2
xo=1

x1=1.5

x2=2

I=(b-a)(f(xo)+4 f(x1)+f(x2)
6

I=(2-1)(9+4(8.0277)+9 = 8.3518
6

METODO DE SIMPSON
f(x)= (x+2/x)^2
xo=1

3/8 APLICACIN MULTIPLE

n=4

x1=1.25

x2=1.5

x3=1.75

x4=2

I=(b-a)(f(xo)+4 (f(x1)+f(x2)+f(x3))+f(x4)
3n
I=(2-1)(9+4 (8.1225+8.0277+8.3686)+9 =9.6729
12
4) f(x)=(x^2)(e^x) =((x^2)(e^x))-((e^x)2x)=60.24

METODO DEL TRAPECIO


a=0 b=3
f(x)=(x^2)(e^x)
f(x)=(b-a)(f(a)+f(b))
2

f(x)=(3-0)(0+60.25) = 1(30.1283) =90.3849


2

METODO DEL TRAPECIO APLICACIN MULTIPLE


f(x)= (x^2 )(e^x)
a=0 b=3

n=4

h=0.1

I=(b-a)(f(xo)+2 (f(x1)+f(x2)+f(x3))+f(xn)
2n
x0=0

f(xo)=0

x1=0.1 f(x1)=0.0110
x2=0.2 f(x2)=0.0488
x3=0.3 f(x3)=0.1214
x4=0.4 f(x4)=0.2386
I=(3-0)(0+2 (0.0110+0.0488+0.1214)+0.2386
2n
I=1(65.434) =0.9753
8

METODO DE SIMPSON

1/3

f(x)= (x^2 )(e^x)


xo=0

x1=1.5

x2=3

I=(b-a)(f(xo)+4 f(x1)+f(x2)
6
I=(3-0)(0+4(10.0838)+60.25 = 50.2926
6

METODO DE SIMPSON

3/8 APLICACIN MULTIPLE

f(x)= (x^2 )(e^x) n=4


xo=0

x1=0.75

x2=1.5

x3=2.25

I=(b-a)(f(xo)+4 (f(x1)+f(x2)+f(x3))+f(x4)

x4=3

3n
I=(3-0)(0+4 (1.1908+10.0838+48.0316)+60.25 =74.3687
12

Ejercicio 6

Usando el mtodo de Euler mejorado y RK4 obtener la solucin de las siguientes


ecuaciones diferenciales, considere h=0.1, en el intervalo de x=0 a 1. Adems
realice una grfica en Matlab donde se observe la solucin exacta y aproximada.
a)

y= x,

dy
= y x 21.1 y
dx

b)

c)

y(0)=1
, y(0)=1

dy
=( 1+ 2 x ) y
dx

y(0)=1

Mtodo de Euler mejorado


a)

y= x,

X0 = 0

y(0)=1

Y0 = 1

h= 0.1

Formula
Y n+1 =Y n+

h ( f ( X n , Y n ) + f ( X n +1 , Y n+1 ) )
2

Y n+1 =Y n+ h f ( X n , Y n )
X 1 = 0.1 , X 2 = 0.2, X 3 = 0.3, X 4 = 0.4,
0.7, X 8 = 0.8, X 9 = 0.9, X 10 =1

X 5 = 0.5,

X 6 = 0.6,

y= x

Y =Y 0 +h f ( X 0 ,Y 0 )

n=0
Y =1+0.1 ( 0 )

Y 1 = 1

X7 =

Y 1=Y 0 +

h ( f ( X 0 ,Y 0 ) +f ( X 1 , Y 1 ) )
2

= 1+

0.1 ( 0.1 ( 0 ) + ( 0.1 ) )


2

= 1+0.005= 1.005

n=1
Y 2=Y 1 +

h ( f ( X 1 ,Y 1 ) + f ( X 2 ,Y 2) )
2

= 1.005+

0.1 ( 0.1+ ( 0.2 ) )


2

= 1.005+0.015=

1.02

n=2

Y 3=Y 2 +

h ( f ( X 2 ,Y 2 ) + f ( X 3 , Y 3 ) )
2

= 1.02+

0.1 ( 0.2+ ( 0.3 ) )


2

= 1.02+0.025= 1.045

n=3

Y 4 =Y 3+

h ( f ( X 3, Y 3)+ f ( X 4 , Y 4) )
2

= 1.045+

0.1 ( 0.3+ ( 0.4 ) )


2

= 1.08

n=4
Y 5=Y 4+

h ( f ( X 4 ,Y 4 ) + f ( X 5 ,Y 5 ) )
2

= 1.08+

0.1 ( 0.4+ ( 0.5 ) )


2

=1.125

n=5
Y 6=Y 0 +

h ( f ( X 5 , Y 5 ) +f ( X 6 ,Y 6 ) )
2

= 1.125+

0.1 ( 0.5+ ( 0.6 ) )


2

= 1.18

n=6
Y 7=Y 6 +

h ( f ( X 6 , Y 6 ) + f ( X 7 ,Y 7 ) )
2

= 1.18+

0.1 ( 0.6+ ( 0.7 ) )


2

1.245

n=7
Y 8=Y 7 +

h ( f ( X 7 , Y 7 ) +f ( X 8 ,Y 8 ) )
2

= 1.245+

0.1 ( 0.7+ ( 0.8 ) )


2

= 1.32

n=8

Y 9=Y 8 +

h ( f ( X 8 , Y 8 ) + f ( X 9 ,Y 9 ) )
2

= 1.32+

0.1 ( 0.8+ ( 0.9 ) )


2

n=9

= 1.405

Y 10=Y 9 +

h ( f ( X 9 ,Y 9 ) +f ( X 10 , Y 10 ) )

= 1.405+

Respuesta Exacta
y= x,
dy
=x
dx

X=0
Y=1
02
1= 2 +c

dy= x dx

dy = x dx

1= 0+ c

x2
Y = 2 +c

1=c
x2
Y = 2 +1
2

X=0.1
X=0.2

Y 1 = 0.1 +1
2
2
Y 2 = 0.2 +1
2

= 1.005
= 1.02

X=0.3

Y 3 = 0.3 +1
2

X=0.4

Y4

X=0.5
X=0.6
X=0.7

0.42
= 2 +1

2
Y 5 = 0.5 +1
2

Y6

0.62
= 2 +1

2
Y 7 = 0.7 +1
2

= 1.045
= 1.08
= 1.125
= 1.18
= 1.245

X=0.8

Y 1 = 0.8 +1
2

= 1.32

0.1 ( 0.8+ ( 0.9 ) )


2

= 1.5

Y 1 = 0.9 +1
2

X=0.9

2
Y 1 = 1 +1
2

X=1

= 1.405

= 1.5

Mtodo de Runge Kutta 4


a)

y= x,

X0 = 0

y(0)=1

Y0 = 1

h= 0.1

Formula
h
Y n+1 =Y n+ ( k 1 +2 k 2 +2 k 3 + k 4 )
6
k 1=f ( X n , Y n )
1
1
k 2=f X n + h ,Y n+ h k 1
2
2

(
)
1
1
k =f ( X + h , Y + h k )
2
2
3

k 4=f ( X n +h , Y n +h k 3 )

n=0
k 1=f ( X 0 , Y 0 )

= (0)=0

1
1
k 2=f X 0 + h ,Y 0+ h k 1
2
2

(
) = (0+1/2(0.1)1)=0.05
1
1
k =f ( X + h , Y + h k ) =(0+1/2(0.1)1)=0.05
2
2
3

k 4=f ( X 0 +h , Y 0 +h k 3 ) =
h
Y 1=Y 0 + ( k 1 +2 k 2 +2 k 3 +k 4 ) =1+0.1/6(0+2(0.05)+2(0.05)+0.1)
6
Y 1= 1+0.0166(0+0.1+0.1+0.1)= 1.0049

(0+0.1)=0.1

n=1
k 1=f ( X 1 , Y 1 )

= (0.1)=0.1

1
1
k 2=f X 1+ h ,Y 1 + h k 1
2
2

(
) = (0.1+1/2(0.1))=0.15
1
1
k =f ( X + h ,Y + h k ) =(0.1+1/2(0.1))=0.15
2
2
3

k 4=f ( X 1 +h , Y 1+ h k 3 )=

(0.1+0.1)=0.2

h
Y 2=Y 1 + ( k 1+ 2 k 2+ 2 k 3+ k 4 ) =1.0049+0.1/6(0.1+2(0.15)+2(0.15)+0.2)
6
Y 2= 1.0049+0.0166(0+0.3+0.3+0.2)= 1.018
n=2
k 1=f ( X 2 , Y 2 )

= (0.2)=0.2

1
1
k 2=f X 2+ h ,Y 2 + h k 1
2
2

(
) = (0.2+1/2(0.1))=0.25
1
1
k =f ( X + h ,Y + h k ) =(0.2+1/2(0.1))=0.25
2
2
3

k 4=f ( X 2 +h , Y 2+ h k 3 )=

(0.2+0.1)=0.3

h
Y 3=Y 3 + ( k 1 +2 k 2 +2 k 3 +k 4 ) =1.018+0.1/6(0.2+2(0.25)+2(0.25)+0.3)
6
Y 3= 1.018+0.0166(0+0.5+0.5+0.3)= 1.04
n=3
k 1=f ( X 3 , Y 3 )

= (0.3)=0.3

1
1
k 2=f X 3 + h ,Y 3 + h k 1
2
2

(
) = (0.3+1/2(0.1))=0.35
1
1
k =f ( X + h ,Y + h k ) =(0.3+1/2(0.1))=0.35
2
2
3

k 4=f ( X 3 +h , Y 3+ h k 3 ) =

(0.3+0.1)=0.4

h
Y 4 =Y 3+ ( k 1+2 k 2 +2 k 3 + k 4 ) =1.04+0.1/6(0.3+2(0.35)+2(0.35)+0.4)
6
Y 4 = 1.04+0.0166(0+0.7+0.7+0.4)= 1.06
n=4
k 1=f ( X 4 ,Y 4 )

= (0.4)=0.4

1
1
k 2=f X 4 + h , Y 4 + h k 1
2
2

(
) = (0.4+1/2(0.1))=0.45
1
1
k =f ( X + h , Y + h k ) =(0.1+1/2(0.1))=0.45
2
2
3

k 4=f ( X 4 +h ,Y 4+h k 3 ) =

(0.4+0.1)=0.5

h
Y 5=Y 4+ ( k 1+2 k 2 +2 k 3 + k 4 ) =1.06+0.1/6(0.4+2(0.45)+2(0.45)+0.5)
6
Y 5= 1.06+0.0166(0+0.9+0.9+0.5)= 1.09
n=5
k 1=f ( X 5 , Y 5 )

= (0.5)=0.5

1
1
k 2=f X 5 + h ,Y 5 + h k 1
2
2

(
) = (0.5+1/2(0.1))=0.55
1
1
k =f ( X + h ,Y + h k ) =(0.5+1/2(0.1))=0.55
2
2
3

k 4=f ( X 5 +h , Y 5+ h k 3 ) =

(0.5+0.1)=0.7

h
Y 6=Y 5 + ( k 1 +2 k 2 +2 k 3 +k 4 ) =1.09+0.1/6(0.5+2(0.55)+2(0.55)+0.7)
6
Y 6= 1.09+0.0166(0.5+1.1+1.1+0.7)= 1.13
n=6
k 1=f ( X 6 , Y 6 )

= (0.6)=0.6

1
1
k 2=f X 6 + h , Y 6+ h k 1
2
2

(
) = (0.6+1/2(0.1))=0.65
1
1
k =f ( X + h , Y + h k ) =(0.6+1/2(0.1))=0.65
2
2
3

k 4=f ( X 6 +h , Y 6 +h k 3 ) =

(0.6+0.1)=0.7

h
Y 7=Y 1 + ( k 1 +2 k 2 +2 k 3 +k 4 ) =1.13+0.1/6(0.6+2(0.65)+2(0.65)+0.7)
6
Y 7= 1.13+0.0166(0.6+1.3+1.3+0.8)= 1.18
n=7
k 1=f ( X 7 , Y 7 )

= (0.7)=0.7

1
1
k 2=f X 7 + h ,Y 7+ h k 1
2
2

= (0.7+1/2(0.1))=0.75

1
1
k 3 =f X 7 + h , Y 7+ h k 2
2
2

=(0.7+1/2(0.1))=0.75
k 4=f ( X 7 +h , Y 7 +h k 3 ) =

(0.7+0.1)=0.8

h
Y 8=Y 1 + ( k 1 +2 k 2 +2 k 3 +k 4 ) =1.18+0.1/6(0.7+2(0.75)+2(0.75)+0.8)
6
Y 8= 1.18+0.0166(0.7+1.5+1.5+0.8)= 1.25
n=8
k 1=f ( X 8 , Y 8 )

= (0.8)=0.8

1
1
k 2=f X 8 + h ,Y 8+ h k 1
2
2

(
) = (0.8+1/2(0.1))=0.85
1
1
k =f ( X + h , Y + h k ) =(0.8+1/2(0.1))=0.85
2
2
3

k 4=f ( X 8 +h , Y 8 +h k 3 ) =

(0.8+0.1)=0.9

h
Y 9=Y 9+ ( k 1 +2 k 2 +2 k 3 +k 4 ) =1.25+0.1/6(0.8+2(0.85)+2(0.85)+0.9)
6
Y 2= 1.25+0.0166(0.8+1.7+1.7+0.9)= 1.33
n=9
k 1=f ( X 9 , Y 9 )

= (0.9)=0.9

1
1
k 2=f X 9 + h , Y 9+ h k 1
2
2

(
) = (0.9+1/2(0.1))=0.95
1
1
k =f ( X + h , Y + h k ) =(0.9+1/2(0.1))=0.95
2
2
3

k 4=f ( X 9 +h , Y 9 +h k 3 ) =

(0.9+0.1)=1

h
Y 10=Y 9 + ( k 1 +2 k 2+ 2 k 3+ k 4 ) =1.33+0.1/6(0.9+2(0.95)+2(0.95)+1)
6
Y 10= 1.33+0.0166(0.9+1.9+1.9+1)= 1.42

Metodo de Euler Mejorado


b)
0.1

dy
= y x 21.1 y
dx

, y(0)=1 1

X0 = 0

Y0 = 1

h=

N=0

Y 1=Y 0 +h f ( X 0 ,Y 0 )
h ( f ( X 0 ,Y 0 ) +f ( X 1 , Y 1 ) )

Y 1=Y 0 +

Y =Y 1 +h f ( X 1 ,Y 1 ) =

h ( f ( X 1 ,Y 1 ) + f ( X 2 ,Y 2) )
2

Y =Y 2 +h f ( X 2 ,Y 2 ) =
Y 3=Y 3 +

= 1+

0.1 ( 0 ( 0 )1.1 ( 0.1 ) )


2

h ( f ( X 2 ,Y 2 ) + f ( X 3 , Y 3 ) )
2

= 1.005+

0.1 ( 0.1+ ( 0.2 ) )


2

= 0.9

= 1.005+0.015=

n=2
Y =1.02+0.1( ( 0.2 )1.1 ( 1.02 ) )

= 1.02+

0.1 ( 0.2+ ( 0.3 ) )


2

0.89

= 1+0.005= 1.005

n=1
1.005+0.1( ( 0.01 )1.1 ( 1.005 ) )

Y 2=Y 1 +

Y 1=1+0.1( ( 0 )1.1 (1 ))

1.02

1.005

= 1.02+0.025= 1.045

n=3
Y 4 =Y 3+ h f ( X 3 , Y 3 )
Y 4 =Y 4 +

= Y 4 =1.045+0.1( ( 0.3 ) 1.1 ( 1.045 ) )

h ( f ( X 3 ,Y 3) + f ( X 4 ,Y 4 ) )
2

Y =Y 4+ h f ( X 4 ,Y 4 )

= 1.045+

n=4
Y =1.355+0.1( ( 0.4 )1.1 ( 1.355 ) )

h ( f ( X 4 , Y 4 )+ f ( X 5 , Y 5 ))
2
Y 6=Y 5 + h f ( X 5 , Y 5 )

Y 6=Y 6 +

h ( f ( X 5 , Y 5 ) +f ( X 6 ,Y

Y 7=Y 6 +

))

Y 7=Y 6 + h f ( X 6 , Y 6 )
h ( f ( X 6 , Y 6 ) + f ( X 7 ,Y

))

Y =Y 7 + h f ( X 7 , Y 7 )

= 1.11+0.125= 1.355

Y 5=Y 5 +

0.1 ( 0.3+ ( 1.156 ) )


2

= 1.355+

0.1 ( 0.4+ ( 1.255 ) )


2

0.1 ( 0.5+ ( 1.354 ) )


2

n=6
Y =1.55+ 0.1( ( 0.6 )1.1 ( 1.55 ) )
0.1 ( 0.6+ ( 1.456 ) )
2

= 1.354

= 1.456

= 1.55+0.125= 1.645

n=7
Y =1.645+ 0.1( ( 0.7 )1.1 ( 1.645 ) )

1.255

= 1.30+0.15= 1.555

= 1.55+

= 1.25+0.125= 1.455

n=5
Y 6=1.455+ 0.1( ( 0 )1.1 ( 1.455 ) )

= 1.455+

= 1.156

= 1.575

Y 8=Y 7 +

h ( f ( X 7 , Y 7 ) +f ( X 8 ,Y 8 ) )

= 1.645+

0.1 ( 0.7+ ( 1.575 ) )


2

= 1.645+0.155= 1755

Mtodo de Euler mejorado


dy
=( 1+ 2 x ) y
dx

c)

y(0)=1

X0 = 0

Y0 = 1

h= 0.1

Formula

Y n+1 =Y n+

h ( f ( X n , Y n ) + f ( X n +1 , Y n+1 ) )
2

Y n+1 =Y n+ h f ( X n , Y n )
X 1 = 0.1 , X 2 = 0.2, X 3 = 0.3, X 4 = 0.4,
0.7, X 8 = 0.8, X 9 = 0.9, X 10 =1

X 5 = 0.5,

X 6 = 0.6,

X7 =

dy
=( 1+ 2 x ) y
dx

Y 1=Y 0 +h f ( X 0 ,Y 0 )

n=0

Y 1=1+0.1 ( 1+2(0) )

1.1

Y 1=Y 0 +

h ( f ( X 0 ,Y 0 ) +f ( X 1 , Y
2

))

1+2 ( 0 )+ ( 1+ 2(0.1)() )

0.1
1+
n=1

Y 2=Y 1 +h f ( X 1 ,Y 1 )

1.11
1+2(0.1)()
=
Y 1=1.111+0.1

= 1.12

Y 1 = 1.1

=1.111

1.12

1.11+ ( 1+2(0.1)())

Y 2=Y 1 +

h ( f ( X 1 ,Y 1 ) + f ( X 2 ,Y 2) )
2

1+2 ( 0.1 )
0.1
1.11+

=1.23

n=2

1.23
1+ 2(0.2)( )
=
Y 3=1.23+0.1

Y 3=Y 2 +h f ( X 2 ,Y 2 )

= 1.37

1.37

Y 3=Y 2 +

h ( f ( X 2 ,Y 2 ) + f ( X 3 , Y 3 ) )
2

1.23+ ( 1+ 2(0.3)())

1+2 ( 0.2 )
0.1
1.23+

=1.38

n=3

1.38
2(0.3)()
= 1+

Y 3=1.38+0.1

Y 4 =Y 3+ h f ( X 3 , Y 3 )

Y 4 =Y 3+

h ( f ( X 3, Y 3)+ f ( X 4 , Y 4) )
2

= 1.55

1.55
1.38+

( 1+ 2(0.4)() )

1+ 2 ( 0.3 )
0.1
1.38+

=1.56

n=4

1.56

Y 5=Y 4+ h f ( X 4 ,Y 4 )

Y 5=Y 4+

1+2( 0.4)()
Y 5=1.56+ 0.1

h ( f ( X 4 ,Y 4 ) + f ( X 5 ,Y 5 ) )
2

= 1.75

1.75
1.56+( 1+2(0.5)())
=

1+2 ( 0.4 )
0.1
1.56+
n=5

Y 6=Y 5 + h f ( X 5 , Y 5 )

1.79
1+ 2(0.5)()
=
Y 6=1.79+ 0.1

= 2.02

=1.79

2.02

1.79+ ( 1+ 2(0.6)())

Y 6=Y 5 +

h ( f ( X 5 , Y 5 ) +f ( X 6 ,Y 6 ) )
2

(
1+2 0.5 )
0.1
1.79+

=2.04

Respuesta Exacta
dy
=( 1+ 2 x ) y
dx

X= 0
2

dy= ( 1+2 x ) y dx
dy
=
y

0+1 +c
)
1 = (e

dy

y = (1+2 x ) dx
2

x+x +c
)
Y = (e

0=c
x+ y
Y = (e

X=0.1

Y 1 = ( e 0.1+ 0.1 ) 2

= 1.245

X=0.2

Y 2 = ( e 0.2+ 0.2 ) 2

= 1.27

X=0.3

Y3

( e 0.3+0.3 )

X=0.4

Y4

0.4 +0.4
)
= (e

X=0.5

Y 5 = ( e 0.5+0.5 )2 = 2.11

X=0.6

Y6

X=0.7

Y 7 = ( e 0.7 +0.7 )2 = 3.28

X=0.8

Y 1 = ( e 0.8 +0.8 )2

X=0.9

Y1

= 1.47
2

= 1.75

0.6 +0.6
)
= (e

= 2.61

X=1

Y1

( e 0.9+0.9 )
2

x+x +c
)
Y = (e

( 1+2 x ) dx

y=1

= 4.22
= 5.52

( e 1+1 ) = 7.38

Mtodo de Runge Kutta 4


c)

dy
=( 1+ 2 x ) y ,
dx

X0 = 0

y(0)=1

Y0 = 1

h= 0.1
Formula
h
Y n+1 =Y n+ ( k 1 +2 k 2 +2 k 3 + k 4 )
6
k 1=f ( X n , Y n )
1
1
k 2=f X n + h ,Y n+ h k 1
2
2

(
)
1
1
k =f ( X + h , Y + h k )
2
2
3

k 4=f ( X n +h , Y n +h k 3 )

n=0
k 1=f ( X 0 , Y 0 )

= (1+2(0))( 1 )=1

1
1
k 2=f X 0 + h ,Y 0+ h k 1
2
2

(
)
1
1
k =f ( X + h , Y + h k )
2
2
3

= (1+2(0))( +1/2(0.1)) ( 1 ) 1/2(1) =1.0025


= (1+2(0))( +1/2(0.1)) ( 1 ) 1/2(1.002) =1.02

k 4=f ( X 0 +h , Y 0 +h k 3 ) = (1+2(0)+0.1(1)+0.1(1.02)=1.21
h
Y 1=Y 0 + ( k 1 +2 k 2 +2 k 3 +k 4 ) =1+0.1/6(1+2(1.0025)+2(1.02)+1.21)
6
Y 1= 1+0.0166(1+2.005+2.04+1.21)= 1.104

n=1
k 1=f ( X 1 , Y 1 )

= (1+2(0.1)(sqrt1.10)=1.248

1
1
k 2=f X 1+ h ,Y 1 + h k 1
2
2

(
)
1
1
k =f ( X + h ,Y + h k )
2
2
3

=(1+2(0.1)+1/2(0.1) ( 1.14 ) 1 /2(1.24 ) =0.82


=(1+2(0.1)+1/2(0.1) ( 1.14 ) 1 /2( 0.82) =0.54

k 4=f ( X 1 +h , Y 1+ h k 3 )= (1+2(0.1)+0.1(sqrt1.14)0.1(1.02)=1.21
h
Y 2=Y 1 + ( k 1+ 2 k 2+ 2 k 3+ k 4 ) =1.0049+0.1/6(0.1+2(0.15)+2(0.15)+0.2)
6
Y 2= 1.0049+0.0166(0+0.3+0.3+0.2)= 1.018
n=2
k 1=f ( X 2 , Y 2 )

= (0.2)=0.2

1
1
k 2=f X 2+ h ,Y 2 + h k 1
2
2

(
) = (0.2+1/2(0.1))=0.25
1
1
k =f ( X + h ,Y + h k ) =(0.2+1/2(0.1))=0.25
2
2
3

k 4=f ( X 2 +h , Y 2+ h k 3 )=

(0.2+0.1)=0.3

h
Y 3=Y 3 + ( k 1 +2 k 2 +2 k 3 +k 4 ) =1.018+0.1/6(0.2+2(0.25)+2(0.25)+0.3)
6
Y 3= 1.018+0.0166(0+0.5+0.5+0.3)= 1.04
n=3
k 1=f ( X 3 , Y 3 )

= (0.3)=0.3

1
1
k 2=f X 3 + h ,Y 3 + h k 1
2
2

(
) = (0.3+1/2(0.1))=0.35
1
1
k =f ( X + h ,Y + h k ) =(0.3+1/2(0.1))=0.35
2
2
3

k 4=f ( X 3 +h , Y 3+ h k 3 ) =

(0.3+0.1)=0.4

h
Y 4 =Y 3+ ( k 1+2 k 2 +2 k 3 + k 4 ) =1.04+0.1/6(0.3+2(0.35)+2(0.35)+0.4)
6
Y 4 = 1.04+0.0166(0+0.7+0.7+0.4)= 1.06
n=4
k 1=f ( X 4 ,Y 4 )

= (0.4)=0.4

1
1
k 2=f X 4 + h , Y 4 + h k 1
2
2

= (0.4+1/2(0.1))=0.45

1
1
k 3 =f X 4 + h , Y 4 + h k 2
2
2

=(0.1+1/2(0.1))=0.45
k 4=f ( X 4 +h ,Y 4+h k 3 ) =

(0.4+0.1)=0.5

h
Y 5=Y 4+ ( k 1+2 k 2 +2 k 3 + k 4 ) =1.06+0.1/6(0.4+2(0.45)+2(0.45)+0.5)
6
Y 5= 1.06+0.0166(0+0.9+0.9+0.5)= 1.09
n=5
k 1=f ( X 5 , Y 5 )

= (0.5)=0.5

1
1
k 2=f X 5 + h ,Y 5 + h k 1
2
2

(
) = (0.5+1/2(0.1))=0.55
1
1
k =f ( X + h ,Y + h k ) =(0.5+1/2(0.1))=0.55
2
2
3

k 4=f ( X 5 +h , Y 5+ h k 3 ) =

(0.5+0.1)=0.7

h
Y 6=Y 5 + ( k 1 +2 k 2 +2 k 3 +k 4 ) =1.09+0.1/6(0.5+2(0.55)+2(0.55)+0.7)
6
Y 6= 1.09+0.0166(0.5+1.1+1.1+0.7)= 1.13
n=6
k 1=f ( X 6 , Y 6 )

= (0.6)=0.6

1
1
k 2=f X 6 + h , Y 6+ h k 1
2
2

(
) = (0.6+1/2(0.1))=0.65
1
1
k =f ( X + h , Y + h k ) =(0.6+1/2(0.1))=0.65
2
2
3

k 4=f ( X 6 +h , Y 6 +h k 3 ) =

(0.6+0.1)=0.7

h
Y 7=Y 1 + ( k 1 +2 k 2 +2 k 3 +k 4 ) =1.13+0.1/6(0.6+2(0.65)+2(0.65)+0.7)
6
Y 7= 1.13+0.0166(0.6+1.3+1.3+0.8)= 1.18
n=7
k 1=f ( X 7 , Y 7 )

= (0.7)=0.7

1
1
k 2=f X 7 + h ,Y 7+ h k 1
2
2

(
) = (0.7+1/2(0.1))=0.75
1
1
k =f ( X + h , Y + h k ) =(0.7+1/2(0.1))=0.75
2
2
3

k 4=f ( X 7 +h , Y 7 +h k 3 ) =

(0.7+0.1)=0.8

h
Y 8=Y 1 + ( k 1 +2 k 2 +2 k 3 +k 4 ) =1.18+0.1/6(0.7+2(0.75)+2(0.75)+0.8)
6
Y 8= 1.18+0.0166(0.7+1.5+1.5+0.8)= 1.25
n=8
k 1=f ( X 8 , Y 8 )

= (0.8)=0.8

1
1
k 2=f X 8 + h ,Y 8+ h k 1
2
2

(
) = (0.8+1/2(0.1))=0.85
1
1
k =f ( X + h , Y + h k ) =(0.8+1/2(0.1))=0.85
2
2
3

k 4=f ( X 8 +h , Y 8 +h k 3 ) =

(0.8+0.1)=0.9

h
Y 9=Y 9+ ( k 1 +2 k 2 +2 k 3 +k 4 ) =1.25+0.1/6(0.8+2(0.85)+2(0.85)+0.9)
6
Y 2= 1.25+0.0166(0.8+1.7+1.7+0.9)= 1.33
n=9
k 1=f ( X 9 , Y 9 )

= (0.9)=0.9

1
1
k 2=f X 9 + h , Y 9+ h k 1
2
2

(
) = (0.9+1/2(0.1))=0.95
1
1
k =f ( X + h , Y + h k ) =(0.9+1/2(0.1))=0.95
2
2
3

k 4=f ( X 9 +h , Y 9 +h k 3 ) =

(0.9+0.1)=1

h
Y 10=Y 9 + ( k 1 +2 k 2+ 2 k 3+ k 4 ) =1.33+0.1/6(0.9+2(0.95)+2(0.95)+1)
6
Y 10= 1.33+0.0166(0.9+1.9+1.9+1)= 1.42

Codigo matlab
Euler

function [t,x] =euler(f,t0,tf,x0,n)


h=(tf-t0)/n;
t=t0:h:tf;
x=zeros(n+1,1); %reserva memoria para n+1 elementos del vector x
x(1)=x0;
for i=1:n
x(i+1)=x(i)+f(t(i),x(i))*h;

end
end

tf=input('tiempo final, tf: ');


n=input('nmero de pasos, n: ');
f=@(t,x) cos(t);
%condiciones iniciales
t0=0;
x0=0;
[t,x]=euler(f,t0,tf,x0,n);
hold on
plot(t,x,'b')
y=sin(t);
plot(t,y,'r')
xlabel('t')
ylabel('x');
legend('aproximada','exacta')
title('dx/dt=cost')
hold off

runge kutaa
function [t,x] =rk_1(f,t0,tf,x0,n)
h=(tf-t0)/n;
t=t0:h:tf;
x=zeros(n+1,1); %reserva memoria para n elementos del vector x
x(1)=x0;
for i=1:n
k1=h*f(t(i),x(i));
k2=h*f(t(i)+h/2,x(i)+k1/2);
k3=h*f(t(i)+h/2,x(i)+k2/2);
k4=h*f(t(i)+h,x(i)+k3);
x(i+1)=x(i)+(k1+2*k2+2*k3+k4)/6;
end
end

Mtodo del Trapecio en matlab


clear all;
clc;
fprintf('Calculo de la integral por el metodo trapecial\n\n');
f=input('introduce la funcion:','s');
a=input('lime inferior:');
b=input('limite superior:');
c=input('numero de segmentos a dividir:');
h=(b-a)/c;
z=0;

for x=a:h:b
k=eval(f);
if x==a,d=k;
end
if x==b,e=k;
end
z=z+k;
end
z=z-d-e;
z=z*2;
z=z+d+e;
z=z/(2*c);
z=z*(b-a)
fprintf('Resultado ');

Simpson 1/3 en Matlab


%regla de simpson 1/3
clear all; close all; clc
fun=input('Ingresa la funcin f(x) entre comillas: ');
f=inline(fun);
n=1;
while mod(n,2)~=0
n=input('Ingrese el nmero de subintervalos: ');
if mod(n,2)~=0
disp('El nmero de subintervalos debe ser par, pulse
una tecla para continuar')
pause
end
end
a=input('Ingrese el lmite inferior de la integral: ');
b=input('Ingrese el lmite superior de la integral: ');

h=(b-a)/n;

sumai=0;
sumap=0;

for i=1:2:n-1
sumai=sumai+feval(f,h*i+a);
end
for i=2:2:n-2
sumap=sumap+feval(f,h*i+a);
end

int=(h/3)*(feval(f,a)+4*sumai+2*sumap+feval(f,b));

disp(['El resultado de la integral es ' num2str(int)])

Potrebbero piacerti anche