Tarea 5
Tarea 5
Tarea 5
∫ xlnx dx
1
'' 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
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
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.
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
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
% define f(t,y)
fcnstr='t*y+4*t/y' ;
f=inline(fcnstr,'t','y') ;
t0=0 ;
y0=1;
tf=1;
h=0.1;
%**********************************************************************
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 ;
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
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
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
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
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
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
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
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
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
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
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