Академический Документы
Профессиональный Документы
Культура Документы
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
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
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
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
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
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
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.
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.
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
Composite trapezium rule has error of order h2 , compared to h3 for each individual interval.
30 4.5 Composite methods
f (x)
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.