Introduction_Numerical_Analysis_MATH104_2
Introduction_Numerical_Analysis_MATH104_2
Introduction
3
4 CHAPTER 1. INTRODUCTION
In most cases we cannot find an exact value of I[f ] and very often we only
know the integrand f at finite number of points in [a, b]. The problem is
then to produce an approximation to I[f ] as accurate as we need and at a
reasonable computational cost.
f (b) f (a)
f (x) ⇡ p1 (x) = f (a) + (x a). (1.2)
b a
and
Z b Z b
1
f (x)dx ⇡ p1 (x)dx = f (a)(b a) + [f (b) f (a)](b a)
a a 2 (1.3)
1
= [f (a) + f (b)](b a).
2
That is
Z b
b a
f (x)dx ⇡ [f (a) + f (b)]. (1.4)
a 2
The right hand side is known as the simple Trapezoidal Rule Quadrature. A
quadrature is a method to approximate an integral. How accurate is this
approximation? Clearly, if f is a linear polynomial or a constant then the
Trapezoidal Rule would give us the exact value of the integral, i.e. it would
be exact. The underlying question is: how well does a linear polynomial p1 ,
satisfying
approximate f on the interval [a, b]? We can almost guess the answer. The
approximation is exact at x = a and x = b because of (1.5)-(1.6) and it is
1.2. AN ILLUSTRATIVE EXAMPLE 5
exact for all polynomials of degree 1. This suggests that f (x) p1 (x) =
Cf 00 (⇠)(x a)(x b), where C is a constant. But where is f 00 evaluated
at? it cannot be at x for if it did f would be the solution of a second order
ODE and f is an arbitrary (but sufficiently smooth, C 2 [a, b] ) function so
it has to be at some undetermined point ⇠(x) in (a, b). Now, if we take the
particular case f (x) = x2 on [0, 1] then p1 (x) = x, f (x) p1 (x) = x(x 1),
and f 00 (x) = 2, which implies that C would have to be 1/2. So our conjecture
is
1
f (x) p1 (x) = f 00 (⇠(x))(x a)(x b). (1.7)
2
There is a beautiful 19th Century proof of this result by A. Cauchy. It goes
as follows. If x = a or x = b (1.7) holds trivially. So let us take x in (a, b)
and define the following function of a new variable t as
(t a)(t b)
(t) = f (t) p1 (t) [f (x) p1 (x)] . (1.8)
(x a)(x b)
00 2
0= (⇠(x)) = f 00 (⇠(x)) [f (x) p1 (x)] (1.9)
(x a)(x b)
and so
1
f (x) p1 (x) = f 00 (⇠(x))(x a)(x b), ⇠(x) 2 (a, b). ⇤ (1.10)
2
We can use (1.10) to find the accuracy of the simple Trapezoidal Rule. As-
suming the integrand f is C 2 [a, b]
Z b Z b Z
1 b 00
f (x)dx = p1 (x)dx + f (⇠(x))(x a)(x b)dx. (1.11)
a a 2 a
Now, (x a)(x b) does not change sign in [a, b] and f 00 is continuous so
by the Weighted Mean Value Theorem for Integrals we have that there is
6 CHAPTER 1. INTRODUCTION
The last integral can be easily evaluated if we shift to the midpoint, i.e.,
changing variables to x = y + 12 (a + b) then
Z b Z b a " ✓ ◆2 #
2 b a 1
(x a)(x b)dx = y2 dy = (b a)3 . (1.13)
a b a
2
2 6
X1 Z xj+1
N (1.16)
= f (x)dx.
j=0 xj
1.2. AN ILLUSTRATIVE EXAMPLE 7
But we know
Z xj+1
1 1 00
f (x)dx = [f (xj ) + f (xj+1 )]h f (⇠j )h3 (1.17)
xj 2 12
The first term on the right hand side is called the Composite Trapezoidal
Rule Quadrature (CTR):
1 1
Th [f ] := h f (x0 ) + f (x1 ) + . . . + f (xN 1 ) + f (xN ) . (1.18)
2 2
I[f ] = Th [f ] + Eh [f ]. (1.21)
8 CHAPTER 1. INTRODUCTION
Definition 1.1. We say that g(h) is order h↵ , and write g(h) = O(h↵ ), if
there is a constant C and h0 such that |g(h)| Ch↵ for 0 h h0 , i.e. for
sufficiently small h.
Example 1.1. Let’s check the Trapezoidal Rule approximation for an integral
we can compute exactly. Take f (x) = ex in [0, 1]. The exact value of the
integral is e 1. Observe how the error |I[ex ] T1/N [ex ]| decreases by a
1
|Eh [f ]| (b a)h2 M2 . (1.22)
12
1
Neglecting round-o↵ errors introduced by finite precision number representation and
computer arithmetic.
1.2. AN ILLUSTRATIVE EXAMPLE 9
However, this bound does not in general provide an accurate estimate of the
error. It could grossly overestimate it. This can be seen from (1.19). As
N ! 1 the term in brackets converges to a mean value of f 00 , i.e.
N 1 Z b
1 X 00 1 1
f (⇠j ) ! f 00 (x)dx = [f 0 (b) f 0 (a)], (1.23)
N j=0 b a a b a
Eh [f ] = C2 h2 + R(h), (1.24)
where
1 0
C2 = [f (b) f 0 (a)] (1.25)
12
and R(h) goes to zero faster than h2 as h ! 0, i.e.
R(h)
lim = 0. (1.26)
h!0 h2
g(h)
lim =0
h!0 h↵
f at the end points of the interval then we can compute directly C2 h2 and
use this leading order approximation of the error to obtain the improved
approximation
1 0
Teh [f ] = Th [f ] [f (b) f 0 (a)]h2 . (1.28)
12
This is called the (composite) Modified Trapezoidal Rule. It then follows from
(1.27) that error of this “corrected approximation” is R(h), which goes to
zero faster than h2 . In fact, we will prove later that the error of the Modified
Trapezoidal Rule is O(h4 ).
Often, we only have access to values of f and/or it is difficult to evaluate
f (a) and f 0 (b). Fortunately, we can compute a sufficiently good approxi-
0
mation of the leading order term of the error, C2 h2 , so that we can use the
same error correction idea that we did for the Modified Trapezoidal Rule.
Roughly speaking, the error can be estimated by comparing two approxima-
tions obtained with di↵erent h.
Consider (1.27). If we halve h we get
1
I[f ] = Th/2 [f ] + C2 h2 + R(h/2). (1.29)
4
Subtracting (1.29) from (1.27) we get
4 4
C2 h2 = Th/2 [f ] Th [f ] + (R(h/2) R(h)) . (1.30)
3 3
The last term on the right hand side is o(h2 ). Hence, for h sufficiently small,
we have
4
C2 h2 ⇡ Th/2 [f ] Th [f ] (1.31)
3
and this could provide a good, computable estimate for the error, i.e.
4
Eh [f ] ⇡ Th/2 [f ] Th [f ] . (1.32)
3
The key here is that h has to be sufficiently small to make the asymptotic
approximation (1.31) valid. We can check this by working backwards. If h
is sufficiently small, then evaluating (1.31) at h/2 we get
✓ ◆2
h 4
C2 ⇡ Th/4 [f ] Th/2 [f ] (1.33)
2 3
1.2. AN ILLUSTRATIVE EXAMPLE 11
Therefore
" N
#
h X1 N
X1
Sh [f ] = f (a) + 2 f (a + kh) + 4 f (a + kh/2) + f (b) . (1.39)
6 k=1 k=1
Table 1.2: Composite Trapezoidal Rule for f (x) = 1/(2 + sin x) in [0, 2⇡].
N T2⇡/N [1/(2 + sin x)] |I[1/(2 + sin x)] T2⇡/N [1/(2 + sin x)]|
8 3.627791516645356 1.927881769203665 ⇥ 10 4
16 3.627598733591013 5.122577029226250 ⇥ 10 9
32 3.627598728468435 4.440892098500626 ⇥ 10 16
where the integrand f is periodic in [0, 2⇡] and has m > 1 continuous deriva-
tives, i.e. f 2 C m [0, 2⇡] and f (x + 2⇡) = f (x) for all x. Due to periodicity
we can work in any interval of length 2⇡ and if the function has a di↵erent
period, with a simple change of variables, we can reduce the problem to one
in [0, 2⇡].
Consider the equally spaced points in [0, 2⇡], xj = jh for j = 0, 1, . . . , N
and h = 2⇡/N . Because f is periodic f (x0 = 0) = f (xN = 2⇡) and the CTR
becomes
N
X1
f (x0 ) f (xN )
Th [f ] = h + f (x1 ) + . . . + f (xN 1 ) + =h f (xj ). (1.41)
2 2 j=0
Being f smooth and periodic in [0, 2⇡], it has a uniformly convergent Fourier
Series:
1
a0 X
f (x) = + (ak cos kx + bk sin kx) (1.42)
2 k=1
where
Z
1 2⇡
ak = f (x) cos kx dx, k = 0, 1, . . . (1.43)
⇡ 0
Z
1 2⇡
bk = f (x) sin kx dx, k = 1, 2, . . . (1.44)
⇡ 0
14 CHAPTER 1. INTRODUCTION
we can write
eix + e ix
cos x = , (1.46)
2
eix e ix
sin x = (1.47)
2i
and the Fourier series can be conveniently expressed in complex form in terms
of functions eikx for k = 0, ±1, ±2, . . . so that (1.42) becomes
1
X
f (x) = ck eikx , (1.48)
k= 1
where
Z 2⇡
1 ikx
ck = f (x)e dx. (1.49)
2⇡ 0
N 1
!
X1 X
Th [f ] = h ck eikxj . (1.50)
j=0 k= 1
Justified by the uniform convergence of the series we can exchange the finite
and the infinite sums to get
1 N
X1 2⇡
2⇡ X
Th [f ] = ck eik N j . (1.51)
N k= 1 j=0
3 2
i = 1 and if c = a + ib, with a, b 2 R, then its complex conjugate c̄ = a ib.
1.3. SUPER-ALGEBRAIC CONVERGENCE 15
But
N
X1 X1 ⇣
N ⌘j
ik 2⇡ j ik 2⇡
e N = e N . (1.52)
j=0 j=0
2⇡
Note that eik N = 1 precisely when k is an integer multiple of N , i.e. k = lN ,
l 2 Z and if so
X1 ⇣
N
2⇡
⌘j
eik N =N for k = lN . (1.53)
j=0
Otherwise, if k 6= lN , then
⇣ ⌘N
ik 2⇡
X1 ⇣
N
2⇡
⌘j 1 e N
that is
So now, the relevant question is how fast the Fourier coefficients clN of f
decay with N . The answer is tied to the smoothness of f . Doing integration
by parts in the formula (4.11) for the Fourier coefficients of f we have
Z 2⇡
1 1 2⇡
ck = f 0 (x)e ikx dx f (x)e ikx 0 k 6= 0 (1.59)
2⇡ ik 0
16 CHAPTER 1. INTRODUCTION
ikx
and the last term vanishes due to the periodicity of f (x)e . Hence,
Z
1 1 2⇡ 0
ck = f (x)e ikx dx k=6 0. (1.60)
2⇡ ik 0
Integrating by parts m times we obtain
✓ ◆m Z 2⇡
1 1
ck = f (m) (x)e ikx
dx k 6= 0, (1.61)
2⇡ ik 0
where f (m) is the m-th derivative of f . Therefore, for f 2 C m [0, 2⇡] and
periodic
Am
|ck | , (1.62)
|k|m