Вы находитесь на странице: 1из 8

Chapter 4

Numerical integration

Contents
4.1 Definite integrals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
4.2 Closed Newton-Cotes formulae . . . . . . . . . . . . . . . . . . . . . 24
4.3 Open Newton-Cotes formulae . . . . . . . . . . . . . . . . . . . . . . 28
4.4 Gauss quadrature . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
4.5 Composite methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28

4.1 Definite integrals


The definite integral of a function f on the interval [a, b] is written as
Z b
f (x) dx (4.1)
a

and can be defined as the limit of the Riemann series


Z b (b−a)/h
X
f (x) dx = lim hf (a + (i − 1)h),
a h→0
i=1

i.e. as the area under the curve (x, y = f (x)).

f (x)

a b x
h
Hence, numerical integration is often called quadrature (i.e. computation of an area under a
curve).

23
24 4.2 Closed Newton-Cotes formulae

The definite integral of a function exists even if there is no analytic antiderivative function
F (x) such that
d
F (x) = f (x).
dx

4.2 Closed Newton-Cotes formulae


The definite integral (4.1) can be approximated using the polynomial interpolating f (x)
through n equispaced points (xk ), leading to
b n
b−a
Z X
f (x) dx ≈ wk f (xk ) with xk = a + (k − 1) .
a n−1
k=1

4.2.1 Trapezium rule


This is the simplest numerical method for evaluating a definite integral. It calculates the area
of the trapezium formed by approximating f (x) using linear interpolation.
f (b)
11111111
00000000 f (x)
00000000
11111111
P (x)
00000000
11111111
f11111111
00000000
00000000
11111111
(a)
00000000
11111111
00000000
11111111
00000000
11111111
00000000
11111111
00000000
11111111
00000000
11111111
00000000
11111111
00000000
11111111
00000000
11111111
a b x
b
b−a
Z
f (x) dx ≈ (f (a) + f (b)) . (4.2)
a 2
Thus, the trapezium rule can be obtained by integrating the linear interpolation function
x−b x−a
P (x) = f (a) + f (b) over the interval [a, b].
a−b b−a
Z b Z b
(Check that f (x) dx ≈ P (x) dx leads to (4.2).)
a a

Measure of the error: From Equation (3.4), we know the error in the linear interpolation,
1
f (x) = P (x) + f ′′ (ξ(x))(x − a)(x − b), ξ(x) ∈ [a, b].
2
Therefore,
b b b
1 ′′
Z Z Z
f (x) dx = P (x) dx + f (ξ(x))(x − a)(x − b) dx.
a a a 2
So, the error in the trapezium rule is equal to

1 b ′′
Z
E= f (ξ(x))(x − a)(x − b) dx.
2 a
To evaluate this integral, we shall make use of the following theorem (generalisation of the
Mean Value Theorem).
Chapter 4 – Numerical integration 25

Theorem 4.1 (Weighted Mean Value for Integrals)


If h ∈ C[a, b], if the integral of g(x) exists on [a, b], and if g(x) does not change sign on [a, b],
then there exists c ∈ [a, b] such that
Z b Z b
h(x)g(x) dx = h(c) g(x) dx.
a a

Hence,
b b
1 f ′′ (c)
Z Z
f ′′ (ξ(x))(x − a)(x − b) dx = (x − a)(x − b) dx
2 a 2 a
since (x − a)(x − b) ≤ 0 on the interval [a, b].
Z b−a
1
E = f ′′ (c) u(u − (b − a)) du with u = x − a,
2 0
 3 b−a
1 u u2 (b − a)3
= f ′′ (c) − (b − a) = −f ′′ (c) .
2 3 2 0 12

Thus, the error in the trapezium method scales with the cube of the size on the interval.
(Note that this method is exact for linear functions.)

We can generate other integration rules by using higher order Lagrange polynomials.
Z b Z b n
Z bX
f (x) dx ≈ P (x) dx = f (xk )Lk (x) dx
a a a k=1
n
X Z b n
X
= f (xk ) Lk (x) dx = wk f (xk ),
k=1 a k=1
Z b
where wk = Lk (x) dx are called weights.
a
Z b (n) n
f (ξ(x)) Y
The error is given by (x − xk ) dx.
a n!
k=1
This method provides a means of finding the weights and error terms. However, their eval-
uation becomes more and more complex with increasing n. (Theorem 4.1 cannot be used to
n
Y
evaluate the error since (x − xk ) changes sign for n ≥ 3.)
k=1

4.2.2 Method of undetermined coefficients


Alternative way of evaluating Newton-Cotes integration formulae. To illustrate this method,
let us derive the trapezium rule again.

Trapezium rule
We wish to find an approximation of the form
Z b
f (x) dx ≈ w1 f (a) + w2 f (b).
a

Since, we have two unknown parameters, w1 and w2 , we can make this formulae exact for
linear functions (i.e. functions are of the form αx + β). So, the error term must be of the
form Kf ′′ (ξ) for some ξ ∈ (a, b).
26 4.2 Closed Newton-Cotes formulae

Hence, we seek a quadrature rule of the form


Z b
f (x) dx = w1 f (a) + w2 f (b) + Kf ′′ (ξ), ξ ∈ (a, b).
a

To find w1 and w2 we need to ensure that the formula is exact for all linear functions. However,
using the principle of superposition, it is sufficient to make this work for any two independent
linear polynomials (i.e. polynomials of degree one at most).
E.g. choose the two independent polynomials f ≡ 1 and f ≡ x.
Z b
For f ≡ 1 : dx = w1 + w2 = b − a;
a
Z b
b2 − a 2
for f ≡ x : x dx = aw1 + bw2 = .
a 2
Solving these simultaneous equations gives
b−a
w1 = w2 = .
2

To find the value of K, we can use any quadratic function so that f ′′ (ξ) is a non-zero constant,
independent of the unknown ξ. E.g. take f ≡ x2 ,
Z b
b3 − a 3 b−a 2
x2 dx = a + b2 + 2K (f ′′ = 2),

=
a 3 2
b − a3 b − a 2
3
a + b2 ,

⇒ 2K = −
3  2 
1 2 2
 1 2 2

= (b − a) a + ab + b − a +b ,
3 2
(b − a)3
 
1 2 2

= (b − a) − a − 2ab + b =− ,
6 6
(b − a)3
⇒K=− .
12
Hence,
b
b−a (b − a)3 ′′
Z
f (x) dx = (f (a) + f (b)) − f (ξ), ξ ∈ (a, b), (4.3)
a 2 12
in agreement with § 4.2.1 (but easier to derive).

Simpson’s rule
Three points integration rule derived using the method of undetermined coefficients.
Suppose that we add a quadrature point at the middle of the interval [a, b],
Z b  
a+b
f (x) dx ≈ w1 f (a) + w2 f + w3 f (b).
a 2

a+b b−a
To avoid algebra, substitute x = + u and define h = so that the integral becomes
2 2
Z h
F (u) du ≈ w1 F (−h) + w2 F (0) + w3 F (h), with F (u) = f (x).
−h
Chapter 4 – Numerical integration 27

Since we have three unknowns, we can make this formula exact for all quadratic functions;
so, let us use, e.g., F ≡ 1, F ≡ u and F ≡ u2 .
Z h
F ≡1⇒ du = 2h = w1 + w2 + w3 ;
−h
Z h
F ≡u⇒ u du = 0 = −hw1 + hw3 ⇒ w1 = w3 ;
−h
Z h
2 h
F ≡ u2 ⇒ u2 du = h3 = h2 w1 + h2 w3 ⇒ w1 = w3 = ;
−h 3 3
2 4
w2 = 2h − w1 − w3 = 2h − h = h.
3 3
Hence we obtain the approximation
Z h
h 4h h
F (u) du ≈ F (−h) + F (0) + F (h),
−h 3 3 3
which translates into
b    
b−a a+b
Z
f (x) dx ≈ f (a) + 4f + f (b) .
a 6 2
This is called Simpson’s rule.
As this formula is exact for all quadratic functions, we expect the error to be of the form
KF ′′′ (ξ).
Z h
However, if we examine F ≡ u3 , the integral u3 du = 0 and Simpson’s rule gives
−h

h
(−h)3 + 4 × 0 + h3 = 0 ⇒ K ≡ 0.

3
Therefore Simpson’s rule is exact for cubic functions as well. Consequently, we try an error
term of the form KF (iv) (ξ), ξ ∈ (−h, h).
To find the value of K use, e.g., F (u) ≡ x4 (with F (iv) (ξ) = 4!, independent of ξ).
Z h
2h5 4h5
 
4 h 4 4
 5 1 1
u du = = (−h) + h + 4!K ⇒ 4!K = 2h − =− ,
−h 5 3 5 3 15
h5
⇒K=− .
90
Simpson’s rule is fifth-order accurate: the error varies as the fifth power of the width of the
interval.
Simpson’s rule is given by
Z b
(b − a)5 (iv)
   
b−a a+b
f (x) dx = f (a) + 4f + f (b) − f (ξ), ξ ∈ (a, b). (4.4)
a 6 2 2880

Example 4.1
Material covered in class. Please, see your lecture notes.

Closed Newton-Cotes formula of higher order can be derived using more equispaced interme-
diate points (n = 2: trapezium; n = 3: Simpson).
As observed for Simpson’s rule, the error for n odd is of order (b−a)n+2 rather than (b−a)n+1 ,
due to symmetry.
28 4.3 Open Newton-Cotes formulae

4.3 Open Newton-Cotes formulae


Closed Newton-Cotes formulae such as (4.3) and (4.4) include the value of the function at the
endpoints.
By contrast, open Newton-Cotes formulae are based on the interior points only.

Midpoint rule. For example, consider the open Newton-Cotes formula


Z b  
a+b
f (x) dx ≈ w1 f .
a 2

a+b b−a
Again, we can substitute u = x − and h = ;
2 2
Z h
F (u) du ≈ w1 F (0).
−h

This formula must hold for constant functions. So, taking, e.g. F ≡ 1 ⇒ 2h = w1 . However,
Z h
since for F (u) ≡ u, F (u) du = 0, the quadrature rule is exact for linear functions as well.
−h
So, we look for an error of the form KF ′′ (ξ), ξ ∈ (−h, h);
Z h
F (u) du = 2hF (0) + KF ′′ (ξ), ξ ∈ (−h, h).
−h

Substitute F (u) = u2 ,
2 3 h3
h = 0 + 2K ⇒ K = .
3 3
Z b
(b − a)3 ′′
 
a+b
f (x) dx = (b − a)f + f (ξ), ξ ∈ (a, b). (4.5)
a 2 24
Same order as trapezium and coefficient of the error smaller (halved).

Example 4.2
Material covered in class. Please, see your lecture notes.

4.4 Gauss quadrature


There is no necessity to use equispaced points. By choosing the quadrature points xk ap-
propriately we can derive n-points methods of order 2n + 1 (i.e. error varies as (b − a)2n+1 ),
exact for polynomials of degree (2n − 1).
These are called Gauss formulae and can give stunning accuracy. However, for n ≥ 2, the
values of xk (roots of Legendre polynomials) and the weights wk are non rational.

4.5 Composite methods


Disadvantage of higher order methods: Since higher order methods are based on Lagrange
interpolation, they also suffer the same weaknesses.
While very accurate for functions with well-behaved higher order derivatives, they becomes
inaccurate for functions with unbounded higher derivatives.
Chapter 4 – Numerical integration 29

Therefore, it is often safer to use low order methods, such as trapezium and Simpson’s rules.
While these quadrature rules are not very accurate on large intervals (error varying as (b − a)3
and as (b − a)5 ), accurate approximations can be obtained by breaking the interval [a, b] into
n subintervals of equal width h.

4.5.1 Composite trapezium rule


b−a
Split the interval [a, b] into n intervals of width h = , i.e. consider n + 1 equispaced
n
points xj = a + jh, j = 0, . . . , n. The subinterval j is [xj , xj+1 ], j = 0, . . . , n − 1.

f (x)

x0 x1 x2 xj xj+1 xn x
a b
h

b n−1
X Z xj+1 n−1
X h3

h
Z
f (x) dx = f (x) dx = [f (xj ) + f (xj+1 )] − f ′′ (ξj ) ξj ∈ (xj , xj+1 ),
a xj 2 12
j=0 j=0

b
h h
Z
f (x) dx = [f (a) + f (x1 )] + [f (x1 ) + f (x2 )] + . . .
a 2 2
h h
+ [f (xn−2 ) + f (xn−1 )] + [f (xn−1 ) + f (b)]
2 2
h3  ′′ 
− f (ξ0 ) + f ′′ (ξ1 ) + . . . + f ′′ (ξn−1 ) .
12

Error: since
n−1
1 X ′′
min f ′′ (ξj ) ≤ K = f (ξj ) ≤ max f ′′ (ξj ),
j n j
j=0

and f ′′ is continuous, there exits ξ ∈ (a, b) with f ′′ (ξ) = K (analogous to the intermediate
value theorem). Hence, the total error is of the form

nh3 ′′ b − a 2 ′′
E=− f (ξ) = − h f (ξ) since b − a = nh.
12 12

We can rewrite the composite trapezium rule as


 
Z b n−1
h X b − a 2 ′′
f (x) dx = f (a) + 2 f (xj ) + f (b) − h f (ξ), ξ ∈ (a, b). (4.6)
a 2 12
j=1

Composite trapezium rule has error of order h2 , compared to h3 for each individual interval.
30 4.5 Composite methods

4.5.2 Composite Simpson’s rule


b−a
Consider n/2 intervals [x2j , x2j+2 ], j = 0, . . . , n/2 − 1, of width 2h = with equispaced
n/2
quadrature points xj = a + jh, j = 0, . . . , n.

f (x)

x0 x1 x2 x3 x4 x2j x2j+1 x2j+2 xn x


a b
2h

Z b n/2−1 xZ
2j+2
X
f (x) dx = f (x) dx,
a j=0 x2j
n/2−1 
h5

X h
= [f (x2j ) + 4f (x2j+1 ) + f (x2j+2 )] − f (iv) (ξj ) ξj ∈ [x2j , x2j+2 ],
3 90
j=0

b
h h
Z
f (x) dx = [f (a) + 4f (x1 ) + f (x2 )] + [f (x2 ) + 4f (x3 ) + f (x4 )] + . . .
a 3 3
h h5 h (iv) i
+ [f (xn−2 ) + 4f (xn−1 ) + f (b)] − f (ξ0 ) + f (iv) (ξ1 ) + . . . + f (iv) (ξn/2−1 ) .
3 90
As for the composite trapezium rule, there exists ξ ∈ (a, b) such that
n/2−1
n (iv) X
f (ξ) = f (iv) (ξj ).
2
j=0

b−a
Using also h = , we can rewrite the composite Simpson’s rule as
n
 
Z b n/2−1 n/2−1
h X X
f (x) dx = f (a) + 2 f (x2j ) + 4 f (x2j+1 ) + f (b)
a 3
j=1 j=0
b − a 4 (iv)
− h f (ξ), ξ ∈ (a, b). (4.7)
180
So, the composite Simpson’s rule is 4th order accurate.

Вам также может понравиться