0% found this document useful (0 votes)
13 views

MTH 201 Lecture Notes

Uploaded by

adedavidhishere
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

MTH 201 Lecture Notes

Uploaded by

adedavidhishere
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

MTH 201: Numerical Methods

March 8, 2021
ii

0.1 Solution of Equations in One Variable

Suppose that f is a real-valued function, defined and continuous on a bounded closed


interval [a, b] of the real line. It will be tacitly assumed that a < b, so that the interval is
nonempty. We wish to find a real number ξ ∈ [a, b] such that f (ξ) = 0. If such ξ exists, it
is called a solution to the equation f (x) = 0. So, finding the roots of f (x) means solving
the equation
f (x) = 0. (1)

If f (x) is a quadratic, cubic or a biquadratic expression, then algebraic formulae are


available for expressing the roots in terms of the coefficients. On the other hand, when
f (x) is a polynomial of higher degree or an expression involving transcendental functions,
algebraic methods are not available, and recourse must be taken to find the roots by ap-
proximate methods.
Note: A non-algebraic function is called a transcendental function, e.g. f (x) = ln x3 − 0.7,
φ(x) = e−0.5x − 5x, ψ(x) = sin2 (x) − x2 − 2, etc.

Definition 1. Root of an Equation, Zero of a Function: Assume that f (x) is a


continuous function. Any number ξ for which f (ξ) = 0 is called a root of the equation
f (x) = 0. Also, we say ξ is a zero of the function f (x).

Theorem 1. Let f be a real-valued function, defined and continuous on a bounded closed


interval [a, b] of the real line. Assume, further, that f (a)f (b) ≤ 0; then, there exists ξ in
[a, b] such that f (ξ) = 0.
The roots of equation (1) may be either real or complex. Hundreds of methods are avail-
able for locating zeros of functions, and two of the most useful have been selected for study
here: the bisection and Newton’s methods.

0.1.1 Bisection Method

Let f be a function that has values of opposite sign at the two ends of an interval.
Suppose also that f is continuous on that interval. To fix the notation, let a < b and
f (a)f (b) < 0. It then follows that f has a root in the interval (a, b). In other words, there
must exist a number p that satisfies the two conditions a < p < b and f (p) = 0. How
is this conclusion reached? One must recall the Intermediate Value Theorem. ”If x
traverses an interval [a, b], then the values of f (x) completely fill out the interval between
f (a) and f (b).” No intermediate values can be skipped. Hence, a specific function f must
0.1. SOLUTION OF EQUATIONS IN ONE VARIABLE iii

Figure 1:

take on the value zero somewhere in the interval (a, b) because f (a) and f (b) are of opposite
signs.
The Bisection method calls for a repeated halving (or bisecting) of subintervals of [a, b]
and, at each step, locating the half containing p.

To begin, set a1 = a and b1 = b and let p1 be the midpoint of [a, b]; that is,

b1 − a1 a1 + b1
p1 = a1 + = .
2 2
• If f (p1 ) = 0, then p = p1 , and we are done.
• If f (p1 ) 6= 0, then f (p1 ) has the same sign as either f (a1 ) or f (b1 ).
• If f (p1 ) and f (a1 ) have the same sign, p ∈ (p1 , b1 ). Set a2 = p1 and b2 = b1 .
• If f (p1 ) and f (a1 ) have opposite signs, p ∈ (a1 , p1 ). Set a2 = a1 and b2 = p1 .
Then reapply the process to the interval [a2 , b2 ].
iv

Example 1. Show that f (x) = x3 + 4x2 − 10 = 0 has a root in [1, 2], and use the Bisection
method to determine an approximation to the root that is accurate to at least within 10−4 .
Solution: Because f (1) = −5 and f (2) = 14, the Intermediate Value Theorem ensures
that this is continuous in [1, 2].
For the first iteration, we use the fact that at the midpoint of [1, 2] we have f (1.5) =
2.375 > 0. This indicates that we should select the interval [1, 1.5] for our second iteration.
Then we find that f (1.25) = −1.796875, so our new interval becomes [1.25, 1.5], whose
midpoint is 1.375. Continuing in this manner gives the values in Table 1.
After 13 iterations, p13 = 1.365112305 approximates the root p with an error

|p − p13 | < |b14 − a14 | = |1.365234375 − 1.365112305| = 0.000122070.

Since |a14 | < |p|, we have

|p − p13 | |b14 − a14 |


< ≤ 9.0 × 10−5 ,
|p| |a14 |

so the approximation is correct to at least within 10−4 . The correct value of p to nine
decimal places is p = 1.365230013.
0.1. SOLUTION OF EQUATIONS IN ONE VARIABLE v

Table 1: Table of Results


n an bn rn f (rn )
1 1.0 2.0 1.5 2.375
2 1.0 1.5 1.25 −1.79687
3 1.25 1.5 1.375 0.16211
4 1.25 1.375 1.3125 −0.84839
5 1.3125 1.375 1.34375 −0.35098
6 1.34375 1.375 1.359375 −0.09641
7 1.359375 1.375 1.3671875 0.03236
8 1.359375 1.3671875 1.36328125 −0.03215
9 1.36328125 1.3671875 1.365234375 0.000072
10 1.36328125 1.365234375 1.364257813 −0.01605
11 1.364257813 1.365234375 1.364746094 −0.00799
12 1.364746094 1.365234375 1.364990235 −0.00396
13 1.364746094 1.365234375 1.365112305 −0.00194
vi

Note that p9 is closer to p than the final approximation p13 .

Theorem 2. Suppose that f ∈ C[a, b] and f (a) · f (b) < 0. The Bisection method generates
a sequence {pn }∞
n=1 approximating a zero p of f with

b−a
pn − p ≤ , when n ≥ 1. (2)
2n
Example 2. Determine the number of iterations necessary to solve f (x) = x3 +4x2 −10 = 0
with accuracy 10−3 using a1 = 1 and b1 = 2.
Solution: From equation (2), we have

pn − p ≤ 2−n (b − a) = 2−n < 10−3 .

We will use base-10 logarithms because the tolerance is given as a power of 10.
Thus
2−n < 10−3
implies that
log10 2−n < log10 10−3 = −3.
We then have
−n log10 2 < −3
from which we obtain
3
n> ≈ 9.96.
log10 2
Hence, ten iterations will ensure an approximation accurate to within 10−3 .

0.1.2 Advantages of Bisection Method

i. Provided the function is continuous on an interval [a, b] with f (a) · f (b) < 0, bisection
method is guaranteed to work.
ii. The number of iterations needed to achieve a specific accuracy is known in advance.

0.1.3 Disadvantages of Bisection Method

i. The method is slow to converge.


ii. The errors in pn and in f (pn ) do not necessarily decrease between iterations.
0.1. SOLUTION OF EQUATIONS IN ONE VARIABLE vii

EXERCISE 1

(a) Use the Bisection method to find p3 for f (x) = x − cos(x) on [0, 1]
(b) Use the Bisection method to find solutions accurate to within 10−5 for the following
problems:
i. x − 2−x = 0 f or 0≤x≤1
ii. ex − x2 + 3x − 2 = 0 f or 0≤x≤1
iii. 2x cos(2x) − (x + 1)2 = 0 f or − 3 ≤ x ≤ −2
(c) If a = 0.1 and b = 1.0, how many steps of the bisection method are needed to
determine the root with an error of at most 12 × 10−8 ?
(d) Use Theorem 2 to find a bound for the number of iterations needed to achieve an
approximation with accuracy 10−4 to the solution of x3 − x − 1 = 0 lying in the
interval [1, 2]. Find an approximation to the root with this degree of accuracy.
(e) Consider the bisection method with the initial interval [a0 , b0 ]. Show that after ten
steps with this method,

1  1 
a9 + b9 = 2−11 b0 − a0 .

a10 + b10 −
2 2

(f) The function f (x) = sin(x) satisfies f (−π/2) = −1 and f (π/2) = 1. Using bisection
method, how many iterations are needed to find an interval of length at most 10−4
which contains a root of the function?

0.1.4 Newton’s Method

The procedure known as Newton’s method is also called the Newton-Raphson iteration.
The Newton-Raphson method is one of the most useful and best known algorithms that
relies on the continuity of f 0 (x) and f 00 (x).

0.1.5 Interpretations of Newton’s Method

In Newton’s method, it is assumed at once that the function f is differentiable. This


implies that the graph of f has a definite slope at each point and hence a unique tangent
line.
viii

At a certain point (x0 , f (x0 )) on the graph of f, there is a tangent, which is a rather good
approximation to the curve in the vicinity of that point. Analytically, it means that the
linear function
l(x) = f 0 (x0 )(x − x0 ) + f (x0 )
is close to the given function f near x0 . At x0 , the two functions l and f agree. We take
the zero of l as an approximation to the zero of f. The zero of l is easily found:

f (x0 )
x1 = x0 − .
f 0 (x0 )

Thus, starting with point x0 (which we may interpret as an approximation to the root
sought), we pass to a new point x1 obtained from the preceding formula. Naturally, the
process can be repeated (iterated) to produce a sequence of points:

f (x1 ) f (x2 )
x2 = x1 − , x3 = x2 − ,
f 0 (x1 ) f 0 (x2 )

etc. Under favourable conditions, the sequence of points will approach a zero of f.

The geometry of Newton’s method is shown in Figure 1. The line y = l(x) is tangent to
the curve y = f (x). It intersects the x- axis at a point x1 . The slope of l(x) is f 0 (x0 ).
0.1. SOLUTION OF EQUATIONS IN ONE VARIABLE ix

Figure 2:
x

There are other ways of interpreting Newton’s method. Suppose again that x0
is an initial approximation to a root of f and let x1 = x0 + h be the correct root
so that f (x1 ) = 0.
Expanding f (x0 + h) by Taylor series, we obtain

h2 00
f (x0 ) + hf 0 (x0 ) + f (x0 ) + · · · = 0
2
Neglecting the second and higher order derivatives, we have

f (x0 ) + hf 0 (x0 ) = 0,

which gives
f (x0 )
h=− .
f 0 (x0 )
A better approximation than x0 is therefore, given by x1 , where

f (x0 )
x1 = x0 − .
f 0 (x0 )

Successive approximations are given by x2 , x3 , · · · , xn+1 , where

f (xn )
xn+1 = xn − , (3)
f 0 (xn )

which is the Newton-Raphson formula.

Example 3. Perform four iterations of the Newton’s method to find the smallest positive
root of the equation f (x) = x3 − 5x + 1 = 0.
Solution:

f (x) = x3 − 5x + 1 = 0, theref ore f 0 (x) = 3x2 − 5, f (0) = 1, and f (1) = −3.

Since, f (0) · f (1) < 0, the smallest positive root lies in the interval (0, 1).
Applying the Newton’s method, we obtain

x3n − 5xn + 1 2x3n − 1


xn+1 = xn − = , n = 0, 1, 2, 3.
3x2n − 5 3x2n − 5

The initial approximation x0 is taken to be 0+1


2 = 0.5. Thus we have the follow-
ing
2x3 − 1 2(0.5)3 − 1
x1 = 02 = = 0.176471,
3x0 − 5 3(0.5)2 − 5
0.1. SOLUTION OF EQUATIONS IN ONE VARIABLE xi

2x31 − 1 2(0.176471)3 − 1
x2 = 2 = = 0.201568,
3x1 − 5 3(0.176471)2 − 5

2x32 − 1 2(0.201568)3 − 1
x3 = = = 0.201640,
3x22 − 5 3(0.201568)2 − 5

2x33 − 1 2(0.201640)3 − 1
x4 = = = 0.201640.
3x23 − 5 3(0.201640)2 − 5
Therefore, the root correct to six decimal places is x = 0.201640.

Example 4. Show that the equation


!
π(x + 1)
f (x) = cos + 0.148x − 0.9062 = 0
8

has one root in the interval (−1, 0) and one in (0, 1). Calculate the negative root correct to
4 decimal places.
Solution: From the given function, we have

f (−1) = −0.0542, f (0) = 0.0177, f (1) = −0.0511.

Hence, one root lies in the interval (−1, 0) and one root in the interval (0, 1).
Using the formula
f (xn )
xn+1 = xn − 0 , n = 0, 1, · · ·
f (xn )
where ! !
π π(x + 1)
f 0 (x) = − sin + 0.148.
8 8

With x0 = −0.5, we obtain the following sequence of iterates:

x1 = −0.508199, x2 = −0.508129, x3 = −0.508129.

Hence, the root correct to four decimal places is −0.5081.

0.1.6 Advantages of Newton’s Method

(i) It is fast
(ii) It can be extended to multidimensional problems.
xii

0.1.7 Disadvantages of Newton’s Method

(i) It requires evaluating the derivative, f 0 (x), at each iteration.


(ii) It can fail if the initial guess is not sufficiently close to the solution, par-
ticularly if f 0 (x) = 0.
EXERCISE 2
(a) Find all the roots of cos(x) − x2 − x = 0 to five decimal places.

(b) Verify that when Newton’s method is used to compute R, the sequence
of iterates is defined by
!
1 R
xn+1 = xn + .
2 xn

(c) Establish Newton’s iterative scheme in simplified form, not involving the
reciprocal of x for the function f (x) = xR − x−1 . Carry out three steps of
this procedure using R = 4 and x0 = −1.
(d) Use Newton’s method to find all roots of the following equations, correct
to six decimal places

(i) 3 cos(x) = x + 1 (ii) cos(x) = x (iii) sin(x) = x2 − 2 (iv) cos(x2 − x) =
x4 .
(e) Find all positive roots to the equation
Z x
2
10 e−x dt = 1,
0

correct to six decimal places.


(f ) The function described by f (x) = ln(x2 + 1) − e0.4x cos(πx) has an infinite
number of zeros. (i) Determine, within 10−6 , the only negative zero. (ii)
Determine, within 10−6 , the four smallest positive zeros.

0.2 Numerical Integration

Numerical integration is a primary tool used by engineers and scientists to


obtain approximate answers for definite integrals that cannot be solved ana-
lytically.
0.2. NUMERICAL INTEGRATION xiii

0.2.1 Newton-Cotes Quadrature Formula


Rb
Newton-Cotes quadrature formulas for approximating a f (x)dx, are obtained
by approximating the function of integration f (x) by interpolating polynomials.
The rules are closed when they involve function values at the ends of the interval
of integration. Otherwise, they are said to be open.
The general problem of numerical integration may be stated as follows:
Given a set of data points (x0 , y0 ), (x1 , y1 ), · · · , (xn , yn ) of a function y = f (x), where
f (x) is not known explicitly, it is required to compute the value of definite
integral
Z b
I= ydx.
a

Let the interval [a, b] be divided into n equal subintervals such that a = x0 <
x1 < x2 < · · · < xn = b. Clearly, xn = x0 + nh. Hence the integral becomes
Z xn
I= ydx
x0

Approximating y by Newton’s forward difference formula, we obtain


Z xn " #
r(r − 1) 2 r(r − 1)(r − 2) 3
I=h y0 + r∆y0 + ∆ y0 + ∆ y0 + · · · dx
x0 2! 3!

Since x = x0 + rh, dx = hdr and hence the above integral becomes


Z n" #
r(r − 1) 2 r(r − 1)(r − 2) 3
I=h y0 + r∆y0 + ∆ y0 + ∆ y0 + · · · dr
0 2! 3!
" ! ! #n
r2 1 r3 r2 1 r4
= h ry0 + ∆y0 + − ∆ 2 y0 + − r3 + r2 ∆3 y0 + · · ·
2 2 3 3 6 4
0

which on simplification gives


Z xn " #
n n(2n − 3) 2 n(n − 2)2 3
ydx = nh y0 + ∆y0 + ∆ y0 + ∆ y0 + · · · (4)
x0 2 12 24

This is a general quadrature formula and is known as Newton-Cotes quadrature


formula. Trapezoidal rule, Simpson’s one-third, and Simpson’s three-eighth
rules can be respectively derived by putting n = 1, 2, and 3 in the formula
(4)
xiv

0.2.2 Trapezoidal Rule

Substituting n = 1 in (4) and taking the curve through (x0 , y0 ) and (x1 , y1 ) as a
polynomial of degree one so that differences of an order higher than one vanish,
we get
Z x0 +h !
1 hh i h
ydx = h y0 + ∆y0 = 2y0 + (y1 − y0 ) = (y0 + y1 ).
x0 2 2 2

Similarly, for the next sub-interval (x0 + h, x0 + 2h), we get


Z x0 +2h Z x0 +nh
h h
ydx = (y1 + y2 ), · · · , ydx = (yn−1 + yn )
x0 +h 2 x0 +(n−1)h 2

Adding the above integrals, we get


Z x0 +nh  
h  
ydx = y0 + yn + 2 y1 + y2 + · · · + yn−1 (5)
x0 2

which is the Trapezoidal rule.

0.2.3 Simpson’s 1/3 - Rule

Putting n = 2 in formula (4) and taking the curve through (x0 , y0 ), (x1 , y1 ) and
(x2 , y2 ) as a polynomial of degree two so that differences of order higher than
two vanish, we get
Z x0 +2h !
1 2
ydx = 2h y0 + ∆y0 + ∆ y0
x0 6
 
2h  
= 6y0 + 6 y1 − y0 + y2 − 2y1 + y0
6
 
h
= y0 + 4y1 + y2
3
Similarly,
Z x0 +4h  
h
ydx = y2 + 4y3 + y4 , · · · ,
x0 +2h 3
Z x0 +nh  
h
f (x)dx = yn−2 + 4yn−1 + yn .
x0 +(n−2)h 3
0.2. NUMERICAL INTEGRATION xv

Adding the above integrals, we get


Z x0 +nh  
h
ydx = (y0 + yn ) + 4(y1 + y3 + · · · + yn−1 ) + 2(y2 + y4 + · · · + yn−2 ) (6)
x0 3
which is Simpson’s one-third rule.
Note: Simpson’s one-third rule rule requires the whole range (the given inter-
val) must be divided into even number of equal subintervals.

0.2.4 Simpson’s 3/8 - Rule

Substituting n = 3 in formula (4) and taking the curve through (x0 , y0 ), (x1 , y1 ),
(x2 , y2 ) and (x3 , y3 ) as a polynomial of degree three so that differences of order
higher than three vanish, we get
Z x0 +3h  
3 3 2 1 3
ydx = 3h y0 + ∆y0 + ∆ y0 + ∆ y0
x0 2 4 8
" #
3h      
= 8y0 + 12 y1 − y0 + 6 y2 − 2y1 + y0 + y3 − 3y2 + 3y1 − y0
8
3h h i
= y0 + 3y1 + 3y2 + y3 .
8
Similarly,
Z x0 +6h
3h h i
ydx = y3 + 3y4 + 3y5 + y6 , · · ·
x0 +3h 8
Z x0 +6h
3h h i
ydx = yn−3 + 3yn−2 + 3yn−1 + yn .
x0 +(n−3)h 8
Adding the above integrals, we get
Z x0 +nh  
3h
ydx = (y0 +yn )+3(y1 +y2 +y4 +y5 +· · ·+yn−2 +yn−1 )+2(y3 +y6 +· · ·+yn−3 )
x0 8
(7)
which is known as Simpson’s three-eighth rule.
Note: This rule also requires that the number of subintervals should be taken
as multiples of 3.
Example 5. Evaluate Z 1
1
dx
0 1+x
using trapezoidal and Simpson’s rules with h = 0.5, 0.25, and 0.125, correct to three decimal
places.
Solution: (i) h = 0.5 : The values of x and y are tabulated below (Table 2)
xvi

Table 2: Table of Values


x y
0.0 1.0000
0.5 0.6667
1.0 0.5000
0.2. NUMERICAL INTEGRATION xvii

(a) Trapezoidal rule gives


1h i
I= 1.0000 + 2(0.6667) + 0.5000 = 0.70835.
4

1
(b) Simpson’s 3 rule gives

1h i
I= 1.0000 + 4(0.6667) + 0.5000 = 0.6945.
6

(ii) h = 0.25 : The tabulated values of x and y are given below (Table 3)
xviii

Table 3: Table of Values


x y
0.00 1.0000
0.25 0.8000
0.50 0.6667
0.75 0.5714
1.00 0.5000
0.2. NUMERICAL INTEGRATION xix

(a) Trapezoidal rule gives


1h i
I = 1.0000 + 2(0.8000 + 0.6667 + 0.5714) + 0.5000 = 0.6970.
8

1
(b) Simpson’s 3rule gives
1h i
I= 1.0000 + 4(0.8000 + 0.5714) + 2(0.6667) + 0.5000 = 0.6932.
12

(iii) h = 0.125 : The tabulated values of x and y are given below (Table 4)
(a) Trapezoidal rule gives
1h i
I= 1.0+2(0.8889+0.80+0.7273+0.6667+0.6154+0.5714+0.5333)+0.50 = 0.6941.
16

(b) Simpson’s 31 rule gives


1h i
I= 1.0+4(0.8889+0.7273+0.6154+0.5333)+2(0.80+0.6667+0.5714)+0.5 = 0.6932.
24

Hence the value of I may be taken to be 0.693, correct to three decimal places.
The exact value of I is loge 2, which is 0.693147 · · · .
This example demonstrates that, in general, Simpson’s rule yields more accu-
rate results than the trapezoidal rule.

EXERCISE 3
(a) Evaluate
Z π Z 2
x
(i) x sin(x)dx and (ii) dx
0 −2 5 + 2x
using the trapezoidal rule with five ordinates.
1
(b) Using Simpson’s 3 rule with h = 1, evaluate the integral
Z 7
I= x2 log xdx.
3

(c) Estimate the value of integral


Z 1
2 dx
I= √ √
0 x 1−x
using the trapezoidal rule. What is its exact value?
xx

(d) Evaluate
Z 2
dx
0 x3 +x+1
1
by using Simpson’s 3 rule with h = 0.25.
(e) Suppose that f (0) = 1, f (0.5) = 2.5, f (1) = 2, and f (0.25) = f (0.75)
R 1 = α. Find
α if the Trapezoidal rule with n = 4 gives the value 1.75 for 0 f (x)dx.
0.2. NUMERICAL INTEGRATION xxi

Table 4: Table of Values


x y
0.000 1.0000
0.125 0.8889
0.250 0.8000
0.375 0.7273
0.500 0.6667
0.625 0.6154
0.750 0.5714
0.875 0.5333
1.000 0.5000

You might also like