Beruflich Dokumente
Kultur Dokumente
Mecnica Computacional II
CAPITULO II
Derivacin e integracin
numrica
Captulo II
Derivacin e integracin numrica
Introduccin
Derivacin numrica
Integracin numrica
Referencias
Introduccin
Introduccin
Captulo II
Derivacin e integracin numrica
Introduccin
Derivacin numrica
Integracin numrica
Referencias
Derivacin numrica
donde
2
n
k
n
(
(
(
x x0 )
x x0 )
x x0 )
(n )
(k )
P( x ) = f (x0 ) + f ( x0 )(x x0 ) + f ( x0 )
+ ... + f ( x0 )
= f ( x0 )
2!
n!
k!
R( x ) = f
( n +1)
k =0
n +1
(
x x0 )
( (x ))
(n + 1)!
Residuo
Derivacin numrica
t (
n
n +1
Derivacin numrica
Derivacin numrica
obtenemos
f ( xi +1 ) f ( xi )
df
=
+ O ( x )
dx x
x
10
Derivacin numrica
df
+ O ( x 2 )
dx x
f ( xi ) f ( xi 1 )
df
=
+ O ( x )
dx x
x
Estas ecuaciones
corresponden a las
pendientes de rectas que
unen a los distintos
puntos.
xi
11
Derivacin numrica
+ O ( x3 )
x
+ O ( x3 )
x
12
Derivacin numrica
Al despejar
f ( x + x ) f ( x x )
df
=
+ O ( x 2 )
dx x
2x
Esta ecuacin es de un
orden mayor de precisin y
se interpreta como se
muestra en la figura
xi
13
Derivacin numrica
14
Derivacin numrica
x
(
)
2
1! dx x
2! dx x
2
f ( x + 2x ) = f ( x )
2x ) df
(
+
2
( 2x ) d f
3
+
+
O
x
(
)
2
1! dx x
2! dx x
2
x ) df
(
+2
3
+
O
x
(
)
1! dx x
15
Derivacin numrica
Simplificando obtenemos
3 f ( x ) + 4 f ( x + x ) f ( x + 2x )
df
=
+ O ( x 2 )
dx x
2x
En notacin indicial
3 f ( xi ) + 4 f ( xi +1 ) f ( xi + 2 )
df
=
+ O ( x 2 )
dx x
2x
16
Derivacin numrica
(
)
2
2
( x )
dx x
2 f j 5 f j 1 + 4 f j 2 f j 3
d2 f
2
=
+
O
x
(
)
2
2
( x )
dx x
2 f j 5 f j +1 + 4 f j + 2 f j +3
d2 f
2
=
+
O
x
(
)
2
2
( x )
dx x
17
Derivacin numrica
f(x)
10.88936544
12.70319944
14.7781122
x =1.8
0.1
df ( x )
3 f (1.8) + 4 f (1.9) f (2.0)
=
+ O x 2 = 16.8329463
dx x =1.8
2 * 0.1
( )
18
Derivacin numrica
( )
( )
19
Derivacin numrica
Error (%)
x
1.8
1.9
2
Exacta
Adelante
f(x) [O(Dx)]
f(x)
f(x)
10.88936544 16.9390129
18.13834
12.70319944 19.38909388 20.7491276
14.7781122
22.1671683
Error (%)
x
1.8
1.9
2
Exacta
Atrs
f(x) [O(Dx)]
f(x)
f(x)
10.88936544 16.9390129
12.70319944 19.38909388
18.13834
14.7781122
22.1671683
20.7491276
x
1.8
1.9
2
f(x) [O(Dx2)]
f(x)
f(x)
10.88936544 16.9390129
16.8329463
12.70319944 19.38909388
14.7781122
22.1671683
x
1.8
1.9
2
Exacta
Centrada
f(x) [O(Dx2)]
f(x)
f(x)
10.88936544 16.9390129
12.70319944 19.38909388 19.4437338
14.7781122
22.1671683
7.08
7.01
Hacia
adelante
Orden 1
Hacia atrs
Orden 1
-6.45
-6.40
-0.63
Error (%)
0.28
Hacia
adelante
Orden 2
Centrada
Orden 2
20
Derivacin numrica
f(x+h)
52.705
14.7781
12.8984
12.7226
12.7051
12.7034
12.7032
12.7032
12.7032
Error
empieza
a crecer
Error es
mximo!
21
Derivacin numrica
dx
2x
( )
+ O x 2
2x
( )
+ O x 2
22
Derivacin numrica
=
+ O(x 2 )
dx
2x
2x
=
+ O(x 2 )
dx
2x
23
Derivacin numrica
24
Derivacin numrica
25
Captulo II
Derivacin e integracin numrica
Introduccin
Derivacin numrica
Integracin numrica
Referencias
26
Integracin numrica
27
Integracin numrica
y
1.3
3.5
4.2
5
7
8.8
10.1
12.5
13
15.6
INTEGRACION NUMERICA
12
10
8
f(x)
x
1
2
3
4
5
6
7
8
9
10
6
4
2
0
0
10
12
10
12
x
INTEGRACION NUMERICA
12
Si utilizamos la
definicin de integracin
8
f(x)
10
f ( x ) dx = lim f ( x )x
n
i =1
4
2
0
0
6
x
28
Integracin numrica
n1
i=1
i=1
f (x)dx= h f (x ) = h[ f + f + f +...f
b
i=1
n2
+ fn1]
29
Integracin numrica
b a
Considere diferentes valores de h. Si hacemos h =
n
tendremos
n1
f (x)dx= h f (x )
b
i=0
n1
x
e
dx= h(a +ih) 2(a +ih) +8
b
i=0
n1
x
e
dx= h(ih) 2(ih) +8 =
6
i=0
30
Integracin numrica
f(x)
8
7
8
11
16
23
Luego,
n1
f (x)dx= h f (x ) =1[8+7+8+11+16+23] = 73
b
i=0
31
Integracin numrica
Entonces,
x 2
0 x 2x +8dx= 3 x +8x +C = 84
0
y el error relativo es:
6
84 73
E=
* 100 = 13 .1 %
84
h
1
0.1
0.01
0.001
0.0001
Integral
73.0000
82.8100
83.8801
83.9880
83.9988
Error
-13.09524
-1.41667
-0.14274
-0.01428
-0.00143
32
Integracin numrica
tendremos
n1
f (x)dx= h f (x )
b
i=0
n1
a+ih
e
dx
=
h
e
i=0
n1
x
ih
0h
h
2h
(n2)h (n1)h
e
dx
=
h
e
=
h
e
+
e
+
e
+
...
+
e
+e
i=0
33
Integracin numrica
h
1
0.1
Integral
234.20418
382.64266
Error
-41.8023
-4.9167
600
0.01
400.42000
-0.4992
6000
0.001
402.22761
-0.0500
60000
0.0001
402.40867
-0.0050
34
Integracin numrica
El siguiente programa fue utilizado para obtener los resultados
anteriores
% programa integra
clear all
clc
% Integracin de f(x) entre a y b para
% distintos valores de discretizacin
% Definicin de la funcin
f=inline('x^2-2*x+8');
% f=inline('exp(x)');
% Integral terica
f_int=inline('x^3/3-x^2+8*x');
% f_int=inline('exp(x)');
% Limites de la integracin
a=0; b=6;
% Grafica de la funcin
ezplot(f,[a,b])
35
Integracin numrica
f(x)
8
6
4
2
0
0
10
12
x = ( f0 + 2 f1 + 2 f2 + ...+ 2 fn1 + fn )
a f (x)dx
2
2
i =0
36
Integracin numrica
x = ( f0 + 2 f1 + 2 f2 + ...+ 2 fn1 + fn )
a f (x)dx
2
2
i =0
n
b
h 0h
fi + fi+1
x
1h
2h
(n1)h
nh
e
dx
x
=
e
+
2
e
+
2
e
+
...
+
2
e
+
e
a
2
2
i =0
37
Integracin numrica
h
1
0.1
0.01
0.001
0.0001
Integral
435.41858
402.76409
402.43215
402.42883
402.42879
Error
8.19767
0.08332
0.00083
0.00001
0.00000
38
Integracin numrica
xi+1
xi
f (x)dx =
xi+1
xi
xi
= f (xi )(xi+1 xi ) + O (x xi )
f (xi )
xi
xi+1
39
Integracin numrica
xi+1
xi
f (x)dx =
xi+1
xi
f (xi )dx +
= f (xi )(xi+1
xi+1
xi
xi
2
(
xi+1 xi )
3
x ) + f (x )
+ O((x x ) )
i
40
Integracin numrica
f (xi+1 )
f (xi )
xi
xi+1
41
Integracin numrica
(x x1)
2!
+ f (x1)
(x x1)
3!
+O (x x1)
f (x2 )
f (x1)
f (x0 )
x0
x1
x2
42
Integracin numrica
x2
x0
x0
x2
x2
x0
(
x x1 )
f (x )
Integrando
f (x)dx = f (x )x
x2
x0
x0
3!
x0
(
x x1 )
+ f (x )
2 x2
x2
x0
(
x x1 )
+ f (x )
24
x0
2
(
x x1 )
f (x )
dx
1
2!
dx + O (x x1 ) dx
x2
x0
4 x2
x2
(
x x1 )
+ f (x )
3 x2
x0
+ O (x x1 )
x0
43
Integracin numrica
(
x x1)
f (x )
2 x2
x0
(
x x1)
f (x )
3 x2
x0
(
x x1)
f (x )
4 x2
24
x0
f (x1)
f (x1) 2 2
2
2
(x2 x1) (x0 x1) =
=
h h = 0
2
2
f (x1)
f (x1) 3
f (x1) 3
3
3
3
(x2 x1) (x0 x1) =
=
h (h) =
h
6
6
3
f (x1)
f (x1) 4 4
4
4
(x2 x1) (x0 x1) =
=
h h = 0
24
24
Luego, tendremos
44
Integracin numrica
f (x1 ) 3
5
(
)
(
)
f
x
dx
=
2
hf
x
+
h
+
O
h
1
x0
3
Utilizando la expresin centrada para la segunda
derivada obtenemos (cuidado con el orden del error!)
( )
x2
x2
x0
( )h
x2
x0
h
f (x)dx [ f (x0 ) + 4 f (x1 ) + f (x2 )]
3
45
Integracin numrica
x0
x1
x2
x3
f (x)dx f (x)dx
x2
x4
x0
x2
x4
x2 j2
x2 j
x2 j2
x2 j1
x2 j
f (x)dx
xn1
xn2
xn
xn2
xn
f (x)dx
46
Integracin numrica
x2 j
j =1
x2 j2
f (x)dx
b
x0
x1
x2
x3
f (x)dx f (x)dx
x2
x4
x0
x2
h
f (x)dx = f (x2 j 2 ) + 4 f (x2 j 1 ) + f (x2 j )
j =1 3
n/ 2
x4
x2 j2
x2 j
x2 j2
x2 j1
x2 j
f (x)dx
xn1
xn2
xn
xn2
xn
f (x)dx
47
Integracin numrica
Desarrollando tenemos
b
h
a f (x)dx 3 [ f (x0 ) + 4 f (x1 ) + f (x2 ) + f (x2 ) + 4 f (x3 ) + f (x4 ) +
.... + f (x2 j 4 ) + 4 f (x2 j 3 ) + f (x2 j 2 ) + f (x2 j 2 ) + 4 f (x2 j 1 ) + f (x2 j )
+ f (x2 j ) + 4 f (x2 j +1 ) + f (x2 j +2 )
.....
Reagrupando llegamos a:
b
n/ 2
n / 21
h
f (x)dx f (x0 ) + 4 f (x2 j 1 ) + 2 f (x2 j ) + f (xn )]
3
j =1
j =1
48
Integracin numrica
h
1
0.1
0.01
0.001
0.0001
Integral
404.423706
402.429017
402.428794
402.428793
402.428793
Error
0.49571807
5.5489E-05
5.5555E-09
6.78E-13
-2.119E-13
49
Integracin numrica
k = 0, 1,...,n
con
xi+n xi
h=
n
xi
xi+1
xi+2
xi+n
50
Integracin numrica
xi
i +n
f (x)dx ak f (xk )
k =i
(
xx )
= L (x)dx =
dx
(x x )
xi+n i+n
xi+n
xi
xi
j =i
j k
51
Integracin numrica
f (x)dx a f (x ) = a f (x ) + a f (x )
xi+1
xi
k =i
(
xx )
a =
dx
(x x )
xi+1 i+1
xi
j =i
j k
i +1
i +1
xi+n xi
h=
= xi+1 xi
n
(
xx )
(
xx )
1 ( x x )
a =
dx=
dx=
(x x )
(x x ) (x x ) 2
xi+1
ai+1
xi
i+1
j=i
ji
xi+1
2 xi+1
i+1
xi
i+1
i+1
i+1
(
xx )
(
xx )
=
dx=
dx=
(x x )
(x x ) (x
xi+1
xi
i+1
j =i
j i+1
xi+1
i+1
xi
i+1
(
xi+1 xi )
=
xi
(
xi+1 xi )
1 (x xi )
=
2 x
2
i+1 xi )
i
2 xi+1
52
Integracin numrica
Luego,
(
xi+1 xi )
h
x f (x)dx 2 [ f (xi ) + f (xi+1)] = 2 [ f (xi ) + f (xi+1)]
xi+1
i
53
Integracin numrica
54
Integracin numrica
x
-1
-0.5
0
0.5
1
1.5
2
2.5
3
3.5
4
4.5
5
f(x)
-0.54030231
1.00383983
1
1.12113827
1.27606119
1.08230025
0.38572388
-0.63819594
-1.57593958
-1.95268821
-1.42405796
0.07483521
2.26729225
x cos(x)+(x3+1) exp(-x)
2.5
2
1.5
1
0.5
0
-0.5
-1
-1.5
-2
-1
2
x
55
Integracin numrica
Trapecio
1
2
3
4
5
6
7
8
9
10
11
12
2
1.5
1
f(x)
0.5
0
-0.5
-1
-1.5
-2
-1
2
x
I_trapecio
0.11588438
0.50095996
0.53028457
0.59929987
0.58959036
0.36700603
-0.06311802
-0.55353388
-0.88215695
-0.84418654
-0.33730569
0.58553186
0.60825596
56
Integracin numrica
n=2, tenemos:
h
h5 (4)
xi f (x)dx = 3 [ f (xi ) + 4 f (xi+1) + f (xi+2 )] 90 f ( )
xi < < xi+2
xi+2
Regla de Simpson
2.5
i
0
1
2
3
4
5
6
7
8
9
10
11
12
2
1.5
1
f(x)
0.5
0
-0.5
-1
-1.5
-2
-1
2
x
x
-1
-0.5
0
0.5
1
1.5
2
2.5
3
3.5
4
4.5
5
f(x)
I_Simpson
-0.54030231
1.00383983 0.74584284
1
1.12113827 1.12676905
1.27606119
1.08230025 0.99849768
0.38572388
-0.63819594 -0.62383324
-1.57593958
-1.95268821 -1.80179173
-1.42405796
0.07483521 0.19042919
2.26729225
0.63591378
57
Integracin numrica
i
0
1
2
3
4
5
6
7
8
9
10
11
12
2
1.5
1
f(x)
0.5
0
-0.5
-1
-1.5
-2
-1
2
x
x
-1
-0.5
0
0.5
1
1.5
2
2.5
3
3.5
4
4.5
5
f(x)
I_Simpson 3/8
-0.54030231
1.00383983
1 1.236066649
1.12113827
1.27606119
1.08230025 1.609114964
0.38572388
-0.63819594
-1.57593958 -1.539257038
-1.95268821
-1.42405796
0.07483521 -0.699949537
2.26729225
0.605975037
58
Integracin numrica
n=4,
2h
8h7 (6)
xi f (x)dx 45[7 f (xi ) +32f (xi+1) +12f (xi+2 ) +32f (xi+3) +7 f (xi+4 )] 945f ()
xi < < xi+4
xi+4
i
0
1
2
3
4
5
6
7
8
9
10
11
12
2
1.5
1
f(x)
0.5
0
-0.5
-1
-1.5
-2
-1
2
x
x
-1
-0.5
0
0.5
1
1.5
2
2.5
3
3.5
4
4.5
5
f(x)
n=4
-0.54030231
1.00383983
1 1.892213589
1.12113827
1.27606119
1.08230025
0.38572388 0.372019465
-0.63819594
-1.57593958
-1.95268821
-1.42405796 -1.607567172
0.07483521
2.26729225
0.656665882
59
Integracin numrica
MATLAB calcula fcilmente la integral numrica de la funcin
f, entre a y b utilizando las siguientes instrucciones:
f=inline ('x.*cos (x)+(x.^3+1).*exp (-x)');
a=-1; b=5;
int_teo=quad(f,a,b)
int_teo =
0.6652
Tambin, la integral puede ser obtenida analticamente:
syms x Integ;
Integ = int(x.*cos (x)+(x.^3+1).*exp (-x));
pretty(Integ)
60
Integracin numrica
Trapecio
0.60825596
8.563
0.64948424
2.365
0.65810058
1.070
0.66119032
0.606
Simpson
Simpson_3_8
0.63591378
0.60597504
4.405
8.906
0.66322699
0.66086051
0.300
0.655
0.66481971
0.66433115
0.060
0.134
0.66509235
0.66493535
0.019
0.043
n=4
0.65666588
1.286
0.66504788
0.026
0.66520375
0.002
0.6652167
0.000
61
Integracin numrica
Regla del trapecio
Regla de Simpson
2.5
1.5
1.5
0.5
0.5
-0.5
-0.5
-1
-1
-1.5
-1.5
f(x)
2.5
-2
-1
2
x
-2
-1
2.5
1.5
1.5
0.5
0.5
-0.5
-0.5
-1
-1
-1.5
-1.5
2
x
-2
-1
-2
-1
62
Integracin numrica
63
Captulo II
Derivacin e integracin numrica
Introduccin
Derivacin numrica
Integracin numrica
Referencias
64
Referencias
65
Mecnica Computacional II
Captulo II
Derivacin e integracin
numrica