You are on page 1of 17

Numerical Integration of Periodic Functions: A Few Examples

Author(s): J. A. C. Weideman
Source: The American Mathematical Monthly, Vol. 109, No. 1 (Jan., 2002), pp. 21-36
Published by: Mathematical Association of America
Stable URL: http://www.jstor.org/stable/2695765 .
Accessed: 20/12/2014 04:13

Your use of the JSTOR archive indicates your acceptance of the Terms & Conditions of Use, available at .
http://www.jstor.org/page/info/about/policies/terms.jsp

.
JSTOR is a not-for-profit service that helps scholars, researchers, and students discover, use, and build upon a wide range of
content in a trusted digital archive. We use information technology and tools to increase productivity and facilitate new forms
of scholarship. For more information about JSTOR, please contact support@jstor.org.

Mathematical Association of America is collaborating with JSTOR to digitize, preserve and extend access to
The American Mathematical Monthly.

http://www.jstor.org

This content downloaded from 193.255.248.150 on Sat, 20 Dec 2014 04:13:45 AM


All use subject to JSTOR Terms and Conditions
Numerical Integration of Periodic Functions:
A Few Examples
J. A. C. Weideman

1. A TEXTBOOKPROBLEM. In one of the morepopularcalculustextbooksthe


followingproblemappears[13, p. 466]:

This exercise deals with approximationsto the integral


r27
(f ) = f| f (x) dx, where f (x) = eCOSX. (1)

(a) Use a graph to get a good upperboundfor If "(x) l.


(b) Use M1oto approximateI.
(c) Use part (a) to estimate the error in part (b).
(d) Use the built-innumericalintegrationcapabilityof your CASIto approximateI.
(e) How does the actual error comparewith the error estimate in part (c)?

The notationMloin part(b) refersto the 10-panelmidpointrulefor numericalinte-


gration.This is nothingbut a Riemannsumin whichthe midpointof each subinterval
determinesthe heightof the rectangle.Thatis, we partitionthe interval[0, 2w] into N
subintervalswithuniformwidthh = 27r/N by defining2

xj = jh, j = 0,..., N.

The midpointrule MN(f) and its standarderrorestimate(to be used in part(c)) are


thengiven as in Stewart[13, pp. 458-460] by
N-1 JC3 K
My(f)=hEf (xj+ lh), II(f)-MN (f ) <I N (2)
j=O

The assumptionis thatf (x) is atleasttwice continuouslydifferentiableon [0, 27] and


K is anyboundon the magnitudeof the secondderivative,i.e.,

if"(x)l < K, O'<x < 27.

We also statethe trapezoidalrule TN(f ), with its errorestimate3


N-1 K
~~~~~~~~~27r3
TN(f)=h f(xj) + (21)1 < (3)
Theconstant?f()+
K the sameeaningasabov3
has lI(f)- TN(f)l 3 N2

The constantK has the samemeaningas above.


1CAS = ComputerAlgebra System.
2The interval [0, 27w]is for convenience only. Everything we say can easily be extended to an arbitrary
interval [a, b].
3One notices that the errorbound for the midpoint rule is one half that of the trapezoidalrule; compare (2)
with (3). For a pretty geometrical explanationof why one can expect the midpoint rule to be better by about a
factor of two, the readeris referredto Stewart [13, p. 460].

January 2002] NUMERICALINTEGRATIONOF PERIODICFUNCTIONS 21

This content downloaded from 193.255.248.150 on Sat, 20 Dec 2014 04:13:45 AM


All use subject to JSTOR Terms and Conditions
Startingwithpart(a) of the textbookproblem,we dutifullyturnto ourCASs, com-
pute the second derivative(only the bravedo this by hand),plot it on [0, 27r], and
observethatthe maximummagnitudeis reachedat bothx = 0 andx = 27r.We con-
clude that, if f(x) = eCOSx,then

1f`(x)j < e (= 2.718. ..),

whichwe recordfor use in part(c).


As for parts(b) and(d), we compute1(f) andMlo(f ) as

l(f) t 7.954926521, Mlo(f) t 7.954926518,

roundedto ten significantdigits.(In Section6 we computel(f) explicitlyin termsof


a specialfunction.)The erroris

I (f Mlo0(f) t 3 x 10-9, (4)


whichis spectacularlysmallconsideringthe relativelysmallvalueof N.
The excitementturnsto disappointment when we continueto parts(c) and (e). To
workpart(c) we use the errorbound(2). We have establishedthatthe best boundfor
the second derivative is K = e, and with N = 10 we get

73 e
{I(f) - M1o(f)l < -- ;_ 0.28. (5)
310
Truebutuseless,thisboundoverestimatesthe actualerror(4) by a factorof about108.
It's like saying the distancebetweenNew Yorkand Londonis less than 1011 miles
(abouta milliontimesthe circumferenceof the earth!).
At thispointmanyteachingassistantsandevena few professorsfindthemselvesat a
loss for wordsto explainthis spectacularfailureof the errorbound(2). The exceptions
are the numericalanalysts,who would be quick to point out that the midpointrule
(as well as the trapezoidalrule)is moreaccuratethanusualwhen appliedto integrate
smoothperiodicfunctionsover one period.For such functionsthe convergenceis so
quick that the standarderrorestimatebecomes irrelevant.This is illustratedin the
followingtable.

N I(f)-MN(f) Errorbound (2)


4 3.4 x 10-2 1.8 x 10?
8 1.3 x 10-6 4.4 x 10-
12 6.5 x 10-12 2.0 x 10-1

One of the thingswe intendto showhereis thatthe actualerrordecayslike4

I(f) - MN(f) -2 (2)/2N (2)N (6)

which yields the estimates3.3 x 10-2, 1.2 x 10-6, 6.4 x 10-12 when N = 4, 8, 12,
respectively.These numberscomparefavorablywith the values listed in the middle
columnof the table,despitethe fact thatN is not particularlylarge.
4We use the notationaN - bN to denote that 1imNoo aN/bN = 1.

22 ?g THE MATHEMATICAL ASSOCIATION OF AMERICA [Monthly109

This content downloaded from 193.255.248.150 on Sat, 20 Dec 2014 04:13:45 AM


All use subject to JSTOR Terms and Conditions
2. PRELIMINARIES. A generalanalysisof the speed of convergenceof the mid-
point andtrapezoidalrulesfor smoothperiodicfunctionsrequiresa good dose of ad-
vanced calculus.In the literatureone finds three approaches:(a) Fourierseries [7,
p. 155], (b) residuecalculus[9, p. 211], and (c) the Euler-Maclaurinsummationfor-
mula[2, p. 285].
All threeof these approachesrequirebackgroundthatthe typicalfirst-yearcalculus
studentlacks. For that matter,it cannotbe takenfor grantedthat a numericalanal-
ysis studentat the junior or seniorlevel will know much aboutthese topics either.
This leaves the instructorwith only one recourseto explainthe observeddiscrepancy
betweenthe actualerrorandthe theoreticalerrorbound:hand-waving.
The author'sown effortgoes somethinglike this:"Interpret the integralas the area
underthe graphof f(x), and considerthe trapezoidalrule. In those regions where
the graphis concaveup (respectively,down)the trapezoidsoverestimate(respectively,
underestimate)the true area.When the functionis periodicand one integratesover
one full period,thereare aboutas manysectionsof the graphthatare concaveup as
concavedown,so the errorscancel.Thisleavesone with a muchbetterapproximation
thanwouldhavebeen the case hadthe functionbeen monotonic."
This explanationsatisfiesmost students,and they go on theirway to more inter-
esting things.Thankfully,however,thereare some studentswho would like to know
more,andthis note was writtenfor them.
We shall presenta series of examples,almostall of which have the propertythat
the errorin the trapezoidalandmidpointrules can be computedexplicitly.These ex-
ampleswere selectedto illustratea varietyof convergencebehaviors,most of them
quickerthanthe typical1/N2 givenby (2) and(3). We shallsee algebraicconvergence
like 1/N4, geometricconvergencelike rN (with 0 < r < 1), as well as the superfast
convergencedescribedby (6). A completelist of examples,arrangedin increasingor-
derof speedof convergence,is givenin Table1. (All integralsaredefinedon [0, 27r],
andN is the numberof subintervalsin the integrationrule.)

TABLE 1. Examples
Essential
Example convergencerate Section
f2(x) = sin(x/2) 1/N2 4
f7(x) =e 2N2 1/ 8
f3(x) = sin3(x/2) 1/N4 4
f6(x) = e(C0SX-1)/(CoSX+l) e-(312)N2/3 7
f4(x) = 1/(a-cosx), a > 1 rN (O < r < 1) 5
fA(x) = eacosx 1/NN 6
f1 (x) = cos kx, k an integer exact (N > k) 3

Ourprincipalaim was to writethis paperin such a way thatit may serve as sup-
plementaryreadingfor the firstcoursesin integralcalculusor numericalanalysis.For
this reasonwe shallpresentthe examplesin increasingorderof mathematicalsophis-
tication(as opposedto increasingspeedof convergence).
To readSections2-5 the studentrequiresnothingmorethanfamiliaritywith geo-
metricseries,partialfractions,andEuler'sformulae'o = cos 0 + i sin0. The strategy
we follow in Section 5 is based on Fourierseries, but we shall assumeno previous
exposureto this technique.Termwiseintegrationof such series will be used, andthis
we will haveto askthe first-yearstudentto accepton good faith.

January2002] NUMERICAL INTEGRATIONOF PERIODICFUNCTIONS 23

This content downloaded from 193.255.248.150 on Sat, 20 Dec 2014 04:13:45 AM


All use subject to JSTOR Terms and Conditions
The examplesof Sections6 and7 havea moreadvancedflavor,in thatthey assume
some familiaritywith specialfunctions.Section6, in whichthe textbookexample(1)
will be analyzed,requiresa passingacquaintancewith Bessel functions.In Section7
we shall encounterMeijer'sG-function.The authortriedhis best to demonstratethe
peculiarconvergencebehaviorof Section 7 using more familiarfunctions,but was
unsuccessful.This sectionis thereforestrictlyfor the aficionado.
The secondaryaim of this articlewas to provideexamplesto researchersand ad-
vancedstudentsto supplementthe materialin [11]. The authorsof thatpapermade
a commendableeffortto give a characterization of the speed of convergenceof the
trapezoidalrule for differentclasses of functions,but they did not providemanyex-
amples.
The mainformulasin whatfollows come fromconsideringthe integrals
p27
I(eikx) = 1 eikx dx,

wherek is an integerandi2 = _1.


Supposefirstthatk :A0. By usingthe fact thate27rik = 1, we obtain

27ik 1 2 112
j e dx= ie = (e2ik ) =O

Whenk = 0 the integralsimplifiesto 1 dx = 27r.We thereforeconcludethat

I fek = 27r fork =0, (7)


I(eikx) (o7 fork-?19 ?2. (

to theseintegrals.Applyingthe
Let us now also computenumericalapproximations
trapezoidalruleyields
N-1 N-1
TN(eikx) = h + E ekx 1 e27ik) = hZ e2 iku/N (8)
j=l j=O

The sum on the rightis a finite geometricseries, with commonratioe27rik/N. We can


evaluateit explicitlyto obtain

TN(eikx) = h1 2ik

this kocurs henevrthe


k inumerator 1 - e27rik/N
an itegeris always
Since is aninteger, zero.The denominatormay also be zero:
this occurswheneverk is an integermultipleof N. In the lattercase, the trapezoidal
sum simplifiesto TN(eikx) = h _yN 1 = hN = 2wf.We inferthat
T1ikx f 27-r for k = fN ( = 0, ?1, ?2,... ) (9
TN(e ) t 0 otherwise. (9)

Turningto the midpointrule,we note that

MN(eikx) = eikh/2TN(eikx) (10)

24 ?kTHE MATHEMATICAL ASSOCIATION OF AMERICA [Monthly109

This content downloaded from 193.255.248.150 on Sat, 20 Dec 2014 04:13:45 AM


All use subject to JSTOR Terms and Conditions
Since eikh/2 = ei7r = (_1)e when k = EN, we conclude that

( 27r(-l)f
(N=e,l,02,o.t.h.
MN(eikx) fork-=N (11)

We arereadyfor ourfirstexample.

3. EXAMPLE 1 (Perfect Convergence). For each numericalintegrationrule there


exists a class of functionswiththe propertythatthe ruleintegratesall functionsin this
class exactly.5All these functionswould,of course,provideexamplesof "fasterthan
average"convergence.
For the trapezoidaland midpointrules this class of functionsincludes the linear
functionsf (x) = mx + c. It also includes any functionthat is antisymmetricwith
respectto the line x = TC,i.e., functionsf for which f (x) = -f (27r - x). For such
functionsboththe trapezoidalandmidpointrulesyield the correctvalueof zero.
Importantspecialcases arethefunctionssin kx, wherek is anyinteger.The symme-
tryargumentof thepreviousparagraph maybe invokedto showthatsinkx is integrated
exactlyfor each k. Anotherimportantspecialcase comprisesthe functionsgiven for
integralvaluesof k by

f1(x) = coskx, 0 < x < 27r.

If k = 0 the functionreducesto the constant1, which is integratedexactly, so we


consider only integers k > 1. We note that TN(f + g) = TN(f ) + TN(g). Hence

cos kx = 1 (eik1 + eikx) = TN(fl) = 2 (TN4(e) + TN((e )).

By using the formula(9) one concludesthat the exact value I (fi) = 0 is obtained
whenk is not an integralmultipleof N; in particular,this happenswhen N > k. Sim-
ilarargumentsapplyto the midpointrule.
On the basis of these examplesone mightconjecturethatfor a functionto be in the
"perfectconvergence"class, symmetryis necessary.This appearsnot to be the case.
In [11, p. 124] a functionis cited that has no apparentsymmetryproperties,yet is
integratedexactlyby the trapezoidalrule. Involvingthe M6biusfunctionof number
theory,it is one of those fractal-likefunctionsthat are continuousbut not absolutely
continuous.

4. EXAMPLES 2 AND 3 (Algebraic Convergence). Fromperfectconvergencewe


move to the ratherslow 1/N2 type of convergencethatis typicalfor boththe midpoint
andtrapezoidalrules.
Consider

f2(x) = sin(x/2), 0 <x < 27r. (12)

The functionsin(x/2) has period47r,not 27r.We obtain27r-periodicity by thinking


of (12) as the restrictionof the functionIsin(x/2) 1to the interval[0, 27r].
Proceedingas in the previoussection,we observethat

sinkx = 1 (eikx - eikx) = TN(f2) = (TN(ek)ikx - TN(e& k))x (13)

5We disregard,of course, the effects of roundoff error.

January2002] NUMERICAL INTEGRATIONOF PERIODICFUNCTIONS 25

This content downloaded from 193.255.248.150 on Sat, 20 Dec 2014 04:13:45 AM


All use subject to JSTOR Terms and Conditions
Eachof the trapezoidalsumsin parenthesesis essentiallya finitegeometricseriesthat
we computein a mannersimilarto the calculationthatleads from(8) to (9). By using
the fact that e'i = -1, we obtain
N-1 N-1
TN(eix/2) = h + Eix2 + le = hE eiN
j= ? j=1

Applyinggeometricseriesformulasto the sumon the rightyields

NE1 +
-1- e2Ti/N e-7i/(2N) + e7ri/(2N) 7r

j=1 - e7rilN e-7i/(2N) -


e7r/(2N) 2N

The trapezoidalsum TN (eix/2) can be handledsimilarly.We concludethat

TN(eix/2) ??hi cot-

Substitutingtheseformulasinto (13), we obtainan explicitformulafor the trapezoidal


sum,namely,
27r 7r
TN (f2) = cot 2 .
N 2N
We computethe truevalue of the integraldirectlyas I (f2) = 4 andarriveat an exact
expressionfor the error:
27r JC
I(f2)-TN(f2)44- - cot 2N

The magnitudeof this errorcan be determinedby using the Taylorexpansion

1 x x3
cotx - - = -- - 45 - , O < IxI < 7f (14)

(see AbramowitzandStegun[1, p. 75]). We concludethat

7r21
I(f2) - TN(f2) 3 N2

This estimateimprovesslightlyon the standardestimate(3), which yields the bound


w3/(6N2) when K = 1/4. But both predictessentiallya convergencerate of 1/N2,
whichis the typicalsituation.
Fasterconvergenceis obtained,however,whenwe turnto the function

f3(x) = sin3(x/2), 0 < x < 2Jr. (15)

We again interpretthis as the restrictionto [0, 2wf] of the 2Jr-periodicfunction


Isin(x/2)13. (The readermay wonder why we chose to jump from the function
sin(x/2) to the functionsin3(x/2), skippingthe functionsin2(x/2). Well, sin2(x/2) =
(1 - cos x)/2 and accordingto Section3 boththe trapezoidalandmidpointrules are
ableto integratethis exactlywhen N > 2.)

26 ?oTHE MATHEMATICALASSOCIATIONOF AMERICA [Monthly109

This content downloaded from 193.255.248.150 on Sat, 20 Dec 2014 04:13:45 AM


All use subject to JSTOR Terms and Conditions
Using the left side of (13), herewithk = 1/2, we compute

sin3(x/2) = - (e3ix/2 -3eix/2 + 3e-ixl2 _ e-


8
Proceedingin the samemanneras earlier,we get

TN (f) (TN(e3ix/2) - 3TN(eix/2) + 3TN(e ix/2) - TN(e 3ix/2))

=2_N3 cot -cot_


2N 2N 2N,

Directintegrationgives I (f3) = 8/3, andan appealto (14) showsthat

J741
I() - TN(f3) -3

The factor 1/N4 confirmsthat the convergenceis fasterthan typical. The standard
errorboundis of limiteduse, as the followingtableshows (computedwith K = 3/4).

N II (f3)-TN(f3)I Errorbound(3)
10 3.3 x 10-4 1.6 x 10-1
20 2.0 x 10'- 3.9 x 10-2
40 1.3 x 10-6 9.7 x 10-3

The readerwill wantto know whatcausesthe differentconvergenceratesin these


two examples.We shallpostponesuchgeneraldiscussionsuntilSection7, butfor now
we note thatthe 27r-periodicfunctionsIsin(x/2)1 and Isin(x/2)13havejump discon-
tinuitiesin, respectively,theirfirstand thirdderivatives(at x = 0 and x = 27r).The
respectiveconvergenceratesare 1/N2 and 1/N4. The morecontinuousderivatives,the
quickerthe convergence.
To concludethis sectionwe remarkthatwe have focussedhere on the trapezoidal
rule, but explicit errorformulascan also be obtainedfor the midpointrule. By us-
ing the connectionbetweenthe two rules summarizedby (10), one deducesthateach
cotangentin the trapezoidalrule formulasshouldbe replacedby the cosecantfor the
midpointrule.Using the Taylorseriesof csc x - x (as in [1, p. 75]), the asymptotic
errorbehavioris foundto be

I(2) - MN(f2) -6f I()- MN(f3) 240N4

In the next sectionwe shall see an exampleof muchquickerconvergence.

5. EXAMPLE4 (GeometricConvergence).Let a be a constantandconsider


1
f4(X)- =0 < x < 27r.
a- cosx
To avoidsingularintegrals,we only treatthe case wherea > 1.

January2002] NUMERICAL INTEGRATIONOF PERIODICFUNCTIONS 27

This content downloaded from 193.255.248.150 on Sat, 20 Dec 2014 04:13:45 AM


All use subject to JSTOR Terms and Conditions
Like the textbook example (1), this function is 27r-periodic and smooth, and there-
fore one expects high accuracy. This is confirmed by the following table (computed
witha = 2, I(f4) = 2Tr/V3, K = 1).

N I(f4) - MN(f4) Errorbound (2)


4 3.7 x 1O-2 6.5 x 10-1
8 1.9 x 10-4 1.6 x 10-1
16 5.1 x O-9 4.0 x10-2

What we intend to do is to derive an explicit formula for the errors in the middle
column. This will show that the error decreases at essentially a geometric rate rN for
some positive r < 1 that we shall determine.
To this end, we express f4(x) as

1 eix

a - (eix + e-ix)/2 2 (eix - r)(eix - l1/r)' (16)

where r satisfies

r2 -2ar + 1 = 0.

We may choose to work with either root of this quadratic, so we pick

r = a- a-, (17)

which satisfies 0 < r < 1.


Consider the final expression in (16) as a rational function in the variable z = eix,
and expand it in partial fractions

M4X) = 2 r2 _1[I relx


rt ei
[i 1ei

Since Ire--x = I < 1 for each real value of x, the first two terms inside the square
brackets may be expanded as geometric series
00
1 = E rk +ikx
1reii k=O

Finally, we obtain

f4(x) =2 2 1+ , rk e E rk e-ikx l (18)

Students who have had a course in advanced calculus or analysis will recognize
in the right-hand side of (18) the Fourier series of the function f4(X).6 We shall not
make any use of the properties of Fourier series, except to note that it is in fact valid
to integrate this particular series termwise with respect to x. Doing so yields, as an
6The function f4 (x) is relatedto the Poisson kernel that appearsin the solution of boundaryvalue problems
defined on the circle.

28 ?M
THE MATHEMATICAL ASSOCIATION OF AMERICA [Monthly109

This content downloaded from 193.255.248.150 on Sat, 20 Dec 2014 04:13:45 AM


All use subject to JSTOR Terms and Conditions
unexpectedpayoff,the exactvalueof the integral,namely,

] f4(x)dx=4r r2 (r=a - a2- (19)

wherewe haveused (7).


One may likewiseapplythe midpointformula(11) termwiseto (18) to obtain

MN(4) = 4 -rr [ ?+ 2 (-l)IrPN

Subtractingthis expressionfrom(19) yields an explicitformulafor the error


00 N.

I(4) - MN(4) 87r 1 2 Z( l)fr 8=r1 2 +rN (20)

The formulafor the trapezoidalruleis similar,exceptfor the factor(- 1)f, i.e.,

r rN
I(f4) -TN(f4)= 8 1-r2 1 rN (21)

A similarresultwas obtainedin [5], buttherethe authorsused complexcontourinte-


grationin theirderivation.
For large N we may use the approximation1 ? rN _ 1 to concludethatboth the
midpointandthe trapezoidalrule convergeat essentiallythe exponentialraterN. The
smallerr (or the largera), the quickerthe convergence.
Whena >> 1 (respectively,a 1 l) the integralassumessmall (respectively,large)
valuesandit is moremeaningfulto look at the relative(or percentage)error,whichis

II (f4) -MN (f4)1 2rN


I I(f4)1 1 + rN

The relativeerrorand the numberd of correctsignificantdigits are roughlyrelated


by [2, p. 18]
rN 1
2 - x lo-d.
1 +rN 2
ForlargeN this yields

d t (-log10 r)N.

By doublingN the numberof correctsignificantdigits approximatelydoubles,which


affirmsthe quickconvergence.

6. EXAMPLE 5 (Super-geometric Convergence). Here we increase the required


backgrounda notch,by requiringsome familiaritywithBessel functions.
Let a be a positiveconstant,andconsiderthe function

f5(x) = eaCOSx, 0 < x < 2wr.

It includesthe textbookexample(1) as a specialcase.

January2002] NUMERICAL INTEGRATIONOP PERIODICFUNCTIONS 29

This content downloaded from 193.255.248.150 on Sat, 20 Dec 2014 04:13:45 AM


All use subject to JSTOR Terms and Conditions
Wemay also representthisfunctionas a seriesof the form(18). Ourpointof depar-
tureis the generatingformulafor the modifiedBessel functionsof the firstkind,In(x),
definedin [1, p. 376] by
00

ex(t+t1)/2 = E Ik(X)tk.
k=-oo

From the substitutions x a and t e'x follows


00 00
ea cOsX = Io(a) + E Ik(a)e + E3Ik(a)e-ikx. (22)
k=1 k=1

We haveused the fact thatIk(x) = Ik(x), k = 1, 2, ....


Integratingterm-by-term yields the truevalueof the integralas7
p27
eacosx dx = 27rIo(a). (23)

to this integralas
yields the midpointapproximation
Summing(22) term-by-term
00
MN(f5) = 21 Io(a) + 4X Z(-1)e IeN(a),
f=1

for whichthe erroris


00

I (f5) - MN(f5) = -47 ,(- 1)eIEN (a). (24)


f=1

The errorformulafor the trapezoidalruleis identicalexceptfor the factor(- 1)'.


The Bessel functionsIk(x) decay rapidlyfor fixed x as k -> oo; namely,from [1,
pp. 365 and375] we learnthat
1 eX\k
Ik(X)
s/2 (-I.2k

This meansthatwe may retainonly the firsttermin (24), i.e.,

I (f5) - MN(f) - 47cIN(a)

27r 1/2 ea N

whichis how we arrivedat the estimate(6).


The convergencerate is essentiallyof the form rN, with r = (ea)/(2N). Since
r -- 0 as N -- oo, the convergencerateis often referredto as super-geometric
(see
Boyd [3, p. 32]).

7. EXAMPLE6 (Sub-geometric Convergence). Mainlyof academicinterest,ourfi-


nal exampleassumesparticularknowledgeof Fourierseriesandspecialfunctions.
7The result (23) is not to be sneered at. Only one of the three CASs we tried was able to carry out this
integrationin symbolic form, even when we put a = 1.

30 ?XTHE MATHEMATICAL ASSOCIATION OF AMERICA [Monthly109

This content downloaded from 193.255.248.150 on Sat, 20 Dec 2014 04:13:45 AM


All use subject to JSTOR Terms and Conditions
Consider
f = e(cosxl)/(cosx+l) 0< <
X27r. x :A (25)

This functionis 27c-periodicand, as can be checkedwithoutgreat difficulty,is in-


finitelydifferentiable.High accuracyis to be expectedwhen its integralis approxi-
matedby the trapezoidalor midpointrules, and that this is indeed the case may be
seen in the tablefollowingrelation(30). (Tocomputethe error,we haveused a CAS to
establishthatI (f6) = 2e7r(1 - erf 1) = 2.68658684..., whereerf is the errorfunc-
tion definedin [1, p. 297].)
An explicitformulafor the errormay be derivedby assuminga Fourierseries ex-
pansionof the form
00

f6 (x) = Z cke , (26)


k=-oo

wherethe Fouriercoefficientsaregivenby

Ck = ff (x)ex dx. (27)

Throughrepeatedintegrationby parts,it can be deducedfrom (27) that the Fourier


coefficientssatisfyCk=0 (IkI-) for each integerE.
Integratingandthensummingbothsides of (26) leadsto
00

I(f6) =27co, TN(f6) = 27wco+ 27r E CEN


f=-o0
to

wherewe haveused (7) and(9). The erroris


00

I (6) - TN(f6) = -27r E


E=-oo
CEN (28)
to

The midpointerroris similar,exceptfor the usual (- 1)j factor.


The Fouriercoefficientsof the functionf6(x) can in fact be computedexplicitlyin
termsof Meijer'sG-function.We omit the detailsbutreferthe readerto [15, p. 1501]
and [16, pp. 125-126]. The resultis
e 3O0 1 -k, 1 ?k\
Ck = G23(l 1 1 l+ k =0?1,?2.

Since these coefficientsdecay quiterapidly(recallthe remarkthatfollows (27)), we


retainonly the two termscorrespondingto E= ?1 in (28) to estimatethe erroras8

I(f6) - TN(f6) -4eVG3 G(3 1 -N, 1 +N (29)

An asymptoticestimateof the functionon the righthas been carriedout by the author


in [15, pp. 1501-1510], andthe resultis
8TheG-functionin theerrorestimate(29) maybe computedin Mapleby
MeijerG(I[ ], ], [1-N, 1+N], [1, 1/2, 0], [ ], 0).

January2002] NUMERICAL INTEGRATIONOP PERIODICFUNCTIONS 31

This content downloaded from 193.255.248.150 on Sat, 20 Dec 2014 04:13:45 AM


All use subject to JSTOR Terms and Conditions
_
(f6) - TN(f6) (_l)N+l8(7c/3)l/2e2/3N-2/3

x cos (I12N2/3 + exp (_ N2/3) (30)

Theseestimatesaresharp,even for relativelysmallN:

N lI(f) - TN(f)) lEstimate (29)1 lEstimate (30)1


10 2.8 x 10-3 2.8 x 10-3 2.8 x 10-3
20 7.7 x 10-6 7.6 x 10-6 7.8 x 10-6
40 3.3 x 10-8 3.3 x 10-8 3.3 x 10-8

The speed of convergenceis essentially determinedby the exponentialterm


e-(3/2)N / in (30). It indicates a convergencerate quickerthan the algebraiccon-

vergenceof Section4, butnot quiteas fast as the geometricconvergenceof Section5.


This is oftenreferredto as sub-geometricconvergence(see Boyd [3, p. 32]).
Note also the oscillatorycosine termin (30). It may assumevalues close to zero,
whichwouldimplyhigh accuracy.The zerosof the cosine termoccurwhere

F2w776k - \1-3/2
L33/2 ( 6 ).
By takingthe nearestintegerone obtainsa sequenceof values,namely,
N =2,4,7, 11, 16,20,26,31,37,43,50,56,64,71,79,...,
thatshouldyield particularlysmallerrors.Forexample,withN = 31 one gets I (f6) -
T31(f6) 7.5 x 10-9. Increasingthe numberof subintervalsto N = 33 yields the
_

significantlylargererrorI(f6) - T33(f6) -2.7 x 10'. The authorknows of no


otherclass of functionsthatexhibitsthis patternof convergence.
nonmonotonic

8. GENERALERRORFORMULAS. The examplespresentedin the previoussec-


tions were specialin thatwe were able to derive,in most cases, explicitformulasfor
the error.9Forgeneralintegralsthe best one couldhope to do is estimatethe error.To
learnmoreaboutsucherrorestimatesthe studentis encouragedto consulttheliterature
(forexample[2], [7], or [9]).
One of those references,Gautschi[7, p. 155], uses the Fourierseries as basis for
a convergenceanalysisof the trapezoidalrule. This is essentiallythe approachwe
followed in Sections 5-7. When the Fouriercoefficientsdecay to zero quickly,as
they do for functions f4(x), f5(x), and f6(x), then the formula (28) provides a good
estimatefor the error.On the other hand, when the Ck approacheszero only alge-
braically,like 1/IkI, then (28) shouldnot be used as it stands.To see why not, con-
siderfor examplethe functionf (x) = e-x definedon [0, 27r]. Its Fouriercoefficients
are Ck =(1/27w)(1 - e-27)/(l + k i), which decay like 1/k. As a result,the series
in (28) does not converge.Yetboththe midpointandtrapezoidalrule approximations
convergeaccordingto the standard1/N2. (Thesituationcanbe remediedby consider-
ing only the cosine-partof the Fourierexpansion,as in [7, p. 155].)
An alternativeforfunctionsof relativelylow continuityis the Euler-Maclaurinsum-
mationformula,which we statehere for a functionf (x) thatis not necessarilyperi-
odic. The proofmaybe foundin Atkinson[2, p. 285].
91f one thinks about it, an explicit formula for the error means one can obtain the value of the integral
exactly, and numericalintegrationwould not be necessary in the first place!

32 ? THE MATHEMATICALASSOCIATIONOF AMERICA [Monthly109

This content downloaded from 193.255.248.150 on Sat, 20 Dec 2014 04:13:45 AM


All use subject to JSTOR Terms and Conditions
Theorem 1. Let m > 0, N > 1, and define h = 27r/N, xj = jhfor j = 0,1, ...,N.
Further assume that f (x) is 2m + 2 times continuously differentiable on [0, 27r]for
some m > 0. Then,for the error in the trapezoidal rule defined by (3),
m
1( f))-TN (f ) = _-E 2k h2k [ f (2k-1)(2) f (2k-1) (0)] (31)
k=1 (2k)!
- 2?h2m+2 B2m+2 (2m+2)(o
27h f
(2m + 2)!

for some t in [0, 2cr]. The Bk are the Bernoulli numbers [1, p. 804].

The typicalcase correspondsto m = 0, in whichthe sumin (31) is void. Using the


fact thatB2 = 1/6, the formulareducesto

I (f)- TN(f) = -h6- f (2)(t

whichleads to the standarderrorbound(3). Note, however,thatif the odd derivatives


of f (x) at x = 0 andat x = 2w areequal,the termsin the sum in (31) cancel,andthe
convergencemay be quickerthanusual.
This was the situationfor the functionfM(x)= sin3(x/2). Since f3(0) = f3(27r),
but f."(0) 0 f3"(27r),one may take m = 1 in the Euler-Maclaurin formula,which
thenpredictsa convergencerateof orderh4or 1/N4. By contrast,thefunctionf2(x) =
sin(x/2) does not have equalfirstderivativesat the endpointsof the interval[0, 2w],
andthe regularconvergencerateof 1/N2 is obtained.
The Euler-Maclaurin formularaisesthe interestingpossibilityof certainfunctions
posingas "pseudo-periodic" functions,at leastin finiteprecisionarithmetic.Cooisider,
for example,the nonperiodicfunction

f7(x)=e-X2 0 < x < 2w. (32)

Approximationsby the trapezoidalrule yield the errorslisted in the following table


(once againin comparisonwith the standarderrorbound(3), with K = 2):

N II(f)-TN (f7)I Errorbound(3)


6 2.2x 10-4 1.1 x 10?
8 2.0 x 10-7 6.5 x 10-1
10 2.5 x 10-11 4.1 x 10-1

The function(32) does not satisfy f7(0) = f7(2w), and thereforeone expectsthe
typicalconvergencerate 1/N2. The numericalresultsin the table,however,seem to
indicatemuchquickerconvergence.To see why,note thatall odd derivativesat x = 0
vanish,while at x = 2w many of them are negligible:f7(27r) o10-16, f7"(2w) t
l0-14, f7""'(2r) t 10-12, etc. Whenworkingto aboutsixteensignificantdigits,as we
did here, the derivativetermsin the Euler-Maclaurin formulacancel for all practical
purposesand the numerical resultsindicatea convergence rate much fasterthanthe
expected 1/N2. It shouldbe in
kept mind,however, that the numbersin the middle
columnrepresenttransientbehavior.If the computationsweredoneto higherprecision
andfor largervaluesof N, the convergencewould eventuallysettle into the standard
1/N2 rate.

January2002] NUMERICALINTEGRATIONOP PERIODICFUNCTIONS 33

This content downloaded from 193.255.248.150 on Sat, 20 Dec 2014 04:13:45 AM


All use subject to JSTOR Terms and Conditions
The argumentof the previousparagraphshows why spectacularaccuracymay be
achievedwhenthe trapezoidalruleis appliedto integralsof the form
^00
I e-X2f (x) dx.
-00

This observationdates back at least half a centuryto a paperof E.T. Goodwin [8],
whichwas inspiredby a paperof AlanTuring[10, p. 214]. In turn,thesedevelopments
inspiredFrankStengerto developthe powerfulmachineryof sinc functions[12].
For periodicfunctionsthat are infinitelydifferentiable,like our functionsf4(x),
f5(x), and f6(x), the Euler-Maclaurinformulapredictsa convergenceratefasterthan
any powerof h (or 1/N). On the otherhand,the formulais not sufficientlypowerful
to determinethe rateprecisely.For this one has to go to methodsbased on analytic
functiontheory.Using residuecalculus,for example,the following theoremmay be
proved[9, p. 211].

Theorem 2. Let f: R R be analytic and 27c-periodic. Then there exists a strip


D = R x (-c, c) C C with c > 0 such that f can be extended to a bounded holomor-
phic and 2w-periodic function f: D C
C. The errorfor the trapezoidal rule can be
estimated by

lI(f) - TN(f)l < 4e7rCN 1' (33)

where M denotes a boundfor the holomorphicfunction f on D.

This theorem says that if the 2wr-periodicfunction f (z) is analytic in a strip


lm(z) < c, then geometric convergence of the form rN, with r = ec < 1, is as-
sured.The widerthe stripof analyticity,the quickerthe convergence.
The functions of Sections 5 and 6 are in this class. Consider f4(z) = I/(a - cos z),
a > 1, whichhas simplepoles at pointswherecos z = a, i.e., at

Zk =2k?r i yi, k = 0,? 1, ?2, ...,

with y = log(a + /a-2-1). The strip of analyticity is therefore determined by c < y.


This means that the convergence rate is essentially of the form e-cN = 1/(a +
a2 - = (a -a N, which is consistent with our exact expression for
the error(see (21)).
The textbookfunctionf (z) = ecs z is entire;i.e., it has no singularitiesin the finite
complexplane.One cannottakethe strip Im(z) < c infinitelywide, however,as M
growsunboundedlyas c -- oo. In fact, a quickcalculationshowsthatthe least upper
boundfor f (z) in the strip Im(z) < c is M = ecoshc andsubstitutioninto (33) yields
ecosh c
I(f) - TN(f)l < 47wcN

A minimizationargumentshowsthatto maketheright-handside a tightboundfor each


(large)valueof N, a choicelike c = sinh-1N or cosh-1 N shouldbe made.Choosing
the lattergives
eN
1I(f) - TN(f)l < 47eNcosh1 - 1

34 ? THE MATHEMATICAL AS SOCIATION OF AMERICA [Monthly109

This content downloaded from 193.255.248.150 on Sat, 20 Dec 2014 04:13:45 AM


All use subject to JSTOR Terms and Conditions
As N -- oo the bound on the right decreases like 47r(e/2N)N . Aside from a factor
convergencedefinedby (6).
,22N, this is identicalto the super-geometric
The functionf6(x) studiedin Section7 was a pathologicalcase squeezedbetween
Theorems1 and2 (andthatis why we choseto includeit). Since f6(x) is infinitelydif-
ferentiableon [0, 2w-],the Euler-Maclaurin formulapredictsa convergenceratemore
rapidthan1/Ne for anyt > 0. However,becausethis functionhas an essentialsingu-
larityat x = 2C,it is not analyticin any stripIIm(z)I < c with c > 0. This meansthat
the errorestimate(33) cannotbe appliedto thissituationto establishgeometricconver-
gence.Indeed,the convergencerateof e-(3/2)N2/3 derivedin Section6 falls somewhere
betweenalgebraicandgeometricconvergence.
Perhapsthe most comprehensiveattemptat classifyingthe speed of convergence
of the trapezoidalrule was given by Rahmanand Schmeisserin [11]. They made a
convincingpointthatfunctionscanbe cataloguedinto differentsmoothnessclasses on
the basis of the speedof convergenceof the trapezoidalrule.

9. CONCLUSIONS. The main theme of this essay is that, when the integrandis
smoothandperiodic,the midpointandtrapezoidalrulesareveryefficient.Using more
sophisticatedrules may not be worth the effort. One such rule is Simpson'srule,
which normallyconvergesat a rate 1/N4. Typicallyderivedby computingthe area
underpiecewisequadraticapproximations of the function,Simpson'srulemay also be
viewed as a weightedaverageof the midpointandtrapezoidalrules

SN(f) = 2MN/2(f) + 3TN/2(f).

Whenthis rule is appliedto the functionf4(x) = 1/(a - cos x), for example,the er-
ror estimates(20) and (21) show that the rate of convergenceis roughlyrN12 (with
r definedby (17)). This is fasterconvergencethanthe 1/N4 rate that is typical for
Simpson'srule.Nevertheless,one wouldneed abouttwice as manypointsto achieve
the same accuracyas eitherthe midpointor the trapezoidalrule.
One shouldnot concludefrom this, however,thatthe midpointor the trapezoidal
rule beat all-comershands down when the integrandis smooth and periodic.For
f4(x) = 1/(a - cos x), with a = 1 + E and 0 < E << 1, the powerful Gauss-Legendre
rule is superior,althoughthis superioritydisappearsas a increases (see Davis [4,
p. 54]). If one changesthe minussign in the denominatorinto a plus (so thatthe peak
of the graphis in the middleof the intervalratherthanat the endpoints),thenthe mid-
pointandtrapezoidalrulesremainthe clearwinners,as demonstrated in [5]. Numerical
resultshave also indicatedthatboth the midpointand trapezoidalrules integratethe
functionsf5 (x) andf6(x) betterthanthe Gauss-Legendre ruledoes.
The rapidspeed of convergencemay be exploitedin variousways. First, it may
be useful for the computationof special functions(see Luke [10, chapter15]). The
applicationof these rules to the integral(23), for instance,representsa respectable
tool for computingIo(x), providedx is not too large.
Second,consideran integralfor which the typicalrateof convergenceis the stan-
dard1/N2. One may attemptto improvethe accuracyby a changeof variables,with
the aim of makingthe integrand"moreperiodic."Such transformation methodsare
discussedin [6, pp. 107-135] and[9, p. 220].
Third,thereis the Fourierspectralmethod.Based on the differentiationof trun-
cated Fourierseries such as (26), this is a powerfulmethodfor solving differential
equations[3], [14]. Whenthe underlyingfunctionis smoothandperiodic,the rateof
convergenceof the Fourierspectralmethodis similarto the rateof convergenceof the

January2002] NUMERICAL INTEGRATIONOP PERIODICFUNCTIONS 35

This content downloaded from 193.255.248.150 on Sat, 20 Dec 2014 04:13:45 AM


All use subject to JSTOR Terms and Conditions
rules.Indeed,severalof ourexamplescanbe usedto quantifythe
trapezoidal/midpoint
convergencecurvesof the spectralmethoddisplayedin [14, p. 36].
Fourth,and perhapsmost importantly,is the computationof Fouriercoefficients.
Applyingthe trapezoidalruleto the integral(27) andassumingf (O)= f (27r)yields

I N-1
Ck -E Z f
(x j )e27rijk/N

Not only has our discussionshown that this is the "right"way to approximatethe
integral,butthe summaybe evaluatedefficientlywiththe FastFourierTransform(see
Atkinson[2, p. 181] or Kress [9, p. 167]). This is an algorithmthat approximatesN
of the coefficientsCk in asymptotically0 (N log N) algebraicoperations.By contrast,
directsummationrequires0 (N2) operations.The FFThas revolutionizedapproaches
to applicationssuchas signalprocessinganddigitalimaging.

ACKNOWLEDGEMENTS. The authorthanks An6l Kemp, a student at the University of Stellenbosch. Her
honorsproject,writtenunderguidance of the author,dealt with analyzing the errorin the trapezoidalrule by the
method of residue calculus. Useful suggestions by Bob Burton, Dirk Laurie, Nick Trefethen, and particularly
David Elliott are also acknowledged.

REFERENCES

1. M. Abramowitzand I. Stegun, Handbook of Mathematical Functions, Dover, New York, 1972.


2. K. E. Atkinson, An Introductionto Numerical Analysis 2nd Ed., Wiley, New York, 1989.
3. J. P. Boyd, Chebyshev& Fourier Spectral Methods, Springer-Verlag,Berlin, 1989.
4. P. J. Davis, On the numericalintegrationof periodic analytic functions, In: On numerical approximation
(ed. R. E. Langer). Proceedings of a Symposium, Madison, April 21-23, 1958.
5. J. D. Donaldson and D. Elliott, A unified approachto quadraturerules with asymptotic estimates of their
remainders,SIAMJ. Numer Anal. 9 (1972) 573-602.
6. D. Elliott, Sigmoidal transformationsand the TrapezoidalRule, J. Austral. Math. Soc. B 40 (E) (1998)
77-137.
7. W. Gautschi,Numerical Analysis: An Introduction,Birkhauser,Boston, 1997.
8. E. T. Goodwin, On the evaluation of integrals of the form f0 exp(-x2) f (x) dx, Proc. Cambridge
Philos. Soc. 45 (1949) 242-245.
9. R. Kress, Numerical Analysis, Springer,New York, 1998.
10. Y. L. Luke, The Special Functions and TheirApproximationsVol.II, Academic Press, New York, 1969.
11. Q. I. Rahman and G. Schmeisser, Characterizationof the speed of convergence of the trapezoidalrule,
Numer.Math. 57 (1990) 123-138.
12. F.Stenger,Numerical MethodsBased on Sinc and Analytic Functions, Springer-Verlag,New York, 1993.
13. J. Stewart, Calculus: Early Transcendentals3rd Ed., Brooks/Cole, Pacific Grove, 1995.
14. L. N. Trefethen,Spectral Methods in Matlab, SIAM, Philadelphia,2000.
15. J. A. C. Weideman,Computationof the complex errorfunction, SIAMJ. Numer.Anal. 31 (1994) 1497-
1518. Erratumpublished in SIAMJ. Numer.Anal. 32 (1995) 330-33 1.
16. J. Wimp, Computationwith RecurrenceRelations, Pitman, Boston, 1984.

ANDRE WEIDEMAN spent the 1980s at the University of the Free State in Bloemfontein, South Africa,
where he earned a Ph.D. in Applied Mathematics and also landed his first teaching position. The 1990s were
spent at Oregon State University in Corvallis, Oregon, where he rose to the rank of Associate Professor in the
MathematicsDepartment.In the 2000s he finds himself back in South Africa, as Professor in the Department
of Applied Mathematics,University of Stellenbosch. In his free time he likes to enjoy good food and music
with his wife Marf, play chess and other board games with their children (Hendrik,Nicolaas, Rina-MarO,or
bike in the beautiful JonkershoekValley just outside their home in Stellenbosch.
Departmentof Applied Mathematics, Universityof Stellenbosch, Stellenbosch 7600, SouthAfrica
weideman@dip.sun.ac.zaor weideman@na-net.ornl.gov

366 THE MATHEMATICAL ASSOCIATION OF AMERICA [Monthly109

This content downloaded from 193.255.248.150 on Sat, 20 Dec 2014 04:13:45 AM


All use subject to JSTOR Terms and Conditions

You might also like