Documente Academic
Documente Profesional
Documente Cultură
C
alculo Numerico
Tema N 4, 20 de Octubre de 2014
Diferenciaci
on e Integraci
on
Recordemos que la aproximacion de una funcion f (x) por Lagrange establece que :
f (x) = P (x) + E(x)
f (x) = P (x) +
f (n+1) (c)
(x x0 ) (x x1 ) ... (x xn )
(n + 1)!
n
n
Y
X
(x xi )
P (x) =
f (xk )
(xk xi )
k=0
i=0
i 6= k
en un soporte S = {x0 , x1 , .., xn } distintos en [a, b] y f C n+1 ([a, b]) , c(x) (a, b) .
Por otro lado la derivada
f (x0 + h) f (x0 )
.
f 0 (x0 ) = lim
h0
h
Como aproximamos la derivada de f (x) en un punto de S?
Supongamos que x0 (a, b) , donde f C 2 ([a, b]) y x1 = x0 + h, con h 6= 0 suficientemente
peque
no tal que x1 [a, b] . Si aproximamos f usando P (x) en S = {x0 , x1 } , tenemos:
f (x) = P (x) +
f (x) = f (x0 )
f (x) = f (x0 )
f (2) (c(x))
(x x0 ) (x x1 )
2!
(x x1 )
(x x0 )
f (2) (c(x))
+ f (x1 )
+
(x x0 ) (x x1 )
(x0 x1 )
(x1 x0 )
2!
(x x0 h)
(x x0 ) f (2) (c(x))
+ f (x0 + h)
+
(x x0 ) (x x0 h)
h
h
2!
para alg
un c(x) (a, b) . Si derivamos c/r a x tenemos que:
f (x0 + h) f (x0 )
d f (2) (c(x))
0
f (x) =
+
(x x0 ) (x x0 h)
h
dx
2!
f
(x
+
h)
f
(x
)
d
(x
x
)
(x
h)
0
0
0
0
f 0 (x) =
+
f (2) (c(x))
h
dx
2!
2
(x
x
)
h
0
+f (2) (c(x))
2!
1
f (x0 + h) f (x0 )
.
h
d
f (2) (c(x)) = f (2) (c(x))c0 (x), sin embargo,
Pero la dificultad es que no podemos estimar
dx
cuando x = x0 el coeficiente se hace cero y por lo tanto
f (x0 + h) f (x0 )
h
0
(2)
f (x) =
f (c(x))
(1)
h
2!
para alg
un c(x0 ) (a, b) . Lo que ademas nos indica que para h peque
nos la aproximacion
Mh
mejorara, entonces el error cometido es |E(x)| <
donde
2
f (2) (x) < M , x [a, b]
Obs: Si h > 0 la formula (1) se llama diferencia progresiva y diferencia regresiva si h < 0.
Ejemplo: Sea f (x) = ln(x) y x0 = 1.8. Aproxime f 0 (1.8) usando diferencia progresiva y
diferencia regresiva y estime el error cometido. R : f 0 (1.8) = 0.5.
En general la formula (1) se puede generalizar para el soporte S = {x0 , x1 , .., xn } distintos
en [a, b] y f C n+1 ([a, b]) , c(x) (a, b) :
0
f (xk ) =
n
X
j=0
f (n+1) (c (xk ))
+
(n + 1)!
n
Y
(xk xj ) (2)
j=0
j 6= k
2
P
j=0
+f
(3) (c(x
k ))
f (3) (c(xk ))
(3)!
2
Q
(xk xj ) = f (x0 )P00 (xk ) + f (x1 )P10 (xk ) + f (x2 )P20 (xk )
j=0
j 6= k
2
Q
(3)!
(xk xj )
j=0
j 6= k
0
0
0
(xk x1 ) (xk x2 )
(xk x0 ) (xk x2 )
(xk x0 ) (xk x1 )
0
f (xk ) = f (x0 )
+ f (x1 )
+ f (x2 )
(x1 x0 ) (x1 x2 )
(x2 x0 ) (x2 x1 )
(x0 x1 ) (x0 x
2 )
f (3) (c (xk ))
(xk xj )
j=0
j 6= k
2x
x
2x
x
2x
x
k
0
2
k
0
1
k
1
2
+ f (x1 )
+ f (x2 )
f 0 (xk ) = f (x0 )
x2 )
(x1 x0 ) (x1 x2 )
(x2 x0 ) (x2 x1 )
(x0 x1 ) (x0
f (3) (c (xk ))
2
Q
(xk xj )
j=0
j 6= k
2
Q
f (3) (c (xk ))
(xk xj )
j=0
j 6= k
2
Q
f (x0 ) = f (x0 )
3
2h
2
1
f (3) (c (x0 ))
+ f (x1 )
+ f (x2 )
+
h
2h
6
(x0 xj )
j=0
j 6= k
2
Q
f 0 (x0 ) =
f (3) (c (x0 ))
1
[3f (x0 ) + 4f (x1 ) f (x2 )] +
[(x0 x1 ) (x0 x2 )]
2h
6
f 0 (x0 ) =
1
1
[3f (x0 ) + 4f (x0 + h) f (x0 + 2h)] + f (3) (c (x0 )) [h 2h]
2h
6
f 0 (x0 ) =
1
h2
[3f (x0 ) + 4f (x0 + h) f (x0 + 2h)] + f (3) (c (x0 ))
2h
3
donde c(x0 ) (x0 , x0 + 2h) . La formula anterior es conocida como la de 3-puntos progresiva.
De forma similar con un soporte S = {x0 , x1 , x2 } equiespaciado x2 = x0 2h, x1 = x0 h y
x0 obtenemos la formula conocida como la de 3-puntos regresiva:
f 0 (x0 ) =
1
h2
[f (x0 2h) 4f (x0 h) + 3f (x0 )] + f (3) (c (x0 ))
2h
3
h2
1
[f (x0 h) + f (x0 + h)] f (3) (c (x0 ))
2h
6
Ejemplo: Sea f (x) = xex entonces f 0 (x) = ex + xex , en donde f 0 (2.0) = 22. 167168. Luego
a modo de ejemplo considerando la tabla
x
f (x)
1.8
1.9
2.0
2.1
2.2
10.889365 12.703199 14.778112 17.148957 19.855030
1
[3f (2.0) + 4f (2.1) f (2.2)] = 22.032310 y E = 1.35 101
0.2
h = 0.1 =
1
[3f (2.0) + 4f (1.9) f (1.8)] = 22.054525 y E = 1.13 101
0.2
h = 0.1 =
1
[f (2.1) + f (1.9)] = 22.228790 y E = 6.16 102
0.2
h = 0.2 =
1
[f (2.2) + f (1.8)] = 22.414163 y E = 2.47 101
0.4
x3 e1.3x
con x en radianes. Use una tabla para aproxmar f 0 (0.0)
cos(x)
con cinco cifras significativas.
Sol: Considerando un tama
no de paso h = 0.1, obtenemos
Ejercicio:
x
f (x)
f 0 (0.0)
Sea f (x) =
0.2
6. 293 9 103
0.1
8. 825 104
0.0
0.1
0.0 1. 144 5 103
0.2
1. 058 6 102
1
1
[3f (0.0) + 4f (0.1) f (0.2)] =
[3 (0.0) + 4 (1. 144 5 103 ) 1. 058 6 102 ]
0.2
0.2
f 0 (0.0) 0.030 04
f 0 (0.0)
1
1
[f (0.1) + f (0.1)] =
[ (8. 825 104 ) + (1. 144 5 103 )] = 0.0135
0.2
0.2
f 0 (0.0)
1
1
[f (0.2) 4f (0.1) + 3f (0.0)] =
[(6. 293 9 103 ) 4 (8. 825 104 ) + 3 (0.0)]
0.2
0.2
0.01
9. 871 3 107
0.0
0.0
0.01
1. 013 1 106
0.02
8. 212 4 106
1
f 0 (0.0)
[3f (0.00) + 4f (0.01) f (0.02)]
0.2
1
[3 (0.00) + 4 (1. 013 1 106 ) (8. 212 4 106 )] 2. 08 105
=
0.2
1
1
[f (0.01) + f (0.01)] =
[ (9. 871 3 107 ) + (1. 013 1 106 )]
0.2
0.2
f 0 (0.0) 1. 000 1 105
f 0 (0.0)
1
f 0 (0.0)
[f (0.02) 4f (0.01) + 3f (0.00)]
0.2
1
=
((7. 796 2 106 ) 4 (9. 871 3 107 ) + 3 (0.0)) 1. 923 8 105
0.2
Optimizaci
on del tama
no de paso h
Seg
un lo que hemos estudiado en las formulas de n + 1 puntos h debe ser peque
no en funcion
de reducir el error y mejorar la aproximacion de la derivada f(x0 ). Pero el error esta formado
por un error de redondeo y uno de truncamiento, por lo tanto:
Consideremos el caso de la formula de los 3puntos central
f 0 (x0 ) =
1
h2
[f (x0 h) + f (x0 + h)] f (3) (c (x0 ))
2h
6
ET
ET
ET
ET
h
i
0
1
f(x0 h) + f(x0 + h)
= f (x0 )
2h
0
1
= f (x0 )
[ (f (x0 h) E (x0 h)) + (f (x0 + h) E (x0 + h))]
2h
0
1
1
= f (x0 )
[f (x0 h) + f (x0 + h)] +
[E (x0 + h) E (x0 h)]
2h
2h
1
1
f 0 (x0 )
[f (x0 h) + f (x0 + h)] +
|[E (x0 + h) E (x0 h)]|
2h
2h
ET
1
h2 (3)
f (c (x0 )) +
|[E (x0 + h) E (x0 h)]|
6
2h
si suponemos contantes de acotamiento M , > 0 entonces f (3) (c (x0 )) < M y E (x0 h) <
ET
donde definimos E1 (h) =
h2
M+
6
h
h2
Obs: De la expresion del error total se deduce que si h 0 entonces E1 (h) 0 pero
E2 (h) + y el caso contrario si h + . Luego h no puede ser tan peque
no ni tan
grande, debe tener un optimo.
Esto es, si tomamos la igualdad para el error total tenmos:
ET (h) =
h2
M+
6
h
6
M 2
3
h
3
2
M
00
, u
nico punto crtico y como ET (h) =
+ 3 entonces al
M
3
h
evaluar
00
ET (
=
As finalmente h
r
3
r
3
3
M
2M
)=
+
=M >0
M
3
3
3
es un mnimo para ET (h), el c
ual es un optimo para la formula de
M
3-puntos central.
Ejemplo
Sea f (x) = cos(x) donde f 0 (0.880) = sin(0.880) = 0.770 74.Vamos a considerar una
supuesta tabla de valores
x
f (x)
0.800
0.850
0.880
0.910
0.960
0.696 71 0.659 98 0.637 15 0.613 75 0.573 52
1
1
[f (0.880 h) + f (0.880 + h)] =
[ cos(0.880 h) + cos(0.880 + h)] .
2h
2h
=
entonces h
r
3
3
=
=h
M
x[0.8,0.9]
r
3
3 0.000005
= 2. 675 4 102 = 0.026754.
0.783 33
h
Aprox.
Error Absoluto
0.026754 0.770 65 0.000 01
h2 00
h3
h4
f (x0 ) f (3) (x0 ) + f (4) (
c(x0 ))
2
6
24
h2 00
h3
h4
f (x0 ) + f (3) (x0 ) + f (4) (c(x0 ))
2
6
24
con x0 h < c(x0 ) < x < c(x0 ) < x0 + h.Sumando ambas expresiones se tiene:
f (x0 + h) + f (x0 h) = 2f (x0 ) + h2 f 00 (x0 ) +
h4 (4)
f (
c(x0 )) + f (4) (c(x0 ))
24
1
h2 (4)
(4)
(f
(x
+
h)
2f
(x
)
+
f
(x
h))
f
(
c
(x
))
+
f
(c(x
))
0
0
0
0
0
h2
24
ahora si f (4) es una funcion continua en [x0 h, x0 + h] , por el Teorema del valor Medio
f 00 (x0 ) =
1
h2 (4)
(f
(x
+
h)
2f
(x
)
+
f
(x
h))
f
(d(x
))
0
0
0
0
h2
12
donde d (x0 h, x0 + h) .
Tarea: Aproxime la segunda derivada de la funcion f (x) = xex en x0 = 2.0 con h = 0.1 y
0.2.
Integraci
on Num
erica
Herramienta fundamental usada en ciencias e ingeniera para obtener valores aproximados a
integrales no tradicionales (o dificiles de resolver)
Por ejemplo:
Z 1
1 + 2sen(x)
1
ln
dx
(x) =
1 2sen(x) sen(x)
0
Obs: Lo anterior tiene su origen en la propia construccion de la integral definida por Suma
de Riemann.
Def : Considerando los valores reales distintos o soporte S = {x0 , x1 , ..., xn } en I = [a, b] ,
sabemos que P (x) el polinomio de Lagrange de grado n aproxima a una funcion f (x) en S
por:
n
Y
(x xi )
f (n+1) (c)
(x x0 )(x x1 )...(x xn )
f (x) = P (x)+E(x) =
f (xk )
+
(xk xi ) (n + 1)!
k=0
i=0
i 6= k
n
X
Rb
a
f (x)dx =
n
Q
f (xk )
k=0
i=0
i 6= k
n
Rb P
a
(xxi )
dx
(xk xi )
f (n+1) (c)
a (n+1)!
Rb
(x x0 ) (x x1 ) ... (x xn ) dx
Rb
n
Rb Q
f (x)dx =
f (xk ) a
k=0
i=0
i 6= k
n
P
(xxi )
dx
(xk xi )
n
R b (n+1)
Q (xxi )
1
+
f
(c)
dx
(xk xi )
(n + 1)! a
i=0
k=0
donde
" n
#
Z b
Z b
n
Y
Y (x xi )
(x xi )
1
ak =
f (n+1) (c)
dx
dx y E(x) =
(x
x
)
(n
+
1)!
(x
x
)
k
i
k
i
a
a
i=0
i=0
i 6= k
9
Rb
a
1
Rb Q
f (x)dx =
f (xk ) a
k=0
i=0
i 6= k
1
P
R x1
x0
R x1
x0
R x1
x0
R x1
x0
Rb
a
R x1
(xxi )
dx
(xk xi )
f (x)dx =
f (x0 )
(x0 x1 )
f (x)dx =
f (x0 )
h
f (x)dx =
f (x0 )
h
12 (x0 x1 )2 +
f (x)dx =
f (x0 )
h
12 (h)2 +
f (x)dx =
x0
R x1
x0
(x x1 ) dx +
(x x1 ) dx +
f (x1 )
(x1 x0 )
f (x1 )
h
f (x1 )
h
1
Q (xxi )
1 R b (2)
+
dx
f (c)
(xk xi )
(2)! a
i=0
R x1
x0
f (x1 )
h
1
2
1
2
R x1
x0
(x x0 ) dx +
(x x0 ) dx +
1 R x1 (2)
f (c) (x x0 ) (x x1 ) dx
2 x0
f (2) (c) R x1
(x x0 ) (x x1 ) dx
x0
2
f (2) (c)
(x0 x1 )2 +
2
f (2) (c)
(h)2 +
2
1
6
(h)3
1
6
(x0 x1 )3
f (2) (c) 3
h
(f (x0 ) + f (x1 ))
h
2
12
f (x)dx
a
donde x0 = a, x1 = a + h, x2 = a + 2h con h =
ba
2
f (1) (x1 )
f (2) (x1 )
f (3) (x1 )
f (4) (c(x1 ))
(xx1 )+
(xx1 )2 +
(xx1 )3 +
(xx1 )4
1!
2!
3!
4!
1 2
1
(x x1 )dx =
(x2 x1 )2 (x0 x1 )2 =
(h) (h)2 = 0 =
2
2
entonces
Rb
a
f (2) (x1 )
2!
R x2
x0
10
(x x1 )2 dx +
f (4) (c(x1 ))
4!
R x2
x0
x2
(x x1 )3 dx
x0
(x x1 )4 dx
ademas
Z
x2
(x x1 )2 dx =
2h3
1
(x2 x1 )3 (x0 x1 )3 =
3
3
(x x1 )4 dx =
2h5
1
(x2 x1 )5 (x0 x1 )5 =
5
5
x0
x2
x0
Rb
a
Rb
f (2) (x1 ) =
reemplazando
Rb
f (x)dx = 2hf (x1 ) +
a
Rb
a
Rb
a
Rb
a
1
h2 (4)
f (d(x0 ))
(f
(x
)
2f
(x
)
+
f
(x
))
0
1
2
2
h
12
h3
3
1
h2
f (x)dx =
h
3
h5
36
f (x)dx =
h
3
h5
12
f (x)dx =
h
3
h5 (4)
f (e(x1 )).
12
h2
12
f (4) (d(x0 )) +
1
3
f (4) (d(x0 )) +
h5 (4)
f
60
h5 (4)
f
60
(c(x1 ))
(c(x1 ))
f (4) (d(x0 )) + 51 f (4) (c(x1 ))
Ejercicio:
Rb
Considerando el intervalo I = [0, 2], determine a f (x)dx completando la tabla:
f (x)
x2
x4
1/(x + 1)
1 + x2 sen(x)
ex
Valor exacto
Trapecio
Simpson
Obs: Las reglas del Trapecio y Simpson son casos particulares de los metodos conocidos
como formulas de Newton-Cotes y existen Cerradas y Abiertas.
Cerradas: Considerando (n + 1)-puntos xi = x0 + ih, i = 0, 1, ..., n, donde x0 = a y xn = b
ba
(h =
), algunas formulas cerradas son:
n
Rb
n Regla
f (x)dx =
a
h
f (2) (c) 3
1 Trapecio
(f (x0 ) + f (x1 ))
h
2
12
h5 (4)
f (e)
12
Simpson
h
3
3h
8
??
2h
45
11
3h5 (4)
f (e)
80
8h7 (4)
f (e)
945
??
3f (2) (c) 3
3h
(f (x0 ) + f (x1 ))
h
2
4
??
4h
3
??
5h
24
14h5 (4)
f (e)
45
95h5 (4)
f (e)
144
Z /4
2
0.292 89
sen(x)dx = 1
2
0
12
Soluci
on num
erica de problemas de valor inicial para ecuaciones diferenciales
ordinarias
Estudiaremos algunos metodos numericos para encontrar una solucion aproximada w(t) de
la solucion exacta y(t) de un PVI:
0
y (t) = f (t, y(t)), para t0 t tn
()
con y(t0 ) = y0
Obs: Todos estos metodos pueden ser aplicados a sistemas de ecuaciones de primer orden.
Recordemos que para que un PVI como (*) tenga solucion debe satisfacer:
Teo 1:
1. (Existencia) Si f (t, y) es continua en un rectangulo
R = (t, y) R2 / t0 t t0 + a, |y y0 | b
entonces existe un intervalo t0 t t0 + en el cual existe una solucion y(t) del PVI
()
f (t, y)
es continua en un rectangulo R entonces existe un
y
intervalo t0 t t0 + en el cual existe una u
nica solucion y(t) del PVI ()
2. (Unicidad) Si f (t, y) y
13
Rt
t0
f (s, y(s))ds
Ejemplos:
1) Sea el PVI
()
0
y (t) = f (t, y(t)) = 1 + y 2
con y(0) = 0
su
on es y(t) = tan(t), pero esta solucion solo existe para un intervalo I
soluci
,
que contenga al 0. Por lo tanto (si por ejemplo) como f (t, y) es continua en
2 2
n
o
0
y (t) = f (t, y(t)) = y 1/3
con y(0) = 0
3/2
para un intervalo I que contenga
sus soluciones existentes son y(t) = 0 y y(t) = 32 t
al 0, dado que f (t, y) es continua en
o
n
2
R = (t, y) R / 0 t + < , 0 y .
2
f (t, y)
1
= p
y no es continua en R no tenemos unicidad.
3
y
3 y2
Ejercicio: Considere el PVI
0
y (t) = f (t, y(t)) = y 2 + cos(t2 )
()
con y(0) = 0
Por otro lado como
14
entonces
f (t, y(t)) = y 2 + cos(t2 ) y
f (t, y)
= 2y
y
(t,y)R
0
y (t) = f (t, y(t)) = 1 + tsen(ty), 0 t 2
con y(0) = 0
0
y (t) = f (t, y(t)), a t b
con y(a) = y0
1. () tiene solucion u
nica, y(t);
2. Para cualquier > 0, existe una cosntante positiva k() con la propiedad de que siempre
que |0 | < y (t) es continua con |(t)| < en [a, b] , existe una u
nica solucion, z(t),
al problema perturbado:
0
z (t) = f (t, z(t)) + (t), a t b
()
con z(a) = y0 + 0
con |z(t) y(t)| < k() , t [a, b] .
Obs: Todo PVI () donde f (t, y) satifaga la condicion de Lipschitz en y sobre R es
un Problema bien Planteado.
Ejemplo: Sea el PVI
0
y (t) = f (t, y(t)) = y t2 + 1, 0 t 2
()
16
M
etodo de Euler
Dado el PVI
()
0
y (t) = f (t, y(t)), a t b
con y(a) = y0
(ti+1 ti )2 00
y (i ),
2
h2 00
y (i ),
2
h2 00
y (i ). (ecuacion en diferencias)
2
El Metodo de Euler construye una sucesion wi y(ti ) para cada i = 1, 2, ..., n con
n N, al despreciar el termino de orden dos. Por lo tanto
w0 = y0
()
17
Ejercicio: Use el metodo de Euler para aproximar la solucion del PVI anterior dado
por:
0
y (t) = f (t, y(t)) = y t2 + 1, 0 t 2
()
w0 = 12
()
6
1
1
wi+1 = wi t2i +
5
5
5
wi
yi = y(ti ) |yi wi |
0.5000 0.5000
0.0000
0.8000 0.8292
0.0292
1.1520 1.2140
0.0620
1.5540 1.6489
0.0985
1.9884 2.1272
0.1387
2.4581 2.6408
0.1826
2.9498 3.1799
0.2301
3.4517 3.7324
0.2806
3.9501 4.2834
0.3333
4.4281 4.8151
0.3870
4.8657 5.3054
0.4396
18