Tarea 5

Descargar como docx, pdf o txt
Descargar como docx, pdf o txt
Está en la página 1de 19

1.

Determine los valores de n y h que se requieren para aproximar


2

∫ xlnx dx
1

Con una exactitud de 10−5 y calcule la aproximación.


b−a 2−1 1
h= = h=
n n n

(a) Aplique la regla compuesta del trapecio y hallamos n y h


b−a 2
| |
12
h Max |f ' ' ( μ )|

'' 1
f ( x )=xlnx dx f ( x ) =
x

2−1 1 2
| | ( ) Max 1
12 n x ||
1
2
∗0.5<10−5
12n
1
2
< 10−5
24 n

105 2
<n
24

4166.667 <n2
n=64.5497
n=65

1
h=
n
1
h=
65
h=0.01538

b) Aplique la regla compuesta de simpson.


|−b−a
180 |
4
h max|f ( IV )
( μ )|

iv 2
f ( x )=xlnx dx f ( x )=
x3

2−1 1 4 2
| |( ) | |
180 n
Max 3
x
1
4
∗0.25<10−5
180 n
1
4
<10−5
720 n

105 4
<n
720

138.889<n 4
n=4
1
h=
n
1
h=
4
h=0.25

(d) Utilice matlab, compare resultados y haga un análisis de ellos; muestre


capture.
Para la RCT se tiene
n=65
Para la RCS se tiene

n=4
Por lo que se puede concluir que entre más grande sea el n, más se acerca a la
solución exacta del problema.

2. Utilice el método de Runge-Kutta de orden 4 para aproximar la solución para


el siguiente problema de valor
inicial y compare los resultados con los valores reales. Haga un análisis de ellos y
muéstrelos en una tabla.

(a) Utilice matlab, haga la gráfica y muestre capture.


4t
y ' =−ty+ , 0 ≤ t ≤1, y ( 0 )=1 , con h=0.1, Solución real
y
2

y ( t ) =√ 4−3 e−t
Discretizacion del dominio
[0,1] con h=0,1
Hallamos las subdivisiones del intervalo

t f −t 0 1−0
n= = =10
h 0.1
Ahora hallamos los puntos
Como t 0=0 ; t i=t 0+ ih

i=0 →t 0=0+ 0 ( 0.1 )=0

i=1 →t 1=0+1 ( 0.1 )=0,1

i=2 →t 2=0+2 ( 0.1 )=0,2

i=3 →t 3=0+3 ( 0.1 ) =0,3


.
.
i=10 →t 10=0+10 ( 0.1 )=1
Adecuación de las ecuaciones
4t 4t
y ' =−ty+ , f(t,y)¿−ty + ,
y y
K 1=f ( t i , y i )

h K1
(
K 2=f ti+ , y i +
2 2
h )
h K2
K 3=f ( ti+ , i +
2 )
i h
2

K 4=f ( ti+h , i i+ K 3 h )

Código en Matlab:
clc
clf
clear all

% RK4 method

% Solve dy/dt = f(t,y). In general it can be a function of both


% variables t and y. If your function is only a function of t then
% you will need to add a 0*y to your function.

% define f(t,y)
fcnstr='t*y+4*t/y' ;
f=inline(fcnstr,'t','y') ;

% t0, initial time

t0=0 ;

% y0, corresponding value of y at t0

y0=1;

% tf, upper boundary of time t (end time).

tf=1;

% h, number of steps to take

h=0.1;

%**********************************************************************

% Displays title information


disp(sprintf('\n\nThe 4th Order Runge-Kutta Method of Solving Ordinary Differential
Equations'))
n=(tf-t0)/h ;
disp(sprintf(' n = ( tf - t0 ) / h '))
disp(sprintf(' = ( %g - %g ) / %g ',tf,t0,h))
disp(sprintf(' = %g',n))

ta(1)=t0 ;
ya(1)=y0 ;

for i=1:n
disp(sprintf('\nStep %g',i))
disp(sprintf('-----------------------------------------------------------------'))
% Adding Step Size
ta(i+1)=ta(i)+h ;

% Calculating k1, k2, k3, and k4


k1 = f(ta(i),ya(i)) ;
k2 = f(ta(i)+0.5*h,ya(i)+0.5*k1*h) ;
k3 = f(ta(i)+0.5*h,ya(i)+0.5*k2*h) ;
k4 = f(ta(i)+h,ya(i)+k3*h) ;

% Using 4th Order Runge-Kutta formula


ya(i+1)=ya(i)+1/6*(k1+2*k2+2*k3+k4)*h ;

disp('1) Find k1 and k2 using the previous step information.')


disp(sprintf(' k1 = f( x%g , y%g )',i-1,i-1))
disp(sprintf(' = f( %g , %g )',ta(i),ya(i)))
disp(sprintf(' = %g\n',k1))

disp(sprintf(' k2 = f( x%g + 0.5 * h , y%g + 0.5 * k1 * h )',i-1,i-1))


disp(sprintf(' = f( %g + 0.5 * %g , %g + 0.5 * %g * %g)',ta(i),h,ya(i),k1,h))
disp(sprintf(' = f( %g , %g )',ta(i)+0.5*h,ya(i)+0.5*k1*h))
disp(sprintf(' = %g\n',k2))

disp(sprintf(' k3 = f( x%g + 0.5 * h , y%g + 0.5 * k2 * h )',i-1,i-1))


disp(sprintf(' = f( %g + 0.5 * %g , %g + 0.5 * %g * %g)',ta(i),h,ya(i),k2,h))
disp(sprintf(' = f( %g , %g )',ta(i)+0.5*h,ya(i)+0.5*k2*h))
disp(sprintf(' = %g\n',k3))

disp(sprintf(' k4 = f( x%g + h, y%g + k3*h)',i-1,i-1))


disp(sprintf(' = f( %g , %g )',ta(i)+h,ya(i)+k3*h))
disp(sprintf(' = %g\n',k1))

disp(sprintf('2) Apply the Runge-Kutta 4th Order method to estimate y%g',i))


disp(sprintf(' y%g = y%g + 1/6*( k1 + 2*k2 + 2*k3 +k4) * h',i,i-1))
disp(sprintf(' = %g + %g * %g * %g',ya(i),1/6,(k1+2*k2+2*k3+k4),h))
disp(sprintf(' = %g\n',ya(i+1)))
disp(sprintf(' at t%g = %g',i,ta(i+1)))
end

The 4th Order Runge-Kutta Method of Solving Ordinary Differential Equations


n = ( tf - t0 ) / h
= ( 1 - 0 ) / 0.1
= 10
Step 1
-----------------------------------------------------------------
1) Find k1 and k2 using the previous step information.
k1 = f( x0 , y0 )
= f( 0 , 1 )
=0

k2 = f( x0 + 0.5 * h , y0 + 0.5 * k1 * h )
= f( 0 + 0.5 * 0.1 , 1 + 0.5 * 0 * 0.1)
= f( 0.05 , 1 )
= 0.25

k3 = f( x0 + 0.5 * h , y0 + 0.5 * k2 * h )
= f( 0 + 0.5 * 0.1 , 1 + 0.5 * 0.25 * 0.1)
= f( 0.05 , 1.0125 )
= 0.248156

k4 = f( x0 + h, y0 + k3*h)
= f( 0.1 , 1.02482 )
=0

2) Apply the Runge-Kutta 4th Order method to estimate y1


y1 = y0 + 1/6*( k1 + 2*k2 + 2*k3 +k4) * h
= 1 + 0.166667 * 1.48911 * 0.1
= 1.02482

at t1 = 0.1
Step 2
-----------------------------------------------------------------
1) Find k1 and k2 using the previous step information.
k1 = f( x1 , y1 )
= f( 0.1 , 1.02482 )
= 0.492795

k2 = f( x1 + 0.5 * h , y1 + 0.5 * k1 * h )
= f( 0.1 + 0.5 * 0.1 , 1.02482 + 0.5 * 0.492795 * 0.1)
= f( 0.15 , 1.04946 )
= 0.729142

k3 = f( x1 + 0.5 * h , y1 + 0.5 * k2 * h )
= f( 0.1 + 0.5 * 0.1 , 1.02482 + 0.5 * 0.729142 * 0.1)
= f( 0.15 , 1.06128 )
= 0.724549

k4 = f( x1 + h, y1 + k3*h)
= f( 0.2 , 1.09727 )
= 0.492795

2) Apply the Runge-Kutta 4th Order method to estimate y2


y2 = y1 + 1/6*( k1 + 2*k2 + 2*k3 +k4) * h
= 1.02482 + 0.166667 * 4.34871 * 0.1
= 1.0973

at t2 = 0.2
Step 3
-----------------------------------------------------------------
1) Find k1 and k2 using the previous step information.
k1 = f( x2 , y2 )
= f( 0.2 , 1.0973 )
= 0.948524

k2 = f( x2 + 0.5 * h , y2 + 0.5 * k1 * h )
= f( 0.2 + 0.5 * 0.1 , 1.0973 + 0.5 * 0.948524 * 0.1)
= f( 0.25 , 1.14472 )
= 1.15975

k3 = f( x2 + 0.5 * h , y2 + 0.5 * k2 * h )
= f( 0.2 + 0.5 * 0.1 , 1.0973 + 0.5 * 1.15975 * 0.1)
= f( 0.25 , 1.15528 )
= 1.15441

k4 = f( x2 + h, y2 + k3*h)
= f( 0.3 , 1.21274 )
= 0.948524

2) Apply the Runge-Kutta 4th Order method to estimate y3


y3 = y2 + 1/6*( k1 + 2*k2 + 2*k3 +k4) * h
= 1.0973 + 0.166667 * 6.93017 * 0.1
= 1.2128

at t3 = 0.3
Step 4
-----------------------------------------------------------------
1) Find k1 and k2 using the previous step information.
k1 = f( x3 , y3 )
= f( 0.3 , 1.2128 )
= 1.35329

k2 = f( x3 + 0.5 * h , y3 + 0.5 * k1 * h )
= f( 0.3 + 0.5 * 0.1 , 1.2128 + 0.5 * 1.35329 * 0.1)
= f( 0.35 , 1.28046 )
= 1.54152

k3 = f( x3 + 0.5 * h , y3 + 0.5 * k2 * h )
= f( 0.3 + 0.5 * 0.1 , 1.2128 + 0.5 * 1.54152 * 0.1)
= f( 0.35 , 1.28988 )
= 1.53683

k4 = f( x3 + h, y3 + k3*h)
= f( 0.4 , 1.36648 )
= 1.35329

2) Apply the Runge-Kutta 4th Order method to estimate y4


y4 = y3 + 1/6*( k1 + 2*k2 + 2*k3 +k4) * h
= 1.2128 + 0.166667 * 9.22747 * 0.1
= 1.36659

at t4 = 0.4
Step 5
-----------------------------------------------------------------
1) Find k1 and k2 using the previous step information.
k1 = f( x4 , y4 )
= f( 0.4 , 1.36659 )
= 1.71743

k2 = f( x4 + 0.5 * h , y4 + 0.5 * k1 * h )
= f( 0.4 + 0.5 * 0.1 , 1.36659 + 0.5 * 1.71743 * 0.1)
= f( 0.45 , 1.45246 )
= 1.89288

k3 = f( x4 + 0.5 * h , y4 + 0.5 * k2 * h )
= f( 0.4 + 0.5 * 0.1 , 1.36659 + 0.5 * 1.89288 * 0.1)
= f( 0.45 , 1.46124 )
= 1.88939

k4 = f( x4 + h, y4 + k3*h)
= f( 0.5 , 1.55553 )
= 1.71743

2) Apply the Runge-Kutta 4th Order method to estimate y5


y5 = y4 + 1/6*( k1 + 2*k2 + 2*k3 +k4) * h
= 1.36659 + 0.166667 * 11.3455 * 0.1
= 1.55568

at t5 = 0.5
Step 6
-----------------------------------------------------------------
1) Find k1 and k2 using the previous step information.
k1 = f( x5 , y5 )
= f( 0.5 , 1.55568 )
= 2.06345

k2 = f( x5 + 0.5 * h , y5 + 0.5 * k1 * h )
= f( 0.5 + 0.5 * 0.1 , 1.55568 + 0.5 * 2.06345 * 0.1)
= f( 0.55 , 1.65885 )
= 2.23859

k3 = f( x5 + 0.5 * h , y5 + 0.5 * k2 * h )
= f( 0.5 + 0.5 * 0.1 , 1.55568 + 0.5 * 2.23859 * 0.1)
= f( 0.55 , 1.66761 )
= 2.23644

k4 = f( x5 + h, y5 + k3*h)
= f( 0.6 , 1.77933 )
= 2.06345

2) Apply the Runge-Kutta 4th Order method to estimate y6


y6 = y5 + 1/6*( k1 + 2*k2 + 2*k3 +k4) * h
= 1.55568 + 0.166667 * 13.4299 * 0.1
= 1.77951

at t6 = 0.6
Step 7
-----------------------------------------------------------------
1) Find k1 and k2 using the previous step information.
k1 = f( x6 , y6 )
= f( 0.6 , 1.77951 )
= 2.41639

k2 = f( x6 + 0.5 * h , y6 + 0.5 * k1 * h )
= f( 0.6 + 0.5 * 0.1 , 1.77951 + 0.5 * 2.41639 * 0.1)
= f( 0.65 , 1.90033 )
= 2.6034

k3 = f( x6 + 0.5 * h , y6 + 0.5 * k2 * h )
= f( 0.6 + 0.5 * 0.1 , 1.77951 + 0.5 * 2.6034 * 0.1)
= f( 0.65 , 1.90968 )
= 2.60278

k4 = f( x6 + h, y6 + k3*h)
= f( 0.7 , 2.03979 )
= 2.41639

2) Apply the Runge-Kutta 4th Order method to estimate y7


y7 = y6 + 1/6*( k1 + 2*k2 + 2*k3 +k4) * h
= 1.77951 + 0.166667 * 15.6293 * 0.1
= 2.04

at t7 = 0.7
Step 8
-----------------------------------------------------------------
1) Find k1 and k2 using the previous step information.
k1 = f( x7 , y7 )
= f( 0.7 , 2.04 )
= 2.80055

k2 = f( x7 + 0.5 * h , y7 + 0.5 * k1 * h )
= f( 0.7 + 0.5 * 0.1 , 2.04 + 0.5 * 2.80055 * 0.1)
= f( 0.75 , 2.18003 )
= 3.01115

k3 = f( x7 + 0.5 * h , y7 + 0.5 * k2 * h )
= f( 0.7 + 0.5 * 0.1 , 2.04 + 0.5 * 3.01115 * 0.1)
= f( 0.75 , 2.19056 )
= 3.01243

k4 = f( x7 + h, y7 + k3*h)
= f( 0.8 , 2.34125 )
= 2.80055

2) Apply the Runge-Kutta 4th Order method to estimate y8


y8 = y7 + 1/6*( k1 + 2*k2 + 2*k3 +k4) * h
= 2.04 + 0.166667 * 18.0875 * 0.1
= 2.34146

at t8 = 0.8
Step 9
-----------------------------------------------------------------
1) Find k1 and k2 using the previous step information.
k1 = f( x8 , y8 )
= f( 0.8 , 2.34146 )
= 3.23984

k2 = f( x8 + 0.5 * h , y8 + 0.5 * k1 * h )
= f( 0.8 + 0.5 * 0.1 , 2.34146 + 0.5 * 3.23984 * 0.1)
= f( 0.85 , 2.50345 )
= 3.48606

k3 = f( x8 + 0.5 * h , y8 + 0.5 * k2 * h )
= f( 0.8 + 0.5 * 0.1 , 2.34146 + 0.5 * 3.48606 * 0.1)
= f( 0.85 , 2.51576 )
= 3.48988

k4 = f( x8 + h, y8 + k3*h)
= f( 0.9 , 2.69045 )
= 3.23984

2) Apply the Runge-Kutta 4th Order method to estimate y9


y9 = y8 + 1/6*( k1 + 2*k2 + 2*k3 +k4) * h
= 2.34146 + 0.166667 * 20.9512 * 0.1
= 2.69065

at t9 = 0.9
Step 10
-----------------------------------------------------------------
1) Find k1 and k2 using the previous step information.
k1 = f( x9 , y9 )
= f( 0.9 , 2.69065 )
= 3.75955

k2 = f( x9 + 0.5 * h , y9 + 0.5 * k1 * h )
= f( 0.9 + 0.5 * 0.1 , 2.69065 + 0.5 * 3.75955 * 0.1)
= f( 0.95 , 2.87862 )
= 4.05477

k3 = f( x9 + 0.5 * h , y9 + 0.5 * k2 * h )
= f( 0.9 + 0.5 * 0.1 , 2.69065 + 0.5 * 4.05477 * 0.1)
= f( 0.95 , 2.89339 )
= 4.06206

k4 = f( x9 + h, y9 + k3*h)
= f( 1 , 3.09685 )
= 3.75955

2) Apply the Runge-Kutta 4th Order method to estimate y10


y10 = y9 + 1/6*( k1 + 2*k2 + 2*k3 +k4) * h
= 2.69065 + 0.166667 * 24.3817 * 0.1
= 3.09701

at t10 = 1
Tabla
I ti yi Solución
exacta
0 0,0000 1 1.0000
1 0,1000 1.02482 1.0148
2 0,2000 1.0973 1.0572
3 0,3000 1.2128 1.1217
4 0,4000 1.36659 1.2015
5 0,5000 1.55568 1.2898
6 0,6000 1.77951 1.3809
7 0,7000 2.04 1.4704
8 0,8000 2.34146 1.5550
9 0,9000 2.69065 1.6326
10 1,0000 3.09701 1.7019

Gráfica correspondiente a la solución numérica y a la solución exacta

También podría gustarte