Transcript
Page 1: TRAPEZOIDAL METHOD: ERROR FORMULA

TRAPEZOIDAL METHOD: ERROR FORMULA

Theorem Assume f (x) twice continuously differentiable on theinterval [a, b]. Then

ETn (f ) :=

∫ b

af (x) dx − Tn(f ) = −h2 (b − a)

12f ′′ (cn)

for some cn in the interval [a, b].

Later we will say something about the proof of this result, as itleads to some other useful formulas for the error.

The above formula says that the error decreases in a manner thatis roughly proportional to h2. Thus doubling n (and halving h)should cause the error to decrease by a factor of approximately 4.This is what we observed with some past examples from thepreceding section.

Page 2: TRAPEZOIDAL METHOD: ERROR FORMULA

Example

Consider evaluating

I =

∫ 2

0

dx

1 + x2

using the trapezoidal method Tn(f ). Let us bound the error

ETn (f ) = −h2 (b − a)

12f ′′ (cn)

Here, b − a = 2. We bound |f ′′ (cn)| by max0≤x≤2 |f ′′(x)|.Calculate the derivatives:

f ′(x) =−2x

(1 + x2)2, f ′′(x) =

−2 + 6x2

(1 + x2)3, f ′′′(x) =

24 x(1− x2

)(1 + x2)4

For x ∈ (0, 2), f ′′′(x) = 0 only when x = 1. So

max0≤x≤2

∣∣f ′′(x)∣∣ = max

{∣∣f ′′(0)∣∣ , ∣∣f ′′(1)

∣∣ , ∣∣f ′′(2)∣∣} = 2

Therefore, ∣∣∣ETn (f )

∣∣∣ ≤ h2 (2)

12· 2 =

h2

3

Page 3: TRAPEZOIDAL METHOD: ERROR FORMULA

∣∣∣ETn (f )

∣∣∣ ≤ h2

3

How large should n be chosen in order to ensure that∣∣∣ETn (f )

∣∣∣ ≤ 5× 10−6 (1)

To ensure this, we choose h so small that

h2

3≤ 5× 10−6

This is equivalent to choosing h and n to satisfy

h ≤ .003873

n =2

h≥ 516.4

Thus n ≥ 517 will imply (1).

Page 4: TRAPEZOIDAL METHOD: ERROR FORMULA

DERIVING THE ERROR FORMULA

There are two stages in deriving the error:(1) Obtain the error formula for the case of a single subinterval(n = 1);(2) Use this to obtain the general error formula given earlier.

For the trapezoidal method with only a single subinterval, we have∫ α+h

αf (x) dx − h

2[f (α) + f (α + h)] = −h3

12f ′′(c)

for some c in the interval [α, α + h].

This error formula can be derived through an application of Taylor’stheorem or the Newton form of the linear interpolation error.

Page 5: TRAPEZOIDAL METHOD: ERROR FORMULA

The general trapezoidal rule Tn(f ) was obtained by applying thesimple trapezoidal rule to a subdivision of the original interval ofintegration. Recall the notation

h =b − a

n, xj = a + j h, j = 0, 1, ..., n

I (f ) =

∫ xn

x0

f (x) dx

=

∫ x1

x0

f (x) dx +

∫ x2

x1

f (x) dx + · · ·+∫ xn

xn−1

f (x) dx

Tn(f ) =h

2[f (x0) + f (x1)] +

h

2[f (x1) + f (x2)]

+ · · ·+ h

2[f (xn−1) + f (xn)]

Page 6: TRAPEZOIDAL METHOD: ERROR FORMULA

Then the error

ETn (f ) ≡

∫ b

af (x) dx − Tn(f )

can be analyzed by adding together the errors over the subintervals[x0, x1], [x1, x2], ..., [xn−1, xn]. Recall∫ α+h

αf (x) dx − h

2[f (α) + f (α + h)] = −h3

12f ′′(c)

Then on [xj−1, xj ],∫ xj

xj−1

f (x) dx − h

2[f (xj−1) + f (xj)] = −h3

12f ′′(γj)

with xj−1 ≤ γj ≤ xj . Combining these errors, we obtain

ETn (f ) = −h3

12f ′′(γ1)− · · · − h3

12f ′′(γn)

This formula can be further simplified, and we will do so in twoways.

Page 7: TRAPEZOIDAL METHOD: ERROR FORMULA

Rewrite this error as

ETn (f ) = −h3n

12

[f ′′(γ1) + · · ·+ f ′′(γn)

n

]Denote the quantity inside the brackets by ζn. This numbersatisfies

mina≤x≤b

f ′′(x) ≤ ζn ≤ maxa≤x≤b

f ′′(x)

Since f ′′(x) is a continuous function (by original assumption), wehave some number cn in [a, b] for which

f ′′(cn) = ζn

Recall also that hn = b − a. Then

ETn (f ) = −h3n

12

[f ′′(γ1) + · · ·+ f ′′(γn)

n

]= −h2 (b − a)

12f ′′ (cn)

This is the error formula given on the first slide.

Page 8: TRAPEZOIDAL METHOD: ERROR FORMULA

AN ERROR ESTIMATE

We now obtain a way to estimate the error ETn (f ). Return to the

formula

ETn (f ) = −h3

12f ′′(γ1)− · · · − h3

12f ′′(γn)

and rewrite it as

ETn (f ) = −h2

12

[f ′′(γ1)h + · · ·+ f ′′(γn)h

]The quantity

f ′′(γ1)h + · · ·+ f ′′(γn)h

is a Riemann sum for the integral∫ b

af ′′(x) dx = f ′(b)− f ′(a)

By this we mean

limn→∞

[f ′′(γ1)h + · · ·+ f ′′(γn)h

]=

∫ b

af ′′(x) dx

Page 9: TRAPEZOIDAL METHOD: ERROR FORMULA

Thusf ′′(γ1)h + · · ·+ f ′′(γn)h ≈ f ′(b)− f ′(a)

for larger values of n. Combining this with the earlier error formula

ETn (f ) = −h2

12

[f ′′(γ1)h + · · ·+ f ′′(γn)h

]we have

ETn (f ) ≈ −h2

12

[f ′(b)− f ′(a)

]≡ ET

n (f )

This is a computable estimate of the error in the numericalintegration. It is called an asymptotic error estimate.

Page 10: TRAPEZOIDAL METHOD: ERROR FORMULA

Example

Consider evaluating

I (f ) =

∫ π

0ex cos x dx = −eπ + 1

2.

= −12.0703463163896

In this case,

f ′(x) = ex (cos x − sin x) , f ′′(x) = −2ex sin x

max0≤x≤π

∣∣f ′′(x)∣∣ =

∣∣f ′′ (.75π)∣∣ = 14. 921

From

ETn (f ) = −h2 (b − a)

12f ′′ (cn)

we have the error bound∣∣∣ETn (f )

∣∣∣ ≤ h2π

12· 14.921 = 3.906h2 (2)

Also, we have the error estimate

ETn (f ) = −h2

12

[f ′(π)− f ′(0)

]=

h2

12(eπ + 1)

.= 2.012h2 (3)

Page 11: TRAPEZOIDAL METHOD: ERROR FORMULA

n Tn ETn Ratio Bound (2) ET

n

2 -17.38925933 5.319 9.638 4.9644 -13.33602285 1.266 4.20 2.409 1.2418 -12.38216243 3.118E−1 4.06 6.024E−1 3.103E−1

16 -12.14800410 7.766E−2 4.02 1.506E−1 7.757E−232 -12.08974212 1.940E−2 4.00 3.765E−2 1.939E−264 -12.07519410 4.848E−3 4.00 9.412E−3 4.848E−3

128 -12.07155818 1.212E−3 4.00 2.353E−3 1.212E−3256 -12.07064928 3.030E−4 4.00 5.822E−4 3.030E−4

In looking at the table, we see that the error ETn (f ) and the error

estimate ETn (f ) are quite close. Therefore

I (f )− Tn(f ) ≈ h2

12(eπ + 1)

I (f ) ≈ Tn(f ) +h2

12(eπ + 1)

This last formula is called the corrected trapezoidal rule, CTn(f ).

Page 12: TRAPEZOIDAL METHOD: ERROR FORMULA

The corrected trapezoidal rule is illustrated in the following table.

n I − Tn Ratio I − CTn Ratio

2 5.319 3.552E−14 1.266 4.20 2.474E−2 14.48 3.118E−1 4.06 1.583E−3 15.6

16 7.766E−2 4.02 9.949E−5 15.932 1.940E−2 4.00 6.227E−6 16.064 4.848E−3 4.00 3.893E−7 16.0

128 1.212E−3 4.00 2.433E−8 16.0256 3.030E−4 4.00 1.521E−9 16.0

Page 13: TRAPEZOIDAL METHOD: ERROR FORMULA

The corrected trapezoidal rule

In general,

I (f )− Tn(f ) ≈ −h2

12

[f ′(b)− f ′(a)

]I (f ) ≈ CTn(f ) := Tn(f )− h2

12

[f ′(b)− f ′(a)

]This is the corrected trapezoidal rule. It is easy to obtain from thetrapezoidal rule, and in most cases, it converges more rapidly thanthe trapezoidal rule.

Page 14: TRAPEZOIDAL METHOD: ERROR FORMULA

ERROR FORMULA FOR SIMPSON’S RULE

Recall the general Simpson’s rule∫ b

af (x) dx ≈ Sn(f ) :=

h

3[f (x0) + 4f (x1) + 2f (x2)

+ 4f (x3) + 2f (x4) + · · ·+ 2f (xn−2) + 4f (xn−1) + f (xn)]

For its error, we have

ESn (f ) ≡

∫ b

af (x) dx − Sn(f ) = −h4 (b − a)

180f (4)(cn)

where a ≤ cn ≤ b. For an asymptotic error estimate,∫ b

af (x) dx − Sn(f ) ≈ ES

n (f ) ≡ − h4

180

[f ′′′(b)− f ′′′(a)

]

Page 15: TRAPEZOIDAL METHOD: ERROR FORMULA

DISCUSSION

For Simpson’s error formula, both formulas assume that theintegrand f (x) has four continuous derivatives on the interval[a, b]. What happens when this is not valid? We return later tothis question.

Both formulas also say the error should decrease by a factor ofaround 16 when n is doubled.

Compare these results with those for the trapezoidal rule errorformulas:

ETn (f ) ≡

∫ b

af (x) dx − Tn(f ) = −h2 (b − a)

12f ′′ (cn)

ETn (f ) ≈ −h2

12

[f ′(b)− f ′(a)

]≡ ET

n (f )

Page 16: TRAPEZOIDAL METHOD: ERROR FORMULA

EXAMPLE

Consider evaluating

I =

∫ 2

0

dx

1 + x2

using Simpson’s rule Sn(f ). Let us bound the error.Begin by noting that

f (4)(x) = 245x4 − 10x2 + 1

(1 + x2)5

max0≤x≤1

∣∣∣f (4)(x)∣∣∣ = f (4)(0) = 24

Then

ESn (f ) = −h4 (b − a)

180f (4)(cn)∣∣∣ES

n (f )∣∣∣ ≤ h4 · 2

180· 24 =

4h4

15

Page 17: TRAPEZOIDAL METHOD: ERROR FORMULA

How large should n be chosen in order to ensure that∣∣∣ESn (f )

∣∣∣ ≤ 5× 10−6

This is true if

4h4

15≤ 5× 10−6

h ≤ .0658

n ≥ 30.39

Therefore, choosing n ≥ 32 will give the desired error bound.Compare this with the earlier trapezoidal example in whichn ≥ 517 was needed.

For the asymptotic error estimate, we have

f ′′′(x) = −24xx2 − 1

(1 + x2)4

ESn (f ) ≡ − h4

180

[f ′′′(2)− f ′′′(0)

]=

h4

180· 144

625=

4

3125h4

Page 18: TRAPEZOIDAL METHOD: ERROR FORMULA

INTEGRATING√x

Consider the numerical approximation of∫ 1

0

√x dx =

2

3

In the following table, we give the errors when using both thetrapezoidal and Simpson rules.

n ETn Ratio ES

n Ratio

2 6.311E − 2 2.860E − 24 2.338E − 2 2.70 1.012E − 2 2.828 8.536E − 3 2.74 3.587E − 3 2.83

16 3.085E − 3 2.77 1.268E − 3 2.8332 1.108E − 3 2.78 4.485E − 4 2.8364 3.959E − 4 2.80 1.586E − 4 2.83

128 1.410E − 4 2.81 5.606E − 5 2.83

The rate of convergence is slower because the function f (x) =√x

is not sufficiently differentiable on [0, 1]. Both methods convergewith a rate proportional to h1.5.

Page 19: TRAPEZOIDAL METHOD: ERROR FORMULA

ASYMPTOTIC ERROR FORMULAS

For a numerical integration formula,∫ b

af (x) dx ≈

n∑j=0

wj f (xj)

let En(f ) denote its error,

En(f ) =

∫ b

af (x) dx −

n∑j=0

wj f (xj)

We say another formula En(f ) is an asymptotic error formula thisnumerical integration if it satisfies

limn→∞

En(f )

En(f )= 1 or lim

n→∞

En(f )− En(f )

En(f )= 0

These conditions say that En(f ) looks increasingly like En(f ) as nincreases, and thus En(f ) ≈ En(f ).

Page 20: TRAPEZOIDAL METHOD: ERROR FORMULA

Examples

For the trapezoidal rule, assuming f (x) has two continuousderivatives on [a, b],

ETn (f ) ≈ ET

n (f ) ≡ −h2

12

[f ′(b)− f ′(a)

]For Simpson’s rule, assuming f (x) has four continuous derivativeson [a, b],

ESn (f ) ≈ ES

n (f ) ≡ − h4

180

[f ′′′(b)− f ′′′(a)

]

Page 21: TRAPEZOIDAL METHOD: ERROR FORMULA

Example (cont.)

Note that both of these formulas can be written in an equivalentform as

En(f ) =c

np

for appropriate constant c and exponent p. With the trapezoidalrule, p = 2 and

c = −(b − a)2

12

[f ′(b)− f ′(a)

]and for Simpson’s rule, p = 4 and

c = −(b − a)4

180

[f ′′′(b)− f ′′′(a)

]

Page 22: TRAPEZOIDAL METHOD: ERROR FORMULA

The formulaEn(f ) =

c

np(4)

occurs for many other numerical integration formulas that we havenot yet defined or studied. In addition, if we use the trapezoidal orSimpson rules with an integrand f (x) which is not sufficientlydifferentiable, then (4) may hold with a p less than the ideal.Example. Consider

I =

∫ 1

0xβf (x) dx

in which 0 < β < 1 and f (x) is a smooth function with f (0) 6= 0 .Then the convergence of the trapezoidal rule can be shown to havean asymptotic error formula

En ≈ En =c

nβ+1(5)

for some constant c dependent on β. A similar result holds forSimpson’s rule, with 0 < β < 3, β not an integer. We can actuallyspecify a formula for c ; but the formula is often less importantthan knowing that (4) is valid for some c.

Page 23: TRAPEZOIDAL METHOD: ERROR FORMULA

APPLICATION OF ASYMPTOTIC ERROR FORMULAS

Assume we know that an asymptotic error formula

I − In ≈c

np

is valid for some numerical integration rule denoted by In. Initially,assume we know the exponent p. Then imagine calculating both Inand I2n. With I2n, we have

I − I2n ≈c

2pnp

This leads to

I − In ≈ 2p (I − I2n)

I ≈ 2pI2n − In2p − 1

= I2n +I2n − In2p − 1

The formula

I ≈ I2n +I2n − In2p − 1

(6)

is called Richardson’s extrapolation formula.

Page 24: TRAPEZOIDAL METHOD: ERROR FORMULA

Examples

With the trapezoidal rule and with the integrand f (x) having twocontinuous derivatives, p = 2 and

I ≈ T2n +1

3(T2n − Tn)

With Simpson’s rule and with the integrand f (x) having fourcontinuous derivatives, p = 4 and

I ≈ S2n +1

15(S2n − Sn)

Page 25: TRAPEZOIDAL METHOD: ERROR FORMULA

Richardson’s error estimate

We can also use the formula (4)

En(f ) =c

np

to obtain error estimation formulas:

I − I2n ≈I2n − In2p − 1

(7)

This is called Richardson’s error estimate. For example, with thetrapezoidal rule,

I − T2n ≈1

3(T2n − Tn)

and for Simpson’s rule,

I − S2n ≈1

15(S2n − Sn)

Page 26: TRAPEZOIDAL METHOD: ERROR FORMULA

AITKEN EXTRAPOLATION

In this case, we again assume

I − In ≈c

np

But in contrast to previously, we do not know either c or p.Imagine computing In, I2n, and I4n. Then

I − In ≈c

np, I − I2n ≈

c

2pnp, I − I4n ≈

c

4pnp

We can directly try to estimate I . Dividing

I − InI − I2n

≈ 2p ≈ I − I2nI − I4n

Solving for I , we obtain

(I − I2n)2 ≈ (I − In) (I − I4n)

I (In + I4n − 2I2n) ≈ InI4n − I 22n

I ≈ InI4n − I 22nIn + I4n − 2I2n

Page 27: TRAPEZOIDAL METHOD: ERROR FORMULA

This can be improved computationally, to avoid loss of significanceerrors.

I ≈ I4n +

(InI4n − I 22n

In + I4n − 2I2n− I4n

)= I4n −

(I4n − I2n)2

(I4n − I2n)− (I2n − In)

This is called Aitken’s extrapolation formula.

To estimate p, we use

I2n − InI4n − I2n

≈ 2p

To see this, write

I2n − InI4n − I2n

=(I − In)− (I − I2n)

(I − I2n)− (I − I4n)

Then substitute from the following and simplify:

I − In ≈c

np, I − I2n ≈

c

2pnp, I − I4n ≈

c

4pnp

Page 28: TRAPEZOIDAL METHOD: ERROR FORMULA

Example

Consider the following table of numerical integrals.

n In In − In/2 Ratio

2 .284517796864 .28559254576 1.075E − 38 .28570248748 1.099E − 4 9.78

16 .28571317731 1.069E − 5 10.2832 .28571418363 1.006E − 6 10.6264 .28571427643 9.280E − 8 10.84

What is its order of convergence? It appears

2p.

= 10.84, p.

= log2 10.84 = 3.44

We could now combine this with Richardson’s error formula:

I − In ≈1

2p − 1

(In − In/2

)For example,

I − I64 ≈1

9.84[9.280E − 8] = 9.43E − 9

Page 29: TRAPEZOIDAL METHOD: ERROR FORMULA

PERIODIC FUNCTIONS

A function f (x) is periodic if the following condition is satisfied.There is a smallest real number τ > 0 for which

f (x + τ) = f (x), −∞ < x <∞ (8)

The number τ is called the period of the function f (x). Theconstant function f (x) ≡ 1 is also considered periodic, but itsatisfies this condition with any τ > 0. Basically, a periodicfunction is one which repeats itself over intervals of length τ .

The condition (8) implies

f (m)(x + τ) = f (m)(x), −∞ < x <∞ (9)

for the mth-derivative of f (x), provided there is such a derivative.Thus the derivatives are also periodic.

Periodic functions occur very frequently in applications ofmathematics, reflecting the periodicity of many phenomena in thephysical world.

Page 30: TRAPEZOIDAL METHOD: ERROR FORMULA

PERIODIC INTEGRANDS

Consider the special class of integrals

I (f ) =

∫ b

af (x) dx

in which f (x) is periodic, with b − a an integer multiple of theperiod τ for f (x). In this case, the performance of the trapezoidalrule and other numerical integration rules is much better than thatpredicted by earlier error formulas. To hint at this improvedperformance, recall∫ b

af (x) dx − Tn(f ) ≈ En(f ) ≡ −h2

12

[f ′(b)− f ′(a)

]With our assumption on the periodicity of f (x), we have

f (a) = f (b), f ′(a) = f ′(b)

Therefore, En(f ) = 0 and we should expect improved performancein the convergence behaviour of the trapezoidal sums Tn(f ).

Page 31: TRAPEZOIDAL METHOD: ERROR FORMULA

If in addition to being periodic on [a, b], the integrand f (x) alsohas m continous derivatives, then it can be shown that

I (f )− Tn(f ) =cmnm

+ smaller terms

By “smaller terms”, we mean terms which decrease to zero morerapidly than n−m.

Thus if f (x) is periodic with b − a an integer multiple of theperiod τ for f (x), and if f (x) is infinitely differentiable, then theerror I − Tn decreases to zero more rapidly than n−m for anym > 0. For periodic integrands, the trapezoidal rule is an optimalnumerical integration method.

Page 32: TRAPEZOIDAL METHOD: ERROR FORMULA

Example

Consider evaluating

I =

∫ 2π

0

sin x

1 + esin xdx

Using the trapezoidal rule, we have the results in the followingtable. In this case, the formulas based on Richardson extrapolationare no longer valid.

n Tn Tn − T 12n

2 0.04 −0.72589193317292 −7.259E − 18 −0.74006131211583 −1.417E − 2

16 −0.74006942337672 −8.111E − 632 −0.74006942337946 −2.746E − 1264 −0.74006942337946 0.0


Top Related