Professional Documents
Culture Documents
Chapter 4 Numerical Differentiation and Integration
Chapter 4 Numerical Differentiation and Integration
Since
( x x1 )( x x2 ) 2 x x1 x2
L0 ( x) , we have L'0 ( x) .
( x0 x1 )( x0 x2 ) ( x0 x1 )( x0 x2 )
Similarly,
2 x x0 x2 2 x x0 x1
L'1 ( x) and L'2 ( x) .
( x1 x0 )( x1 x2 ) ( x2 x0 )( x2 x1 )
4.1 (6)
Hence,
2 x j x1 x2 2 x j x0 x 2
f ' ( x j ) f ( x0 ) f ( x1 )
( x
0 1 0 2
x )( x x ) ( x
1 0 1 2
x )( x x )
2 x j x0 x1 1 ( 3) 2
f ( x2 ) f ( j ) ( x j xk ),
( x2 x0 )( x2 x1 ) 6 k 0
k j
for each j = 0, 1, 2.
Five-Point Formulas
With h = 0.1
1
[ f (1.8) 8 f (1.9) 8 f ( 2.1) f (2.2)] 22.166999
1.2
N 2 ( h ) N1 N1 N1 ( h ).
h h
2 2
4.2 (3)
Then we have the O(h2) approximation formula for M:
K 3K
M N 2 ( h ) 2 h 2 3 h 3 . 2a
2 4
h K 2 2 3K 3 3
M N2 h h . 2b
2 8 32
4 × (2b) – (2a)
3M 4 N 2 N 2 ( h )
h 3K 3 3
h ,
2 8
and dividing by 3 gives an O( h3 ) formula for approximating M:
h N 2 (h / 2) N 2 (h) 3K 3 3
M N2 h .
2 3 8
4.2 (4)
By defining
h N 2 ( h / 2) N 2 ( h )
N 3 (h) N 2 ,
2 3
we have the O( h3 ) formula:
K3 3
M N 3 (h) h .
8
The process is continued by constructing an O(h4) approximation
h N 3 ( h / 2) N 3 ( h )
N 4 (h) N 3 ,
2 7
An O(h5) approximation
N ( h / 2) N 4 ( h )
N 5 ( h ) N 4 4
h
2 15
and so on.
4.2 (5)
In general, if M can be written in the form
m 1
M N (h ) K j h j O ( h m ),
j 1
j
m
K h j
O ( h ),
j 1
EXAMPLE
The centered difference formula to approximate f'(x0)
can be expressed with an error formula
1 h2 h 4 ( 5)
f ' ( x0 ) f ( x 0 h ) f ( x0 h ) f ' " ( x0 ) f ( x0 ) .
2h 6 120
4.2 (7)
Since this error formula contains only even powers of h,
extrapolation is more effective
h2 h 4 ( 5)
f ' ( x0 ) N1 (h) f '" ( x0 ) f ( x0 ) , 1a
6 120
1
N1 (h) N (h) f ( x0 h) f ( x0 h).
2h
h h2 h 4 ( 5)
f ' ( x0 ) N1 f '" ( x0 ) f ( x0 ) . 1b
2 24 1920
[4 × (1b) – (1a)] / 3
h4
f ' ( x0 ) N 2 ( h ) f ( 5 ) ( x 0 ) ,
480
h N 1 ( h / 2) N 1 ( h )
N 2 ( h ) N1
.
2 3
4.2 (8)
Continuing this procedure gives, for each j = 2, 3, …,
an O(h2j) approximation
h N j 1 (h / 2) N j 1 (h )
N j (h ) N j 1 j 1
.
2 4 1
Notice that the denominator of the quotient is 4j-1 - 1
instead of 2j-1 – 1.
f ( x0 h ) f ( x0 h ) 2hf ' ( x0 )
h3
3
f " ' ( x0 )
120
f (1 ) f ( 5) ( 2 ).
h 5 ( 5)
[4 × (1a) – (1b)] / 3
h4 (5)
f ' ( x0 ) f ( x0 2h) 8 f ( x0 h) 8 f ( x0 h) f ( x0 2h) f ( ),
1
12h 30
which is the five-point formula.
4.2 (14)
HW EXERCISE SET 4.2 6.
4.3 Elements of Numerical Integration
The basic method involved in approximating b f ( x)dx
a
is called numerical quadrature.
n
i 0
a
f ( x )dx.
to obtain
b n n
f ( n 1) ( ( x ))
f ( x )dx f ( xi ) Li ( x )dx ( x xi )
b b
a a
i 0
a
i 0 ( n 1)!
dx
n b n
1
ai f ( xi ) ( x x ) f ( n 1)
( ( x ))dx
( n 1)! a i 0
i
i 0
where
b
ai Li ( x)dx for each i = 0, 1, ..., n.
a
4.3 (3)
The quadrature formula is, therefore,
n
f ( x )dx ai f ( xi )
b
a
i 0
1 x ''
f ( ( x ))( x x0 )( x x1 )dx
1
02 x
4.3 (5)
Since (x – x0)(x – x1) does not change sign on [x0, x1],
the Weighted Mean Value Theorem for Integrals
can be applied to the error term to give
x1 x1
f ( ( x))( x x0 )( x x1 )dx f ( ) ( x x0 )( x x1 )dx
'' ''
x0 x0
x 3
( x1 x2 ) 2
f ( )[
''
x x0 x1 x ]xx10
3 2
h 3 ''
f ( )
6
Consequently
b ( x x1 ) 2 ( x x0 ) 2 h 3 ''
f ( x )dx [ f ( x0 ) f ( x1 )] x0 f ( )
x1
a 2( x0 x1 ) 2( x1 x0 ) 12
( x1 x0 ) h 3 ''
[ f ( x0 ) f ( x1 )] f ( )
2 12
4.3 (6)
Since h = x1 – x0, we have the following rule:
Trapezoidal Rule: b h h3 ''
a
f ( x)dx [ f ( x0 ) f ( x1 )]
2 12
f ( )
This is called the Trapezoidal rule because
when f is a function with positive values,
b
a
f ( x ) dx is approximated by the area in a trapezoid
Consequently
x2 h 3 '' f ( 4) (1 ) 5
x0 f ( x )dx 2hf ( x1 ) f ( x1 ) h
3 60
4.3 (10)
If we now replace f " (x1) by the approximation given in Section 4.1,
we have
3 2
h 1 h
x
x02 f ( x )dx 2hf ( x1 ) { 2 [ f ( x0 ) 2 f ( x1 ) f ( x2 )] f ( 4) ( 2 )}
3 h 12
f ( 4) (1 ) 5
h
60
h h 5 1 ( 4) 1
{[ f ( x0 ) 4 f ( x1 ) f ( x2 )] [ f ( 2 ) f ( 4) (1 )]
3 12 3 5
This gives Simpson's rule :
Simpson's Rule:
x2 h h5 ( 4 )
x0 f ( x)dx 3[ f ( x0 ) 4 f ( x1 ) f ( x2 )] 90 f ( )
Simpson's rule gives exact results
when applied to any polynomial of degree three or less.
4.3 (11)
EXAMPLE
The Trapezoidal rule for a function f on the interval [0, 2] is
2
f ( x)dx f (0) f (2)
0
xn n (x xj )
( x x ) dx
xn
ai Li ( x )dx
x0 x0
j 0 i j
j i
4.3 (14)
Theorem 4.2
Suppose that i 0 ai f ( xi ) denotes
n
i 0
ai f ( xi )
(n 2)! 0 t (t 1)...( t n)dt
if n is even and f Cn+2 [a, b],
n
h n 2 ( n 1)
f ( ) n
a f ( x)dx
b
and ai f ( xi ) t (t 1)...(t n)dt
i 0 (n 1)! 0
8h 7 ( 6 )
f ( )
945 where x0 < < x4
4.3 (17)
The open Newton-Cotes formulas use the nodes xi = x0 + ih,
for each i = 0, 1, . . . , n,
where h = (b - a) / (n + 2) and x0 = a + h.
This implies that xn = b - h, so we set x-1 = a and xn+1 = b,
the formulas become
n
f ( x )dx ai f ( xi )
b xn 1 b
a
f ( x )dx
x1
i 0
ai Li ( x )dx
a
4.3 (18)
Theorem 4.3
Suppose that i 0 ai f ( xi ) denotes
n
x2 3h 3h 3 ''
n = 1: x1
f ( x )dx [ f ( x0 ) f ( x1 )]
2 4
f ( ) Where x-1 < < x2
n = 2:
x3 4h 14h5 ( 4 )
f ( x )dx [2 f ( x0 ) f ( x1 ) 2 f ( x2 )] f ( )
x1 3 45
Where x-1 < < x3
n = 3:
x4 5h 95h5 ( 4 )
x1
f ( x )dx [11 f ( x0 ) f ( x1 ) f ( x2 ) 11 f ( x3 )]
24 144
f ( )
8
4
4.3 (21)
1 0 1 2
[ e 4e e ] [ e 4e 3 e 4 ]
2
3 3
1
[ e 0 4e 2e 2 4e 3 e 4 ]
3
53.86385
2 -1
4.4 (5)
With h = (b - a) / n and xj = a + jh, for each j = 0, 1, . . . n, we have
n/2
b
a f ( x )dx xx22 jj2 f ( x )dx
j 1
h
f ( x2 j 2 ) 4 f ( x2 j 1 ) f ( x2 j ) f ( j ) ,
n/2 h5 (4)
j 1 3 90
for some ξj with x2j-2 < ξj < x2j , provided that f C4[a, b].
h ( n / 2) 1 ( n / 2) h 5 n/2
b
a f ( x ) dx 0
f ( x ) 2 f ( x 2j ) 4 f ( x 2 j 1 ) f ( x n
) f ( 4)
( j ).
3 j 1 j 1 90 j 1
4.4 (6)
Theorem 4.4
Let f C4 [a, b], n be even, h = (b - a) / n,
and xj = a + jh, for each j = 0, 1,... ,n.
Step1 Set h = (b - a) / n.
Step2 Set XI0=f (a)+f (b);
XI1 = 0; (Summation of f (x2i-1).)
XI2 = 0. (Summation of f (x2i) .)
Step3 For i = 1, . . . , n - 1 do Steps 4 and 5.
Step4 Set X = a + ih.
Step5 If i is even then set XI2=XI2+f (X)
else set XI1 = XI1 + f (X).
Step6 Set XI = h(XI0+2∙XI2+4∙XI1) / 3.
4.4 (8)
Step7 OUTPUT (XI);
STOP.
9j 10 ( 2 j 1)
0 sin xdx 2 sin 4 sin 2.000006.
60 j 1 10 j 1 20
And
1
k 2
2
Rk ,1 Rk 1,1 hk 1 f (a ( 2i 1)hk ),
2 i 1
in general for each k = 2, 3,…, n.
4.5 (7)
EXAMPLE
Perform the first step of the Romberg integration
scheme for approximating 0 sin xdx
with n = 6 leads to the equations
1
R1,1 sin 0 sin 0; R2,1 R1,1 sin 1.57079633;
2 2 2
1 3
R3,1 R2,1 sin sin 1.89611890;
2 2 4 4
1 3 5 7
R4,1 R3,1 sin sin sin sin 1.97423160;
2 4 8 8 8 8
R5,1 1.99357034 , and R6,1 1.99839336
( 2) 4 (1) b Rk 1,1 Rk ,1
a f ( x) dx Rk 1,1
3 3
K h 2i K 1 4i 1 2i
i k 2i
hk i h .
i 1 4i 1 k
i 2 3 4 i 2
3
The results that are generated from these formulas are shown in
4.5(11)
The Romberg technique allows
an entire new row in the table to be calculated
by doing one additional application
of the composite Trapezoidal rule.
f ( x, y )dy f ( x, y0 ) 2 f ( x, y2 j ) 4 f ( x, y2 j 1 ) f ( x, ym )
d k ( m / 2 )1 m/2
c
3 j 1 j 1
( d c )k 4 4 f ( x, )
,
180 y 4
m/2
4 f ( x, y2 j 1 ) dx
b b
f ( x, ym ) dx
a a
j 1
(d c)k 4 b 4 f ( x, )
180 a y 4
dx.
The Composite Simpson's rule is now employed on the integrals
in this equation.
Let xi = a + ih, for each i = 0, 1, . . . , n.
Then for each j = 0, 1,…, m, we have
h ( n / 2 )1 n/2
a f ( x, y j )dx f ( x0 , y j ) 2 f ( x2i , y j ) 4 f ( x2i 1 , y j ) f ( xn , y j )
b
3 i 1 i 1
(b a )h 4 4 f
( j , y j ), for some ξj in (a, b).
180 x 4
4.6(5)
The resulting approximation has the form
hk ( n / 2 ) 1
f ( x0 , y0 ) 2 f ( x2 i , y0 )
b d
a c
f ( x, y ) dydx
9 i 1
n/2
4 f ( x2 i 1 , y0 ) f ( xn , y0 )
i 1
( m / 2 ) 1 ( m / 2 ) 1 ( n / 2 ) 1
2 f ( x0 , y 2 j ) 2 f ( x2 i , y 2 j )
j 1 j 1 i 1
( m / 2 ) 1 n / 2 ( m / 2 ) 1
4 f (x 2 i 1 , y2 j ) f ( xn , y 2 j )
j 1 i 1 j 1
m / 2 m / 2 ( n / 2 ) 1
4 f ( x0 , y 2 j 1 ) 2 f ( x2 i , y 2 j 1 )
j 1 j 1 i 1
f ( xn , y m ).
4.6(6)
The error term E is given by
k (b a )h f (0 , y0 )
4 4 ( m / 2 ) 1 4
f ( , y ) m / 2 4
f ( 2 j 1 , y2 j 1 )
E 2 2j 2j
4
540 x 4
j 1 x 4
j 1 x 4
4 f ( m , ym ) (d c)k 4 b 4 f ( x, )
a dx.
x 4
180 y 4
with n = 4 and m = 2
uses the step sizes h = 0.15 and k = 0.25.
The region of integral R is shown below,
together with the nodes (xi, yj),
where i = 0, 1, 2, 3, 4 and j= 0, 1, 2 and
the coefficients wi,j of f (xi, yj) = ln (xi + 2yj) in the sum.
4.6(8)
The approximation is
(0.15)( 0.25) 4 2
2.0 1.5
1.4 1.0 ln( x 2 y )dydx 9 i 0 j 0
wi , j ln( xi 2 y j )
0.4295524387
4 f 6 4 f 96
Since and
x 4
( x 2 y )4 y 4
( x 2 y )4
1
and the maximum value of ( x 2 y )4 on R occurs at (1.4, 1.0),
the error is bounded by
(0.5)(0.6) 6 96
E
4
(0.15) max (0.25) max
4
180 ( x , y ) inR ( x 2 y ) 4 ( x , y ) inR ( x 2 y ) 4
4.72 106.
The actual value of the integral to ten decimal places is
2.0 1.5
1.4 1.0
ln( x 2 y)dydx 0.4295545265,
and is written k ( x ) d ( x ) c( x ) .
2
4.6(11)
Consequently,
k ( x)
b d ( x)
a c ( x ) f ( x, y )dydx b
a f ( x, c( x )) 4 f ( x, c( x ) k ( x )) f ( x, d ( x ))dx
3
h k (a )
f (a, c(a ) 4 f (a, c(a ) k (a )) f (a, d (a ))
3 3
4k ( a h )
f (a h, c(a h )) 4 f (a h, c(a h )
3
k ( a h )) f ( a h, d ( a h ))
k (b)
f (b, c(b)) 4 f (b, c(b) k (b)) f (b, d (b)).
3
4.6(12)
ALGORITHM 4.4 Simpson's Double Integral
0, if x a.
Since 0 < p < 1 and P4( k ) ( a ) agrees with g(k)(a)
for each k = 0, 1, 2, 3, 4, we have G C4 [a, b].
This implies that the Composite Simpson's rule can be applied to
approximate the integral of G on [a, b].
4.7(5)
Adding this approximation gives an approximation
to the improper integral of f on [a, b], within the accuracy
of the Composite Simpson's rule approximation.
EXAMPLE
Use the Composite Simpson'sx rule with h = 0.25
to approximate 1 e dx.
0
x
Since the fourth Taylor polynomial for e x about x = 0 is
x2 x3 x4
we have P4 ( x ) 1 x ,
2 6 24
dx 01 x 1 / 2 x1 / 2 x 3 / 2 x 5 / 2
1 P4 ( x ) 1 1 1 7/2
0 x dx
x 2 6 24
1
lim 2 x1 / 2 x 3 / 2 x 5 / 2 x 7 / 2
2 1 1 1 9/2
x
M 0 3 5 21 108 M
2 1 1 1
2 2.9235450.
3 5 21 108
4.7(6)
Table lists the approximate values of
1
( e x P4 ( x )), when 0 x 1,
G( x) x
0, when x 0.
4.7(7)
Applying the Composite Simpson's rule using these data gives
1 0.25
0 G( x)dx 3 [0 4(0.0000170) 2(0.0004013)
4(0.0026026) 0.0099485] 0.0017691.
x
1 e
0 x dx 2.9235450 0.0017691 2.9253141
Since |G (4) (x)| < 1 on [0, 1], the error is bounded by
1 0
(0.25) 4 0.0000217.
180
4.7(7)
To approximate the improper integral with a singularity
at the right endpoint.
We can make the substitution
z x, dz dx
a
b
a f ( x )dx b f ( z )dz,
which has its singularity at the left endpoint.
4.7(8)
An improper integral with a singularity at c, where a < c < b,
is treated as the sum of improper integrals
with endpoint singularities
since ab f ( x )dx ac f ( x )dx cb f ( x )dx.
x t t
4.7(8)
The variable change t = x-1 converts the improper integral
f ( x )dx 1 / a 2 1
f dt
a f ( x )dx into a 0 t
t
EXAMPLE
To approximate I 1 x 3 / 2 sin 1 dx,
x
we make the change of variable t = x-1 to obtain
1
I t 1/ 2 sin t dt.
0