Download Numerical integration

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Resampling (statistics) wikipedia , lookup

Lagrange multiplier wikipedia , lookup

Finite element method wikipedia , lookup

Root-finding algorithm wikipedia , lookup

Interval finite element wikipedia , lookup

False position method wikipedia , lookup

Calculus of variations wikipedia , lookup

Clenshaw–Curtis quadrature wikipedia , lookup

Transcript
Chapter 4
Numerical integration
Contents
4.1
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
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−a)/h
b
f (x) dx = lim
a
h→0
X
hf (a + (i − 1)h),
i=1
i.e. as the area under the curve (x, y = f (x)).
f (x)
a
h
b
x
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
Z
4.2.1
b
f (x) dx ≈
a
n
X
wk f (xk )
with
xk = a + (k − 1)
k=1
b−a
.
n−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
P (x)
00000000
11111111
00000000
11111111
00000000
f11111111
(a)
00000000
11111111
00000000
11111111
00000000
11111111
00000000
11111111
00000000
11111111
00000000
11111111
00000000
11111111
00000000
11111111
00000000
11111111
00000000
11111111
a
f (x)
b
Z
b
f (x) dx ≈
a
x
b−a
(f (a) + f (b)) .
2
(4.2)
Thus, the trapezium rule can be obtained by integrating the linear interpolation function
P (x) = f (a)
(Check that
Z
b
f (x) dx ≈
a
Z
x−b
x−a
+ f (b)
a−b
b−a
over the interval [a, b].
b
P (x) dx leads to (4.2).)
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),
2
Therefore,
Z
b
f (x) dx =
a
Z
b
P (x) dx +
a
Z
b
a
ξ(x) ∈ [a, b].
1 ′′
f (ξ(x))(x − a)(x − b) dx.
2
So, the error in the trapezium rule is equal to
Z
1 b ′′
f (ξ(x))(x − a)(x − b) dx.
E=
2 a
To evaluate this integral, we shall make use of the following theorem (generalisation of the
Mean Value Theorem).
25
Chapter 4 – Numerical integration
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
Hence,
1
2
Z
a
b
f ′′ (ξ(x))(x − a)(x − b) dx =
a
f ′′ (c)
2
Z
b
(x − a)(x − b) dx
a
since (x − a)(x − b) ≤ 0 on the interval [a, b].
Z b−a
1
u(u − (b − a)) du with u = x − a,
E = f ′′ (c)
2
0
3
b−a
1
(b − a)3
u2
u
= f ′′ (c)
= −f ′′ (c)
− (b − a)
.
2
3
2
12
0
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
f (x) dx ≈
a
Z
b
P (x) dx =
a
=
Z bX
n
f (xk )Lk (x) dx
a k=1
n
X
f (xk )
k=1
where wk =
Z
Z
b
Lk (x) dx =
a
n
X
wk f (xk ),
k=1
b
Lk (x) dx are called weights.
Z b (n)
n
f (ξ(x)) Y
(x − xk ) dx.
The error is given by
n!
a
a
k=1
This method provides a means of finding the weights and error terms. However, their evaluation becomes more and more complex with increasing n. (Theorem 4.1 cannot be used to
n
Y
(x − xk ) changes sign for n ≥ 3.)
evaluate the error since
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 =
.
2
a
Solving these simultaneous equations gives
w1 = w2 =
b−a
.
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
b−a 2
b3 − a 3
=
a + b2 + 2K (f ′′ = 2),
x2 dx =
3
2
a
3
b − a3 b − a 2
a + b2 ,
⇒ 2K =
−
3 2
1 2
1 2
2
2
,
a + ab + b −
a +b
= (b − a)
3
2
1 2
(b − a)3
2
= (b − a) − a − 2ab + b
=−
,
6
6
(b − a)3
.
⇒K=−
12
Hence,
Z
b
f (x) dx =
a
b−a
(b − a)3 ′′
(f (a) + f (b)) −
f (ξ),
2
12
ξ ∈ (a, b),
(4.3)
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
+ w3 f (b).
f (x) dx ≈ w1 f (a) + w2 f
2
a
To avoid algebra, substitute x =
Z
a+b
b−a
+ u and define h =
so that the integral becomes
2
2
h
F (u) du ≈ w1 F (−h) + w2 F (0) + w3 F (h),
−h
with F (u) = f (x).
27
Chapter 4 – Numerical integration
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 ;
F ≡u⇒
F ≡ u2 ⇒
Z
−h
h
u du = 0 = −hw1 + hw3 ⇒ w1 = w3 ;
−h
Z h
h
2
u2 du = h3 = h2 w1 + h2 w3 ⇒ w1 = w3 = ;
3
3
−h
4
2
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),
3
3
3
−h
which translates into
Z
b
a
a+b
b−a
f (a) + 4f
+ f (b) .
f (x) dx ≈
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
h
1
4h5
4
4
4
5 1
u du =
(−h) + h + 4!K ⇒ 4!K = 2h
=
−
=−
,
5
3
5 3
15
−h
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)
a+b
b−a
f (x) dx =
f (a) + 4f
+ f (b) −
f (ξ),
6
2
2880
a
ξ ∈ (a, b).
(4.4)
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 intermediate 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
4.3 Open Newton-Cotes formulae
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
2
a
Again, we can substitute u = x −
a+b
b−a
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 (ξ),
f (x) dx = (b − a)f
2
24
a
ξ ∈ (a, b).
(4.5)
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 appropriately 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.
29
Chapter 4 – Numerical integration
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
, 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.
Split the interval [a, b] into n intervals of width h =
f (x)
x0 x1 x2
a
Z
b
f (x) dx =
a
Z
n−1
X Z xj+1
j=0
b
f (x) dx =
a
f (x) dx =
xj
xj xj+1
xn x
b
h
n−1
X
j=0
h
h3
[f (xj ) + f (xj+1 )] − f ′′ (ξj )
2
12
ξj ∈ (xj , xj+1 ),
h
h
[f (a) + f (x1 )] + [f (x1 ) + f (x2 )] + . . .
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
min f ′′ (ξj ) ≤ K =
j
1 X ′′
f (ξj ) ≤ max f ′′ (ξj ),
j
n
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
E=−
nh3 ′′
b − a 2 ′′
f (ξ) = −
h f (ξ)
12
12
since b − a = nh.
We can rewrite the composite trapezium rule as


Z b
n−1
X
b − a 2 ′′
h
h f (ξ),
f (a) + 2
f (xj ) + f (b) −
f (x) dx =
2
12
a
ξ ∈ (a, b).
(4.6)
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
Consider n/2 intervals [x2j , x2j+2 ], j = 0, . . . , n/2 − 1, of width 2h =
b−a
with equispaced
n/2
quadrature points xj = a + jh, j = 0, . . . , n.
f (x)
x0 x1 x2 x3 x4
a
Z
b
f (x) dx =
a
X
b
f (x) dx,
x2j
n/2−1 X
j=0
Z
2h
xn x
b
2j+2
n/2−1 xZ
j=0
=
x2j x2j+1 x2j+2
h5
h
[f (x2j ) + 4f (x2j+1 ) + f (x2j+2 )] − f (iv) (ξj )
3
90
ξj ∈ [x2j , x2j+2 ],
h
h
[f (a) + 4f (x1 ) + f (x2 )] + [f (x2 ) + 4f (x3 ) + f (x4 )] + . . .
3
3
i
h5 h (iv)
h
f (ξ0 ) + f (iv) (ξ1 ) + . . . + f (iv) (ξn/2−1 ) .
+ [f (xn−2 ) + 4f (xn−1 ) + f (b)] −
3
90
f (x) dx =
a
As for the composite trapezium rule, there exists ξ ∈ (a, b) such that
n/2−1
X
n (iv)
f (iv) (ξj ).
f (ξ) =
2
j=0
b−a
, we can rewrite the composite Simpson’s rule as
n


Z b
n/2−1
n/2−1
X
X
h
f (x2j+1 ) + f (b)
f (x2j ) + 4
f (x) dx = f (a) + 2
3
a
Using also h =
j=1
j=0
−
So, the composite Simpson’s rule is 4th order accurate.
b − a 4 (iv)
h f (ξ),
180
ξ ∈ (a, b). (4.7)