You are on page 1of 14

MAT128A: Numerical Analysis

Lecture Seven: The Trapezoidal Rule

October 10, 2018

Lecture 7 October 10, 2018 1 / 14


The Trapezoidal Rule

We call the quadrature rule


Z b
b−a
f (x) dx ≈ pf (x0 ) + 2f (x1 ) + 2f (x2 ) + . . . + 2f (xn−1 ) + f (xn )q ,
a 2n
where the nodes a = x0 < x1 < · · · < xn = b are given by
b−a
xj = a + j,
n
the (n + 1)-point trapezoidal rule on the interval [a, b] (or just the (n + 1)-point
trapezoidal rule when it is clear what interval we are working on).

Lecture 7 October 10, 2018 2 / 14


The Trapezoidal Rule

The trapezoidal rule is not a very good way to integrate most functions. The following
table gives the relative error in Z 1
exp(x) dx
0

for various values of n.

n relative error
10 0.001431662930269 × 10+0
100 0.000014318991372 × 10+0
1000 1.431901499850846 × 10−7
10000 1.431901523477221 × 10−9
100000 1.431901523713485 × 10−11

ˆ ˙
1
Later on, we will show that the error in the trapezoidal rule is O when it is used to
n2
integrate generate smooth functions.

Lecture 7 October 10, 2018 3 / 14


The Trapezoidal Rule

But the trapezoidal rule is a spectacularly good way to integrate smooth, periodic
functions. The following table gives the relative errors in the integral
Z π
exp(cos(t)) dt
−π

which arise when the trapezoidal rule of various lengths are used to approximate it.

n relative error
4 0.03439691880919236 × 10+00
5 0.00341130316644266 × 10+00
6 0.00028260086127189 × 10+00
7 0.00002009636897756 × 10+00
8 1.25168893154474934 × 10−6
9 3.45945653506638244 × 10−9
12 6.52918602772248367 × 10−12
15 2.97881172300385740 × 10−16

The errors here are on the order of exp(−rn) for some constant r > 0.

Lecture 7 October 10, 2018 4 / 14


The Trapezoidal Rule

What’s going on? Why is the trapezoidal rule so effective for smooth,
periodic functions?

Lecture 7 October 10, 2018 5 / 14


The Trapezoidal Rule

We say that a quadrature rule


Z b n
X
f (x) dx ≈ f (xj )wj
a j=1

is exact for the functions f1 , f2 , . . . , fm if


Z b X n
fi (x) dx = fi (xj )wj for all i = 1, 2, . . . , m.
a j=1

That is, a quadrature rule is exact for a collection of functions if it correctly evlautes their
integrals.

Lecture 7 October 10, 2018 6 / 14


The Trapezoidal Rule

The (n + 1)-point trapezoidal rule on the intervals [−π, π] is


Z π
π
f (t) dt ≈ pf (x0 ) + 2f (x1 ) + . . . + 2f (xn−1 ) + f (xn )q (1)
−π n

where

xj = −π + j.
n

If f is 2π-periodic, then f (x0 ) = f (xn ) and (1) can be rewritten as


Z π
π
f (t) dt ≈ p2f (x0 ) + 2f (x1 ) + . . . + 2f (xn−1 )q
−π n

= pf (x0 ) + f (x1 ) + . . . + f (xn−1 )q
n
n−1 ˆ ˙
2π X 2π
= f −π + j
n j=0 n

Lecture 7 October 10, 2018 7 / 14


The n-point Periodic Trapezoidal Rule
We will refer to the quadrature rule
Z π n−1 ˆ ˙
2π X 2π
f (t) dt ≈ f −π + j , (2)
−π n j=0 n

as the n-point periodic trapezoidal rule. It is exact for the functions

exp(−ikt), k = −n + 1, −n + 2, . . . , −1, 0, 1, 2, . . . , n − 1.

Indeed, when (2) is used to approximate the integral


Z π
exp(ikt) dt,
−π

the result is
|k|

(−1) 2π
 if k = m · n for some nonzero integer m
2π if k = 0

0 otherwise.

Proof: This is part of homework assignment 3. 

Lecture 7 October 10, 2018 8 / 14


The Trapezoidal Rule

Corollary
If

X
f (t) = an exp(int).
n=−∞

then Z π
f (t) dt = 2πa0 ,
−π

whereas the approximation of the integral obtained via the m-point periodic trapezoidal
rule is

X
2πa0 + 2π (−1)km pakm + a−km q .
k=1

In particular, the error in the trapezoidal will be small if the Fourier coefficients of f
decay rapidly!

Lecture 7 October 10, 2018 9 / 14


The Trapezoidal Rule

Corollary
If f is a C k function, then error in the approximation of
Z π
f (t) dt
−π
ˆ ˙
1
obtained via the n-point periodic trapezoidal rule is O .
nk

Corollary
If f is a 2π-periodic function which is analytic in a strip containing the real line, then the
error in the approximation of Z π
f (t) dt
−π

obtained via the n-point periodic trapezoidal rule is O pexp(−rn)q with r > 0 a constant.

The first of these is a pessimistic estimate, meaning that it is not the best possible result.

Lecture 7 October 10, 2018 10 / 14


The Trapezoidal Rule and The Exponential Functions

The functions
{exp(int) : n ∈ Z}
are orthonormal with respect to the inner product
Z π
1
pf , g q = f (t)g (t) dt.
2π −π

That is, (
1 if n = m
pexp(int), exp(imt)q =
0 otherwise.

Lecture 7 October 10, 2018 11 / 14


The Trapezoidal Rule and The Exponential Functions

The periodic trapezoidal rule of length (2N + 1) integrates the exponential functions

exp(−i2Nt), . . . , exp(−it), 1, exp(it), . . . , exp(i2Nt).

This menas that it integrates all products of the form

exp(int) exp(imt)

with −N ≤ n, m ≤ N.

In other words, it accurately discretizes the restriction of inner product we just defined to
the finite-dimensional space

{exp(int) : −N ≤ n ≤ N} .

Lecture 7 October 10, 2018 12 / 14


The Trapezoidal Rule and The Exponential Functions

That is to say: if t0 , t1 , . . . , t2N , w0 , w1 , . . . , w2N are the nodes and weights of the
(2N + 1)-point periodic trapezoidal rule then
Z π 2N
1 1 X
pexp(int), exp(imt)q = exp(int) exp(−imt) dt = exp(intj ) exp(−imtj )wj
2π −π 2π j=0

for all −N ≤ n, m ≤ N.

Lecture 7 October 10, 2018 13 / 14


The Trapezoidal Rule and The Exponential Functions

If we assign to each 2π-periodic function f the C2N+1 vector


¨ c ˛
w0
f (t 0 )
c 2π
˚ ‹
˚ ‹
˚ f (t1 ) w1
˚ ‹

rf s = ˚
˚ 2π ‹,

˚ .. ‹
˚
˚ .c ‹

˝ w2N ‚
f (t2N )

then
2N+1 Z
1 X 1
rf s · rg s = f (tj )g (tj )wj ≈ f (t)g (t) dt. (3)
2π j=0 2π

If f and g are in the span of

EN = {exp(int) : −N ≤ n ≤ N} ,

then (3) is exact!! This is what we mean by the trapezoidal rule discretizes the inner
product we defined on the space EN .

Lecture 7 October 10, 2018 14 / 14

You might also like