You are on page 1of 16

APM2613/LN06/3/2022

Tutorial letter LN06/3/2022

APM2613

Semesters 1 and 2

Department of Mathematical Sciences

This tutorial letter contains important information:

• Lesson 6 - Numerical Differentiation and Integration


Additional notes to supplement prescribed content in Chap-
ter 4 of the textbook.

• Please read this information along with this chapter to get


highlights of concepts discussed in these sections.

BARCODE

university
Define tomorrow. of south africa
1 Lesson 6: Numerical Differentiation and Integration
1.1 Objectives
The objectives of this chapter/lesson is to introduce numerical methods for approximating derivatives and
integrals. in these notes we will

• Highlight the various methods of numerical differentiation

• Highlight the link between methods in this topic and those for interpolation;

• Highlight the nature of the three-point and five-point formulas for approximating the derivative of a
function f (x) at a specific point x0 ;

• Highlight some of the methods for approximating definite integrals for a function represented by tab-
ulated points;

• Highlight how the error in using such methods is estimated.

1.2 Learning Outcomes


At the end of this lesson you should be able to

1. To use the forward, backward and central difference methods to approximate the derivative, f ′ (x0 );

2. To use extrapolation to approximate the derivative, f ′ (x0 );

3. To use the basic interpolating polynomials to formulate the numerical methods to approximate the
integral of a function on a specific interval;

4. To use the following basic numerical methods of integration, called Newton-Cotes formulas:

• Trapezoidal rule
1
• Simpson’s rule or Simpson’s 3
rule
3
• Simpson’s 8
rule

5. To approximate the error in using the above formulas;

6. To use the composite form of the above Newton-Cotes formulae to find better approximations of a
given interval;

7. To formulate the Gaussian quadrature formula for various degree polynomials, leading to the different
sets of parameters;

8. To use Gaussian quadrature formula with different parameter sets to approximate a given integral.

9. To compare numerical results with analytical values of the given integral if the function is given.

10. To extend the basic methods of numerical integration to functions of two variables.

2
APM2613/LN06/3/2022

1.3 Introduction
In previous discussions of functional approximation - interpolation and least squares approximation - we
have seen how polynomials in particular have been used in the approximation of a function represented by
data points (xi , f (xi )) : i = 0, 1, 2, . . . , n. We continue to exploit the admirable properties of polynomial
with regard to differentiation and integration of functions to develop methods for approximating derivatives
and integrals. As it will be observed, the methods developed make use of the interpolation polynomials to
approximate the function to be differentiated or integrated.

The history of the methods goes back 300 years ago to famous names as Newton, Gauss and Lagrange, who
have featured in numerical methods discussed in other contexts of approximation.

1.4 Numerical Differentiation


The foundation of numerical differentiation is the very basic definition of the derivative of a function, which
is based on the difference quotient
f (x + h) − f (x)
h
which is an approximation of the change in the function between two neighbouring points (x, f (x)) and
(x + h, f (x + h)). The derivative emerges as the limit of this quotient as h → 0, as

f (x + h) − f (x)
f ′ (x) = lim
h→0 h
We can already see how this quotient relates to the notion of the secant line and the tangent line that have
been used in previous methods of approximation. Following this definition, much has been discussed about
the derivatives of known functions by calculus methods, and rules are available to apply in such cases. How-
ever, if a function is known only through experimental data displayed in a table of coordinates (x, f (x)), such
analytical rules cannot be applied directly, but through values of approximate functions such as interpolation
polynomials previously discussed.

The above quotient already looks familiar from the difference methods associated with interpolation poly-
nomials approximation. Prior to that, a similar quotient was encoountered in the Mean-value theorem when
analysing a function f (x) over an interval [a, b]:

f (b) − f (a)
, a < ξ < b.
b−a
We saw in the difference methods for interpolation that there are different ways of computing the difference
of f (x) between two neighbouring points:

(i) Forward-difference: f (x + h) − f (x);

(ii) Backward-difference: f (x) − f (x − h), h < 0;

(iii) Central-difference: f (x + h) − f (x − h)

In the current context, the derivative f ′ (x) of a function at a point x can be approximated in terms of its
neighbouring points using these differences as

3
f (x + h) − f (x)
f ′ (x) ≈ , (forward-difference)
h
f (x) − f (x − h)
f ′ (x) ≈ , (backward-difference)
h
f (x + h) − f (x − h)
f ′ (x) ≈ , (central-difference)
2h
for small values of h. As a specific point x0 , f (x0 ) is obtained by replacing x with x0 in the above formulas.
The textbook presents formulas for approximating the derivative f ′ (x0 ) of a tabulated function f (x) at a node
x0 . Note that x0 in this case is used to denote one of the tabulated nodes in a different context than the usual
left end-point x0 in the general node representation x0 , x1 , x2 , . . . , xn . In this context, x0 , is a point of focus
where the value of the derivative is desired. this point can be any of the tabulated points, not necessarily the
endpoint of the interval [x0 , xn ].

The formulas are based on the Lagrange interpolating polynomial. Starting with the usual Lagrange form of
the interpolating polynomial approximation f (x), together with the error term, the equation is differentiated
to get the derivative f ′ (x) in terms of the derivative of the Lagrange coefficients L′k (x) and the tabulated
values f (xk ). This is equation (4.2) on p174.

Recalling that the coefficient Lk (x) of an n-th degree Lagrange polynomial is explicitly written as

(x − x0 )(x − x1 ) . . . (x − xk−1 )(x − xk+1 ) . . . (x − xn )


Lk (x) =
(xk − x0 )(xk − x1 ) . . . (xk − xk−1 )(xk − xk+1 ) . . . (xk − xn )

the derivatives of Lk (x) will be based on the explicit form. The number of factors depend on the number of
points used and the degree of the approximating polynomial. Taking the first few terms of the equation to
approximate f ′ (x) leads to equation (4.3) which involves three points, x0 , x1 , and x2 at a time. Hence the
name three-point formulas.

NOTE:
• the derivative is based on the assumption that the data nodes are equally spaced by h; so that

• starting with any of the nodes and call it x0 , the other nodes can be written in terms of this node as
x0 +kh; thus for 3 successive nodes x0 , x1 , x2 the denotion x+1 = x0 +h, x1 = x0 +2h, x2 = x0 +2h
is used.
Hence letting some node xj = x0 , the formula of the derivative f ′ (xj ) and at the neighbouring nodes can be
written in terms of x0 and h.
This yields 3 three-point formulas, two of which are prominent and called the Three-point Endpoint-Formula
(equation (4.4)) and the Three-point Midpoint Formula (equation (4.5)).

Note also the emphasis of ’Endpoint’and ’Midpoint’ in these formulas. This is the main distinction between
these formulas:

• the ’Endpoint’ formula involves x0 used as the left-endpoint of the set x0 , x1 , x2 ;

• the ’Midpoint’ formula uses x0 as a midpoint of x − h and x + h;

4
APM2613/LN06/3/2022

• the sign of h depends on whether xi is to the left or right of xj = x0 .

By similar arguments, the five-point formulas are derived, one of which is given.

For the second derivative, only the ’Midpoint’ formula is presented for the three-point case.

Another difference formula that has been used in interpolation in the divided-difference formula. this turns
out to be a powerful way to get derivatives numerically. In this context, to get the derivative f ′ (x) at the point
x within an interval where the function is given as data points (xi , f (xi )), for which a divided-difference
interpolating polynomial can be used to approximate the functional value f (x), the interpolating polynomial
can be used in the place of the function to approximate the derivative f ′ (x).

1.4.1 A note on Error


The error in using these formulas in the one involving f ( d) where d (the order of the derivative) varies for
different formulas and ξ is some point in the interval containing x0 (as an endpoint or midpoint).

The order (or magnitude) of the error is expressed in terms of the power of h in the error term; i.e. if hk
appears in the error term, the error is of order O(hk ). This implies a dependence of the error on the size of h,
noting that if |h| < 1, then higher powers of h get smaller. So the higher the power k of h in the error term
associated with a formula (this is different from round-off error), the smaller the error resulting from the use
of that formula.

1.5 Numerical Integration


Numerical quadrature is the core method used in the discussion of approximating a definite integral of a
function that has no explicit antiderivative or whose antiderivative is not easy to obtain. Generally, the
approximation of the definite integral by this type of methods is
Z b n
X
f (x) dx ≈ f (xi )
a i=0

Rb
Recall that the definite integral a
f (x) dx is geometrically interpreted as the area under the curve f (x) be-
tween x = a and x = b.

The methods presented under numerical integration are developed from the Lagrange interpolating polyno-
mial (as it has been with differentiation). In this approach, the general numerical quadrature approximation
Z b n
X
f (x) dx ≈ ai f (xi )
a i=0
Xn Z b
= f (xi ) Li (x) dx, i = 0, 1, 2, . . . , n
i=0 a

from which it is deduced that the coefficients of the quadrature expression have the form
Z b
ai = Li (x) dx.
a

5
So, the main task int he formulation is the evaluation of these integrals.

In terms of the associated degree Lagrange polynomial,

• first degree Lagrange polynomial leads to the Trapezoidal Rule;

• second degree Lagrange polynomial leads to Simpson’s Rule;

• etc.

1.5.1 The Trapezoidal Rule


The derivation of this method presented in the textbook (p192) is straight forward, and it ends with the
formula Z b
h h3
f (x) dx = [f (x0 ) + f (x1 )] − f ′′ (ξ)
a 2 12
where x0 = a, x1 = b and h = b − a.

The interpretation of associated with the Trapezoidal Rule is that it approximates the area under the curve of
f (x) inthe interval [a, b] as the area of the trapezium obtained from drawing the secant joining (a, f (a)) and
(b, f (b)) (see Figure 4.3). The normal formula for computing the area of a trapezium is applied, taking two
parallel sides to be the lines x = a and x = b and the corresponding lengths are respectively f (a) and f (b).

The error associated with the Trapezoidal Rule is O(h3 ).

1.5.2 Simpson’s Rule/s


1
Two of Simpson’s formulas are of interest: Simpson’s Rule (also called Simpson’s 3
Rule) and Simpson’s
3/8 rule.

Simpson’s Rule

A second degree polynomial is a quadratic polynomial represented graphically by a parabola.Since the poly-
nomial used is an interpolation polynomial, this parabola passes through 3 equally spaced points on the graph
of f (x) (see Figure 4.4), with x0 = a, x1 = a + h, and x2 = a + 2h. So in this case h = b−a
2
.

Observe that some of the area in [a, b] under the curve f (x) is above and other part of the area is below the
parabola.

Although the original intent is to use a second degree Lagrange polynomial in the approximation of f (x), a
direct formulation is bypassed by using a Taylor polynomial about x1 , a mid-point of [x0 , x0 +2h] (see p194).

Take note that the derivatives involved in the Taylor expansion are eventually replaced by numerical ap-
proximations using numerical differentiation discussed in the section immediately before this one. the final
formula for Simpson’s Rule for approximating the definite integral is stated as
Z b Z x2
h
f (x) dx = f (x) dx ≈ [f (x0 ) + 4f (x1 ) + f (x2 )]
a x0 3

6
APM2613/LN06/3/2022

Note that Simpson’s Rule is based on 3 node points partitioning the interval [a, b] into 2 subintervals (or area
panels).

Simpson’s 3/8 Rule is discussed below under the subsection, Newton Cotes Formulas.

1.5.3 Newton-Cotes Formulas


The so called Newton-Cotes formulas are a generalisation of the formulas just discussed by taking the inter-
val [a, b] where the integral is computed and dividing it into n subintervals of equal length h = b−a n
(n =
1, 2, . . . ) for different formulas. n = 1 and n = 2 lead to the Trapezoidal Rule and Simpson’s Rule, respec-
tively. By sub-dividing the interval [a, b], a polynomial of degree n that agrees with f (x) at the nodal points
is used to approximate the definite integral.

Two classes of Newton-Cotes Formulas are presented, closed type (x = a and x = b included as nodes)
and open type (x = a and x = b excluded from the nodes). Depending on the choice of n, the number of
sub-intervals, different formulas have been developed. Of particular interest is the case of n = 3 which leads
to the so called Simpson’s 83 -th Rule:
x3
3h5 (6)
Z
3h
f (x) dx = [f (x0 ) + 3f (x1 ) + 3f (x2 ) + f (x3 )] − f (ξ), x0 < ξ < x3 ,
x0 8 80

notably based on 4 nodes forming 3 sub-intervals.


The common closed Newton-Cotes formulas are summarised on p197, including the formula corresponding
to n = 4, equation (4.28).

While for the closed Newton-Cotes formulas, h = b−a n


b−a
, for the open Newton-Cotes formulas, h = n+2 , and
x0 = a + h, xn = b − h, respectively labeled x−1 and xn+1 . Applying the Lagrange-based polynomials,
leads to several open-Cotes formulas for n = 0, 1, 2, 3 (equations (4.29)-4.32)

1.5.4 Improving Accuracy of the Approximations


Judging from the order of the error terms, Simpson’s formulas are better approximations than the Trapezoidal
Rule because |h5 | < |h3 | in the error terms. According to Definition 4.1, because the Trapezoidal Rule is a
linear polynomial approximation it computes exactly the area under a line; i.e. a linear function. Simpson’s
Rules on the other hand compute a quadratic and cubic functions exactly. Hence, by the same definition,
Simpson’s rule could be a better approximation than Trapezoidal rule based on the degree of the polynomials
used.

1.6 Composite Formulas for Integration


Improving accuracy by using higher degree polynomial approximations is cumbersome and prone to higher
computational
Rb error. Instead of using higher degree interpolation polynomials to approximate the definite
integral a f (x) dx, composite formulas use the lower degree polynomials on each subinterval, or groups of
a few of them to approximate the integral. In particular, the Trapezoidal Rule and Simpson’s Rules are used
on adjacent intervals that cover the whole interval [a, b] and then added up.

7
1.6.1 Composite Trapezoidal Rule
The Composite Trapezoidal Rule is not discussed in the textbook, but it is easy to derive and apply, and so
we discuss it below.

This numerical technique assumes that the values of y = f (x) are known for a sequence of equally spaced
values of x, a ≤ x ≤ b, We let
(a) xk , k = 0, 1, 2, . . . , n, denote the values of x (the nodes), with x0 = a, xk = x0 +kh, and xn = x0 +nh,
h being the stepsize h = b−a n
.
(b) fk = f (xk ), k = 0, 1, 2, . . . , n, denote the corresponding functional values.
The procedure is based on joining consecutive pair of points (xk , f (xk )) and (xk+1 , f (xk+1 )), k = 0, 1, 2, . . . , (n−
1) with straight line segments (secants) whose equation is given by
y − fk fk+1 − fk
= (x − xk ) (k-th interval), k = 0, 1, 2, . . . , (n − 1).
x − xk xk+1 − xk
Note here that the right-endpoint of each intermediate sub-interval coincides with the left-endpoint of the
next sub-interval.

The last equation can be written as


fk+1 − fk
y = fk + (x − xk ).
xk+1 − xk
If on each subinterval [xk , fk=1 ], f (x) is approximated by the corresponding line segment, then
Z xk+1 Z xk+1
fk+1 − fk
f (x) dx = fk + (x − xk ) dx
xk xk xk+1 − xk
x
fk+1 − fk (x − xk )2 k+1

= fk x +
xk+1 − xk 2 xk
1
= (xk+1 − xk )(fk + fk+1 ).
2
using h = xk+1 − xk , the integral becomes
Z xk+1
h
f (x) dx = (fk + fk+1 ). (1)
xk 2
Adding up all such integrals for k = 0, 1, 2, . . . , n we obtain the Composite Trapezoidal formula
Z b Z x1 Z x2 Z xn
f (x) dx = f (x) dx + f (x) dx + · · · + f (x) dx
a x0 x1 xn−1
h h h
≈ [f0 + f1 ] + [f1 + f2 ] + · · · + [fn−1 + fn ]
2 2 2
h
= [f0 + 2f1 + 2f2 + · · · + 2fn−1 + fn ] (2)
2
with an error of
b − a 2 ′′
e=− h f (µ), a<µ<b
12

8
APM2613/LN06/3/2022

The compact form of the Composite Trapezoidal Rule is (see p205)


Z b
h b − a 2 ′′
f (x) dx = [f0 + 2f1 + 2f2 + · · · + 2fn−1 + fn ] − h f (µ), a<µ<b (3)
a 2 12
Note that the total error in the integral can be approximated if f (x) is known. If |f ′′ (x) ≤ M for all x in
[a, b], then
h3
|Ek | ≤ M, M = |f ′′ (ξ), ξ ∈ [a, b].
12
Summing this error over n trapezoids, the maximum error in the integral is

h3 h2 h2
|E| ≤ n M = nh M = (b − a) M.
12 12 12
This is the truncation error bound for the method.

Example R4
Using Example 1 on p202, to approximate 0 ex dx by the Composite Trapezoidal Rule with h = 1 we have
Z 4 Z 1 Z 2 Z 3 Z 4
x x x x
e dx = e dx + e dx + e dx + ex dx
0 0 1 2 3
h
≈ [f0 + 2f1 + 2f2 + 2f3 + f4 ]
2
1 0
= [e + 2e1 + 2e2 + 2e3 + e4 ]
2
1
= (115.9839) = 57.99195
2

1.7 Composite Simpson’s Rule


Only the Simpson’s 13 Rule is discussed in the textbook. As alluded to before, the parabolas so designed
for this technique have to go through three points at a time (for each pair of panels). Let each parabola be
uniquely defined by an equation of the form

y = αx2 + βx + γ

or any other equivalent form. It is hoped that the area under a parabola is easier to find than the area under
the curve f (x) in a particular interval [xk , xk+1 ] and that the two areas are approximately equal.

There are various ways to express the parabolas and given below is one of the possible ways that does not
allude to Legendre polynomials which are a topic that we have not yet discussed in our functional approxi-
mation methods. The principle in using quadratic functions is, however, the same in all the approaches.

In the Trapezoidal rule, the area between any two adjacent points would be approximated by the equation
h
Ak = (f (xk ) + f (xk+1 ),
2
which can be written as
Ak = P f (xk ) + Qf (xk+1 ),

9
h
where P = Q = 2
and h is the width of the trapezoid.

Here we seek an equation of similar form but involving three points xk−1 , xk and xk+1 :

Ak = P f (xk−1 ) + Qf (xk ) + Rf (xk+1 ), k = 1, 2, . . . , n − 1. (4)

Simpson’s Rule should give exact answers for any f (x) which is either constant, a straight line, or a parabola.
That is, Simpson’s Rule should give exact answers for
Z h
I1 = 1 dx = x]h−h = 2h,
−h
h h
x2
Z
I2 = x dx = = 0,
−h 2 −h
Z h h
2 x3 2h3
I3 = x dx = = ,
−h 3 −h 3

which represent the three monomials y = 1, y = x, and y = x2 .


To obtain the exact area from an equation of the form (4) we use in each case the replacement xk−1 =
−h, xk = 0, xk+1 = h, so that the three integrals are

I1 = P · 1 + Q · 1 + R · 1 = 2h
I2 = P (−h) + Q(0) + R(h) = −P h + Rh = 0
2h3
I3 = P (−h)2 + Q(0) + R(h2 ) = ph2 + rh2 = .
3
Hence the three equations to be solved for P, Q and R:

(1) I1 = P + Q + R = 2h
(2) I2 = −P h + Rh = 0
2h3
(3) I3 = P h2 + Rh2 = .
3
From (2), P = R and hence from (3) we obtain P = R = h3 .
finally, from (1)
h
P + Q + R = Q + 2 = 2h,
3
4
from which we obtain Q = 3 h. thus for Simpson’s method the equation for the area approximation (4) is

Ak = P f (xk−1 ) + Qf (xk ) + Rf (xk−1 )


h 4 h
= f (xk−1 ) + f (xk ) + f (xk+1 )
3 3 3
h
= [f (xk−1 ) + 4f (xk ) + f (xk+1 )].
3
From this synopsis we observe that the area of two strips, each of width h, is calculated at a time. This im-
plies the need for an even number of strips in the interval [a, b] or rather an odd number of intermediate points.

10
APM2613/LN06/3/2022

Therefore, summing these over the whole interval [a, b] yields the Composite Simpson’s Rule
Z b Z xn Z x2 Z x4 Z xn
f (x) dx = f (x) dx = f (x) dx + f (x) dx + · · · + f (x) dx
a x0 x0 x2 xn−2
h h
≈ [f (x0 ) + 4f (x1 ) + 2f (x2 )] + [f (x2 ) + 4f (x3 ) + 2f (x4 )] + . . .
3 3
h
+ [f (xn−2 ) + 4f (xn−1 ) + 2f (xn )]
3
h
= [f (x0 ) + 4f (x1 ) + 2f (x2 ) + 4f (x3 ) + · · · + 2f (xn−2 ) + 4f (xn−1 ) + f (xn )] (5)
3
Note the alternating coefficients of 4 and 2 in the expression of the Composite Simpson’s Rule.

1.7.1 Error in Simpson’s Rule


Consider the subintervals [xk−1 , xk ] and [xk , xk+1 ]. The error for this subintervals can be defined as

Ek = Ak − Ik ,

where Ak is the approximate area by Simpson’s Rule and Ik is the correct area found by integrating the
function f (x) from xk−1 to xk+1 . That is

h
Ak = [f (xk−1 ) + 4f (xk ) + f (xk+1 )]
Z3 xk+1
Ik = f (x) dx = F (xk+1 ) − F (xk−1 )
xk−1

Using exactly the same procedure as in Trapezoidal Rule, we use Taylor series to expand f (xk−1 ) and
f (xk+1 ) about xk and obtain

h2 h3 h4
f (xk−1 ) = f (xk ) − f ′ (xk )h + f ′′ (xk ) − f ′′′ (xk ) + f (iv) (xk ) + . . .
2! 3! 4!
and
h2 h3 h4
f (xk+1 ) = f (xk ) + f ′ (xk )h + f ′′ (xk ) + f ′′′ (xk ) + f (iv) (xk ) + . . .
2! 3! 4!
Substituting these into Ak yields

h3 h5
Ak = 2f (xk ) + 2f ′′ (xk ) + 2f (iv) (xk ) + ...
3! 3 · 4!
Similar expansions of F (xk−1 ) and F (xk+1 ) in Taylor series about xk , and using the fact that f (x) = F ′ (x),
and simplifying, we obtain

Ik = F (xk+1 ) − F (xk−1 )
h3 h5
= 2f (xk ) + 2f ′′ (xk ) + 2f (iv) + ...
3! 3 · 4!
h3 h5
= 2f (xk )h + 2f ′′ (xk ) + 2f (iv) + . . .
3! 5!

11
Finally, we have

Ek = Ak − Ik
h3 h5
 
′′ (iv)
= Ak = 2f (xk ) + 2f (xk ) + 2f (xk ) + ...
3! 3 · 4!
h3 5
 
′′ (iv) h
− 2f (xk )h + 2f (xk ) + 2f + ...
3! 5!
 5
h5

(iv) h
= 2f (xk ) − + O(h7 ).
3 · 4! 5!

If it is assumed that h is small, then

h5 h5
 
(iv)
Ek ≈ 2f (xk ) − . (6)
3 · 4! 5!
n
An error bound for the overall error from all the now 2
pairs of strips is,

n h5 nh h4 h4
|ES | ≤ M= M = (b − a) M, (7)
2 90 2 90 180
where
M = max |f (iv) (x)| : a ≤ x ≤ b


Hence the error truncation error of Simpson’s Rule is proportional to h4 and thus it decreases much faster as
more intervals are taken; i.e. as h gets smaller.

Note:

• The Composite Trapezoidal Rule can be used for any number of subintervals, but the Composite Simp-
son’s and midpoint Rules require an even number of subintervals since it use two subintervals in its
formula.
b−a
• The width of each subinterval is h = n
for all the formulas.

• Further, that using the composite formulas is not any more difficult that using the basic formulas. The
key thing is to understand the basic formulas and repeatedly apply them on consecutive subintervals,
ensuring that no gaps remain between the subintervals,

1.8 Quadrature Methods


Quadrature methods are adaptive in nature to cater for approximating integrals of functions with subinterval
variations in their values within small intervals. They are based on relaxing the requirement for equally
spaced nodes and are capable of predicting the amount of functional variation and adapting the step size
accordingly to reduce approximation error. This flexibility and capability makes the quadrature methods
popular for professional software use.

Two such quadrature methods are presented: Adaptive Quadrature Method and Gaussian Quadrature Method.

12
APM2613/LN06/3/2022

1.8.1 Adaptive Quadrature Method


The Adaptive Quadrature Method approximation of definite integral of f (x) on [a, b] makes use of basic
Simpson’s Rule, first in its original form (i.e. 2 nodes coinciding with the endpoints):
Z b
h h5
f (x) dx = [f (a) + 4f (a + h) + f (b)] − f (iv)(ξ), (8)
a 3 90
where h = b−a
2
, followed by refinements achieved by recursive application of the Composite Simpson’s Rule
with n = 4 nodes (see equations (4.36) to (4.37) in the textbook):
Z b
1 h5 (iv)
     
a+b a+b
f (x) dx = S a, +S ,b − f (ξ) , (9)
a 2 2 16 90
where S(·) are the Simpson’s Rule applied to the respective subintervals of [a, b]. Before a further subdi-
vision takes place, an accuracy test is performed to check if the error for individual subintervals meets the
required tolerance is made. The test is given in equation (4.38). The procedure is reapplied to those subin-
tervals where the tolerance is not met.

Note that if a further subdivision of a subinterval, say [ak , bk ], is done inthe process, then [a, b] in the above
Adaptive Quadrature formulas (8) and (9) are replaced with [ak , bk ].

Example 1 on p223 illustrates the procedure, particularly the accuracy test.


NOTE:
There seems to be an typo in the examole in the line before the last but one equation, beginning with
’The estimate for the error’. I think the expression should be S(a, (a + b)/2) + S((a + b)/2, b); i.e. the
division by 2 (/2)’ is missing.

1.8.2 Gaussian Quadrature


Gaussian Quadrature method is here derived using an alternative method as that used in deriving Simpson’s
Rule. The adaptive nature of Gaussian quadrature derives from the fact that the coefficients and nodes in the
approximation
Z b Xn
f (x) dx ≈ ci f (xi )
a i=1
are not prescribed, but rather calculated to minimise the expected error in the approximation. Hence they are
considered to be parameters. The textbook (p229) gives a good illustration of the relationship between the
desired nodes and two endpoints of a typical interval [a, b].

By letting c1 be at the point (x1 , f (x1 )) and (x2 , f (x2 )), a formula of the form
Ai = c1 f (x1 ) + c2 f (x2 )
is developed to determine the values of the parameters x1 , x2 , c1 and c2 . Similar to the derivation of Simpson’s
Rule, the method holds for the monomials y = 1, y = x, y = x2 , and y = x3 . An integration of these
monomials over [−1, 1] (to start with), yields
Z 1 Z 1
I1 = 1 dx = 2; I2 = x dx = 0
−1 −1
Z 1 Z 1
2 2
I3 = x dx = ; I4 = x3 dx = 0.
−1 3 −1

13
(If the actual limits of integration are different, they can be changed to −1 and 1) by a change of variable.)
Equating these true integrals Ii to the Ai s above leads to a set of four equations to be solved for the parame-
ters:

(1) I1 = c1 (1) + c2 (1) = 2


(2) I2 = c1 x1 + c2 x2 = 0
2
(3) I3 = c1 x21 + c2 x22 =
3
3 3
(4) I4 = c1 x1 + c2 x2 = 0

From (1) we have c1 + c2 = 2.


Now if c1 = c2 and x1 = −x2 , this would satisfy (2) and (4). So we choose c1 = c2 = 1 and x1 = −x2 , and
substitute in (3) to obtain
2
c1 x21 + c2 x22 = x21 + (−x1 )2 = ,
3
which yields the roots √
1 3
x1 = ± √ = ± = ±0.5773502692.
3 3
Hence the chioce of two point parameters x1 = 0.5773502692 and x2 = −.5773502692 (or vice versa) yield
the formula
Z 1
f (x) dx = c1 f (x1 ) + c2 f (x2 )
−1
= 1 · f (0.5773502692) + 1 · f (−0.5773502692)

Although the above discussion was based on two (end)points only (from which we derive two-point Gaussian
quadrature formula), the same procedure works for any number of unevenly spaced points along the curve
in the interval −1 to 1 and a suitable curve could be passed through these points; i.e. a parabola if there are
three points, a cubic for four points, etc.

Example
Given below is an example to illustrate how Gaussian quadrature is applied in the case of arbitrary integral
limits.
R3
In the integral 1 cosx x dx, f (x) = cosx x , a = 1, b = 3.To transform the integral limits from 1 to 3, to −1 to
1, the change of variable generally given on p233 as
2x − a − b
t=
b−a
which transforms the variable x to
1
x = [(b − a)t + a + b] = t + 2 → dx = dt
2
and the integral limits 1 and 3 to −1 and 1. Hence the tranformed integral becomes
Z 3 Z 1
cos x cos(t + 2)
dx = dt
1 x −1 t+2

14
APM2613/LN06/3/2022

which, for the two point Gaussian quadrature yields


Z 1 Z 3 Z 1
cos x cos(t + 2)
f (x) dx = dx = dt
−1 1 x −1 t+2
= c1 f (x1 ) + c2 f (x2 ) = 1 · f (0.5773502692 + 2) + 1 · f (−0.5773502692 + 2)
cos(0.5773502692 + 2) cos(−0.5773502692 + 2)
= 1· +1·
0.5773502692 + 2 −0.5773502692 + 2
= ...

If Gaussian quadrature method is extended to n points, the general equation for the area to be solved for the
weighting coefficients ci and roots (abscissas) xi is given by
Z 1 n
X
xk dx = ck xki , k = 0, 1, 2, . . . , n. (10)
−1 i=1

Solving this system for ci and xi leads to the transformation


Z b Z 1 n
X
f (x) dx = g(t) dt = c1 f (x1 ) + c2 f (x2 ) + · · · + cn f (xn ) = ci f (xi )
a −1 i=1

The derivation used in the textbook follows what Gauss has shown, that exactness for polynomials of degree
not exceeding 2n − 1 can be attained if and only if the values of x1 , x2 , . . . , xn are the zeros of the Legendre
polynomials Pn (x) given by
2n − 1 n−1
P0 (x) = 1, P1 (x) = x, . . . , Pn (x) = xPn−1 (x) − Pn−2 (x), n = 2, 3, . . . (11)
n n
As you may have figured out, the more points there are involved, the more cumbersome the computations
for solving the system of equations for the parameters. Fortunately, the values of ci and xi to be chosen for
respective number of points are available in standard tables such as Table 4.12 on p232.
e.g. for n = 4
Coefficients, ci Roots, xi
c1 = 0.3478548451 x1 = −0.8611363116
c2 = 0.6521451549 x2 = −0.3399810436
c3 = 0.6521451549 x3 = 0.3399810436
c4 = 0.3478548451 x4 = 0.8611363116
Note that c1 = c4 , c2 = c3 and −x1 = x4 , −x2 = x3 .

15
2 Useful Formulas
1. Trapezoidal rule on [a, b]:
h
Basic: I ≈ (f (a) + f (b)), h=b−a
2
Composite (n intervals):
Z b Z x1
h h
f (x) dx = f (x) dx ≈ (f (x0 )+2f (x1 )+2f (x2 )+· · ·+2f (xn−1 +f (xn )) = (f (a)+f (b)), h=
a x0 2 2

2. Simpson’s Rule:
Basic:
Z b Z x2
h h b−a
f (x) dx = f (x) dx ≈ (f (a)+4f (a+h)+f (b)) = (f (x0 )+4f (x0 +h)+f (x2 ), h=
a x0 3 3 2

Composite rule:

Z b Z xn
h
f (x) dx = f (x) dx ≈ (f (a) + 4f (a + h) + 2f (a2 h) + 4f (a + 3h) + · · · + 4f (b − h) + f (b))
a x0 3
h
= (f (a) + 4f (xa + h) + 2f (xa + 2h) + 4f (xa + 3h) + · · · + 4f (xb − h) +
3
3
Simpson’s 8
rule:
Basic:
Z b Z x3
3h
f (x) dx = f (x) dx ≈ (f (a) + 3f (a + h) + 3f (b − h) + f (b))
a x0 8
3h
= (f (x0 ) + 3f (x1 ) + 3f (x2 ) + f (x4 )),
8
b−a x3 − x0
h= =
3 3

16

You might also like