Chapter 4
Chapter 4
CCMA4003 Calculus
Chapter 4
Numerical Methods
In scientific and engineering work, a frequently occurring problem is to find the roots of
an equation of the form f(x) = 0. It is known that if f(x) is quadratic or cubic then algebraic methods
for exact solutions are available. However, if f(x) is a polynomial of degree higher than three,
then algebraic methods are not easily available.
In this section, we will find the approximate real roots by numerical methods, namely,
method of fixed point iteration and Newton’s method.
Before we apply any numerical method to find the approximate root of an equation f(x) = 0,
we first show that there is a unique real root in an interval [a, b] by the following theorem.
4-1
A. Method of Fixed Point Iteration
Most numerical methods are iterative in nature and start from one or two initial guesses to the root.
They produce a sequence x0, x1, x2,…, xn,… which will presumably converges to the desired root.
Theorem If g(x) is continuous on [a, b] and the sequence {xn} converges to a point m in (a, b),
then m .
Remark:
∴ f(m) = 0
Since there is only one root in [a, b], we have m .
4-2
Theorem Contraction Mapping Theorem
Let g(x) and g’(x) be continuous on [a, b], assume g(a) a and g(b) b , such that
(1) a g(x) b for all x in [a, b] and
(2) there exists a positive constant K such that max g' ( x ) = K < 1
a x b
Remark:
A secant line of a curve is a line that (locally) intersects two points on the curve.
3. x n g(x n 1 ) g()
g '(c)(x n 1 ) (by Mean Value Theorem)
K x n 1
K K x n 2
K 2 x n 2
Kn x0
K n (b a) 0 as n
4-3
Example 1
(a) Show that the equation x3 2x 5 0 has a unique root in [1, 3].
(b) Suppose that the iteration formula x n g(x n 1 ) 3 2x n 1 5 for n = 1, 2, 3, … is used to estimate
the value of .
(i) Show that 1 g(x) 3 for all x in [1, 3].
(ii) Find K max g '(x) correct to 3 decimal places.
1 x 3
(c) Hence, with (i) x 0 2 and (ii) x 0 2.5 , estimate the value of correct to 5 decimal places.
Solution:
2
1 2
(b) Let g(x) 2x 5 . Then g '(x) (2x 5) 3 (2)
3
2
.
3
3(2x 5) 3
Hence by Contraction Mapping Theorem, the sequence of iterates {xn} will converges to for any
initial guess x 0 in [1, 3].
(1) The fixed point iteration is one point iteration where only one starting value x 0 is required.
As a general rule, try to find an interval in which a root lies and then choose as a starting point, x 0 ,
either (i) one of the end-points of the interval, or
(ii) the mean value of the two end-points of the interval.
(2) (i) if g ' ( ) < 1, the sequence x0, x1, x2,… will converge to a root of f(x) = 0.
In particular,
(a) if –1 < g’( ) < 0 then the sequence x0, x1, x2,… will oscillate and converge towards a root
of f(x) = 0 and
(b) if 0 < g’( ) < 1 then the sequence x0, x1, x2,… will converge, without oscillating, towards
a root of f(x) = 0.
(ii) if g ' ( ) 1 then the sequence x0, x1, x2,… will diverge.
Remark:
1. To neglect the rounding off error, we should keep as many as possible the number of decimal places
in each iterate xn. Otherwise, rounding errors will propagate throughout every iterate to affect the
final conclusion.
2. To show that a g(x) b for all x in [a, b], we examine the monotonic property of g(x) on [a, b].
g g min g max
↗ g(a) g(b)
↘ g(b) g(a)
3. To find K max g '(x) , we examine the monotonic property of g’(x) on [a, b].
a x b
g’(x)
↗ ↘
0 0 0 0
4-5
Error Estimate in Method of Fixed Point Iteration
To better understand the accuracy of the estimate of root of an equation, we study the error estimation
formula as follows:
K
Theorem In the nth iteration, x n x n x n 1 for n = 1, 2, 3, …,
1 K
Proof:
x n g(x n 1 ) g()
g '(c) x n 1 (by Mean Value Theorem)
K x n 1
K x n 1 x n x n
K x n 1 x n K x n (by Triangle Inequality)
Hence (1 K) x n K x n x n 1
K
xn x n x n 1 (∵ 1 – K > 0)
1 K
This is a practical way to estimate the error bound of the estimation of the root by xn.
Kn
Theorem In the nth iteration, x n x 1 x 0 for n = 1, 2, 3, …,
1 K
where (0 )K max g '(x) 1 .
a x b
Proof:
Hence (1 K) x n K x n x n 1 K n x1 x 0
Kn
∴ xn x1 x 0 (∵ 1 – K > 0)
1 K
This is a practical way to find the number of iteration required to guarantee to get
an estimate with certain accuracy.
4-6
Example 2
(a) Show that the equation e x x 0 has a unique root in [0.5, ln 2].
(b) Suppose that the iteration formula x n g(x n 1 ) e x n1 for n = 1, 2, 3, … is used to estimate
the value of .
(i) Show that 0.5 g(x) ln 2 for all x in [0.5, ln 2].
(ii) Find K max g '(x) .
0.5 x ln 2
(c) (i) With x 0 0.5 , find the value of correct to 4 decimal places.
(ii) Show that the error bound in estimating by the iterate x 6 is less than 9.73 10-3.
(iii) Find the least number of iterations required to give the estimate of correct to 4 decimal places.
Solution:
4-7
(c) (i) n xn correct to 4 d.p. n xn correct to 4 d.p.
0 0.5 11 0.567277196 0.5673
1 0.606530659 0.6065 12 0.567067351 0.5671
2 0.545239211 0.5453 13 0.56718636 0.5672
3 0.579703094 0.5797 14 0.567118864 0.5671
4 0.560064627 0.5601 15 0.567157143 0.5672
5 0.571172149 0.5712 16 0.567135433 0.5671
6 0.564862947 0.5649 17 0.567147746 0.5671
7 0.568438047 0.5684 18 0.567140763 0.5671
8 0.566409452 0.5664 19 0.567144723 0.5671
9 0.567559634 0.5676 20 0.567142477 0.5671
10 0.566907212 0.5669 21 0.567143751 0.5671
(ii) For n = 6,
K e0.5
x6 x6 x5 = 0.5
0.564862947 0.571172149 9.7256 10 3 9.73 10 3
1 K 1 e
Kn
(iii) The error bound in estimation of by xn is x1 x 0
1 K
1
Since the error tolerance is 104 5 105 ,
2
Kn
set x 1 x 0 5 10-5
1 K
e 0.5 n
Remark:
1. We should retain more significant figures in each xn for error analysis as there will be a loss of
number of significant figures in difference between two approximately equal numbers.
Consider the smooth graph with an equation y = f(x). The root is at the point where the graph
meets the x-axis. We will usually have an estimate of , and it will be denoted by x 0 (initial guess).
To improve the accuracy of this estimate, we consider the tangent to the graph at the point (x 0 ,f (x 0 )) .
If x 0 is near then this tangent line will meet the x-axis at some point x1 nearer to where
f (x 0 ) 0 f (x 0 )
x1 x 0 as f '(x 0 )
f '(x 0 ) x1 x 0
Since x1 is an improvement over x 0 as an estimate of , this entire procedure can be repeated with x1
as the initial approximation. This leads to the new estimate
f (x1 )
x 2 x1
f '(x1 )
Repeating this process, we obtain a sequence of iterates {xn} defined by the iterative formula
f (x n 1 )
x n x n 1 for n = 1, 2, 3, …
f '(x n 1 )
This is the Newton’s method for estimation of roots of the equation f(x) = 0.
4-9
Example 3
Solution:
Let f (x) e x x
Then f '(x) e x 1
With x 0 0.5 ,
we have x1 0.566311003
x 2 0.567143165
x 3 0.56714329
x 4 0.56714329
x 5 0.56714329
4-10
Remark:
1. To estimate a root, Newton’s method is more effective than method of fixed point iteration.
n xn correct to 6 d.p.
0 0.5
1 0.606530659 0.606531
2 0.545239211 0.545239
3 0.579703094 0.579703
4 0.560064627 0.560065
5 0.571172149 0.571172
6 0.564862947 0.564863
7 0.568438047 0.568438
8 0.566409452 0.566409
9 0.567559634 0.567560
10 0.566907212 0.566907
11 0.567277196 0.567277
12 0.567067351 0.567067
13 0.56718636 0.567186
14 0.567118864 0.567119
15 0.567157143 0.567157
16 0.567135433 0.567135
17 0.567147746 0.567148
18 0.567140763 0.567141
19 0.567144723 0.567145
20 0.567142477 0.567142
21 0.567143751 0.567144
22 0.567143029 0.567143
23 0.567143438 0.567143
24 0.567143206 0.567143
25 0.567143338 0.567143
26 0.567143263 0.567143
27 0.567143305 0.567143
1
2. Since the error tolerance is 106 5 107 ,
2
Kn
set x1 x 0 5 107
1 K
(e0.5 )n
we have 0.5
0.606530659 0.5 5 107
1 e
(e 0.5 ) n 1.846742782 10 6
ln(1.846742782 10 6 )
n
ln(e 0.5 )
n 26.40
Example 4
Let f (x) x 6 x 1 .
(a) Show that the equation f(x) = 0 has a unique root in [1, 2].
5x 6 1
(b) Show that the Newton’s iterative formula is x n n5 1 for n = 1, 2, 3, ….
6x n 1 1
(c) Show that the sequence of Newton’s iterates converges to for any initial guess x 0 in [1, 2].
Hence, with x 0 1.1 , find the value of correct to 7 decimal places.
Solution:
∴ The sequence of Newton’s iterates converges to for any initial guess x 0 in [1, 2].
n xn correct to 7 d.p.
0 1.1 (say),
1 1.137912585 1.1379126
2 1.13474852 1.1347485
3 1.13472414 1.1347241
4 1.134724138 1.1347241
5 1.134724138 1.1347241
Remark: x n g(x n 1 ) 6 x n 1 1 , n = 1, 2, 3, …
4-12
4.2 Numerical Integration
By fundamental theorem of calculus, we can evaluate the definite integral by first finding
the primitive function F(x) of the integrand f(x) so that
sin x 1
2
e x dx cannot be evaluated
2
However, most definite integrals for example dx and
1 x 0
analytically in this way because most integrands do not have anti-derivatives expressible in terms
of elementary functions.
In this section, we will study two fundamental numerical methods of integration, namely,
Trapezoidal rule and Simpson’s rule.
A. Trapezoidal Rule
In the trapezoidal rule, we approximate the function f(x) in the interval [a, b] by a straight line
through the end points.
b
a
f ( x ) dx is approximated by the area of a trapezium.
1
= (b a )(AP BQ)
2
1
= (b a )[f (a ) f (b)]
2
Usually the function f(x) is such that a single straight line for the whole interval is not a good
enough approximation. In such cases we divide the interval [a, b] into n equal subintervals,
by the points x0 = a, x1, x2,…, xn = b and apply the trapezoidal rule for each subinterval.
We get the composite trapezoidal rule.
4-13
Theorem Composite Trapezoidal Rule
b ba
Let I = f ( x ) dx. The interval [a, b] is divided into n equal subintervals of width h .
a n
Define xi a ih and yi f (xi ) for i = 0, 1, 2,…, n.
The estimate of I is given by Tn where
h
Tn = [(y0 + yn) + 2(y1 + y2 + … + yn-1)]
2
Proof:
The estimate of I is Tn .
b
3. The trapezoidal rule gives the exact value of a
f ( x ) dx when f(x) is a linear polynomial.
4-14
Example 5
2
Find I ln x dx, correct to 4 decimal places, using the trapezoidal rule with 5 subintervals.
1
Solution:
2 1
For n = 5, h 0.2 . Then
5
i xi yi ln xi
0 1 0
1 1.2 0.182321556
2 1.4 0.336472236
3 1.6 0.470003629
4 1.8 0.587786664
5 2 0.69314718
2 0 .2
I ln x dx T5 = [(y0 + y5) + 2(y1 + y2 + y3 + y4 )]
1 2
= 0.1[0 + 0.69314718 + 2(0.182321556 + 0.336472236 + 0.470003629 + 0.587786664) ]
= 0.384631535
= 0.3846 (correct to 4 decimal places)
ln x dx = x ln x x 1
2
2
Remark: The exact value of ( Using Integration by Parts,
1
Choose f(x) = ln x and g’(x) = 1 )
4-15
Error Estimation in Trapezoidal Rule
Theorem Let f(x) have twice continuous derivatives on [a, b] and n be any positive integer.
b
The error in estimating the value of a
f ( x ) dx using trapezoidal rule
(b a)h 2 ba
E n I Tn f "(c) for some c in [a, b] and h =
12 n
ba
where M 2 = max f "(x) and h
a x b n
2. To find M 2 max f "(x) , we examine the monotonic property of f "(x) on [a, b].
a x b
4-16
Example 6
1
(a) Estimate the value of I = e x dx using the trapezoidal rule with 5 subintervals.
0
(b) (i) Show that the error bound in (a) is less than 0.009061.
(ii) Is it an overestimate or an underestimate of I? Explain your answer.
Solution:
(a) For n = 5
1 0
h= = 0.2
5
1 0 .2 0 1
0
e x dx T5 =
2
[(e + e ) + 2(e0.2 + e0.4 +e0.6 + e0.8 )] = 1.72400562
(1 0)(0.2) 2 (1 0)3
Hence E 5 = f ' ' (c) 2
(e) 9.060939428 103 < 0.009061 (∵ 0 c 1 )
12 12(5)
b
The following steps are some standard procedures to estimate the value of I = f ( x ) dx
a
(1) to determine the least number n of subintervals required by the numerical integration formula
1
so that E n 10 k 5 10 (k 1)
2
(2) to evaluate Tn correct to k decimal places
1
(a) Find the least number of subintervals required by trapezoidal rule to give an estimate of I = e x dx
0
Solution:
1 0
2
(1 0)
n f "(c) (1 0) (1) = 1
3
En = (∵ 0 c 1 )
12 12n 2 12n 2
1
Since the error tolerance is 102 5 103 ,
2
1
we set En 5 103
12n 2
16.66666667 n 2
n 4.08
(b) For n = 5
1 0
h= = 0.2
5
1 0.2 -0 -1
I e x dx T5 = [(e + e ) + 2(e- 0.2 + e- 0.4 + e- 0.6 + e- 0.8 )] = 0.634226224
0 2
1
Remark: The exact value of I = e x dx e x ( e1 ) (e0 ) e1 1 0.632120558
1
0 0
4-18
B. Simpson’s Rule
To improve the estimate value of I by trapezoidal rule which is based on linear interpolation,
ab
we use quadratic polynomial P(x) interpolating the function f(x) at a, m and b and give
2
(x m)(x b) (x a)(x b) (x a)(x m)
P(x) f (a) f (m) f (b)
(a m)(a b) (m a)(m b) (b a)(b m)
The estimate of I is IS .
ba ba
width h = =
n 2N
Define xi a ih and yi f (xi ) for i = 0, 1, 2,…, 2N
The estimate of I is given by Sn where
h
Sn S2N = [(y0 + y2N) + 4(y1 + y3 + … + y2N-1) + 2(y2 + y4 + … + y2N-2)]
3
4-19
Error Estimation in Simpson’s Rule
Theorem Let f(x) have four times continuous derivatives on [a, b] and n = 2N be any even positive integer.
b
The error in estimating the value of I f (x) dx using Simpson’s rule with 2N subintervals
a
is given by
(b a)h 4 (4) ba
E n I Sn f (c) for some c in [a, b] and h =
180 n
(b a )h 4 ( 4) (b a)h 4 (b a)5
En = f ( c) M4 M4
180 180 180n 4
ba
where M 4 = max f ( 4) (x) and h
a xb n
2. To find M4 max f (4) (x) , we examine the monotonic property of f (4) (x) on [a, b].
a x b
If f (4) (x) is ↗ or ↘ on [a, b], then M 4 max{ f (4) (a) , f (4) (b) }
4. If n then En 0
The greater n is, the more accurate is Sn as an estimate of I.
4-20
Example 8
3 1
(a) Estimate the value of I = dx by Simpson’s rule with 8 subintervals.
1 x
Give your answer in 4 decimal places.
(b) Show that the error bound in (a) is less than 0.001042.
Solution:
(a) For n = 8
3 1
h= = 0.25
8
3 1 0.25 1 1 1 1 1 1 1 1 1
I dx S8 4 2 1.098725349
1 x
3 1 3 1.25 1.75 2.25 2.75 1.50 2.00 2.50
1
(b) Let f(x) =
x
1
We have f (1) (x) =
x2
2
f ( 2) (x ) =
x3
6
f (3) (x) =
x4
24
and f ( 4) ( x) =
x5
(3 1)(0.25) 4 ( 4) 2(0.25) 4 1
Hence E 8 = f ( c) (24) = 1.041666667 103 0.001042
180 180 960
(∵1c3)
4-21
Example 9
(a) Find the least number of subintervals required by Simpson’s rule to give the estimate of I 4 ex cos xdx
0
correct to 4 decimal places.
(b) Hence estimate the value of I.
Solution:
Since f ( 4) (x) is decreasing and < 0 on 0,
4
∴ M 4 max f (4) (x) f (4) 4e 4 cos 4e 4 cos
0 x
4 4 4
4
4 5
0 0
4e 4 cos
f (c) 4
4 4 4
En = ( 4)
(∵ 0c )
180 n 4
180n 4 4
5
Since the error tolerance is 104 5 105 , we set E n 4 4e 4 cos 5 105
1 4
2 180n 4
205.9899249 n 4
n 3.788449433
Solution:
5
I sin xdx T6 12 sin 0 sin 2 sin sin sin sin sin 0.994281888
2
0 2 2 12 6 4 3 12
(ii) For n = 6
0
h= 2 =
6 12
5
I sin xdx S6 12 sin 0 sin 4 sin sin sin 2 sin sin 1.000026312
2
0 3 2 12 4 12 6 3
(b) The true value of I = sin x dx = cos x 02 cos cos(0) 0 1 1
2
0
2
Simpson’s rule gives estimate of I more accurate than that of trapezoidal rule using the same even
number of subintervals.
4-23
Example 11
0 .5
Let I = e x dx. Find the least number of subintervals required to give the estimate of I correct to
2
4 decimal places by
(a) Trapezoidal rule (b) Simpson’s rule
Solution:
0 x 0.5
(0.5 0) 2
(0.5 0)
n2 (0.5) 3 (2) 1
En = f "(c) = ( ∵ 0 c 0.5 )
12 12n 2
48n 2
1 1
Since the error tolerance is 104 5 105 , we set E n 2
5 105 i.e. n 2 416.6667 ∴ n 20.41
2 48n
Hence the least number of subinterval required is 21 (round up to the nearest integer)
(b) f (4) (x) 12e x 12x( 2xe x ) 8(3x 2 )e x 8x 3 ( 2xe x ) (16x 4 48x 2 12)e x
2 2 2 2 2
0 x 0.5
(0.5 0) 4
(0.5 0)
n4 (0.5)5 (12) 1
En = f ( 4 ) (c) 4
( ∵ 0 c 0.5 )
180 180n 480n 4
1 1
Since the error tolerance is 104 5 105 , we set E n 4
5 105 i.e. n 4 41.6667 ∴ n 2.54
2 480n
Hence the least even number of subinterval required is 4 (round up to the nearest even integer)
4-24