NUMERICAL ANALYSIS · 2015-10-21 · (a) Nonlinear algebraic equations in one variable - chapter 3...

58
NUMERICAL ANALYSIS K.D. Anderson J.S.C. Prentice C.M. Villet

Transcript of NUMERICAL ANALYSIS · 2015-10-21 · (a) Nonlinear algebraic equations in one variable - chapter 3...

Page 1: NUMERICAL ANALYSIS · 2015-10-21 · (a) Nonlinear algebraic equations in one variable - chapter 3 - we investigate the bisection method, linear interpolation, Newton’s method,

NUMERICAL ANALYSIS

K.D. Anderson

J.S.C. Prentice

C.M. Villet

Page 2: NUMERICAL ANALYSIS · 2015-10-21 · (a) Nonlinear algebraic equations in one variable - chapter 3 - we investigate the bisection method, linear interpolation, Newton’s method,

This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0International License. To view a copy of this license, visit

http://creativecommons.org/licenses/by-nc-sa/4.0/

Last updated: 21 October 2015Disclaimer: Links are followed at own risk when viewing this document electronically.

Page 3: NUMERICAL ANALYSIS · 2015-10-21 · (a) Nonlinear algebraic equations in one variable - chapter 3 - we investigate the bisection method, linear interpolation, Newton’s method,

Contents

1 INTRODUCTION 4

1.1 Numerical methods and analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

1.1.1 Numerical analysis. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

1.1.2 Types of methods. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

1.2 Number representations and round-off errors . . . . . . . . . . . . . . . . . . . . . 5

1.2.1 Decimal number representation . . . . . . . . . . . . . . . . . . . . . . . . . 5

1.2.2 Error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

2 SERIES EXPANSIONS 7

2.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

2.2 Sequences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

2.3 Series . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

2.4 Taylor series expansions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

2.4.1 Taylor’s Theorem (1715) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

2.4.2 Taylor series . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

2.4.3 Lagrange estimate of the error term . . . . . . . . . . . . . . . . . . . . . . 14

2.4.4 Expansion of multivariable functions . . . . . . . . . . . . . . . . . . . . . . 15

3 NONLINEAR EQUATIONS 16

3.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

3.2 The bisection method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

3.3 Linear interpolation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

3.4 Newton’s method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

3.5 Fixed-point iteration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

3.6 Systems of nonlinear equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

4 SYSTEMS OF LINEAR EQUATIONS 24

4.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

4.2 Solvability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

4.3 Cramer’s rule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

4.4 The Jacobi method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

5 APPROXIMATION METHODS 27

5.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27

5.2 Polynomial interpolation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27

5.3 Lagrange’s method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28

5.4 Least-squares curve fitting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30

5.5 Least-squares polynomial fitting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31

5.6 Approximation with Chebyshev polynomials . . . . . . . . . . . . . . . . . . . . . . 33

5.6.1 Definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

5.6.2 Minimal property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35

5.6.3 Expansion of a function in terms of Chebyshev polynomials . . . . . . . . . 36

3

Page 4: NUMERICAL ANALYSIS · 2015-10-21 · (a) Nonlinear algebraic equations in one variable - chapter 3 - we investigate the bisection method, linear interpolation, Newton’s method,

4 CONTENTS

6 NUMERICAL DIFFERENTIATION 406.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 406.2 First derivative . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 406.3 Second derivative . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 416.4 Higher-order derivatives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42

7 NUMERICAL INTEGRATION 447.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 447.2 Newton-Cotes formulae . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 447.3 Trapezium rule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 457.4 Simpson’s rule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 477.5 An analytical complication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49

8 ORDINARY DIFFERENTIAL EQUATIONS 518.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 518.2 One-step methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 528.3 Euler’s method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 528.4 The modified Euler method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 528.5 The Runge-Kutta methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53

8.5.1 The second-order Runge-Kutta method (RK2) . . . . . . . . . . . . . . . . 538.5.2 The fourth-order Runge-Kutta method (RK4) . . . . . . . . . . . . . . . . . 54

8.6 Approximation error in one-step methods . . . . . . . . . . . . . . . . . . . . . . . 55

Page 5: NUMERICAL ANALYSIS · 2015-10-21 · (a) Nonlinear algebraic equations in one variable - chapter 3 - we investigate the bisection method, linear interpolation, Newton’s method,

Chapter 1

INTRODUCTION

1.1 Numerical methods and analysis

When solving a mathematical problem, such as determining a definite integral or solving a differ-ential equation, we attempt to do so analytically—we determine an expression for the indefiniteintegral and then substitute the limits, or we apply an appropriate technique to find an expres-sion that relates the dependent and independent variables of the DE. The precise definition ofan analytic expression or solution is one that can be expressed in terms of a bounded number ofcertain elementary functions: constants (including complex numbers), one variable x, elementaryoperations of arithmetic (+−×÷), n-th roots, exponents (which includes trigonometric functionsand inverse trigonometric functions) and logarithms. However, we are often confronted with math-ematically posed problems that simply cannot be solved analytically, such as the transcendentalequation

sinx− 0.625x = 0 (1.1)

or the non-linear differential equation

dN

dt= aN − k(t)N1.7 (1.2)

both of which we shall revisit in later chapters. Problems which cannot be solved analytically aregenerally nonlinear in nature, which is clearly the case with these two equations.

The only hope we have of dealing with such problems is by finding a numerical solution. Inequation (1.1) this would be a numerical value for x that satisfies the equation; in equation (1.2) thenumerical solution is a set of numbers that represents the true solution over the relevant interval ofintegration. Numerical methods are the mathematical tools we use to find such numerical solutions.

1.1.1 Numerical analysis.

As the term suggests, numerical analysis is the mathematical study of numerical methods and, inthe broader sense, the analysis of the field of numerical methods as a whole. Numerical analysisaddresses the following:

(a) The derivation of numerical methods from fundamental mathematical ideas.

(b) Investigating the properties of numerical methods, such as accuracy and stability.

Numerical methods tend to be approximation techniques, i.e. they yield approximate solutionsrather than exact solutions. Through appropriate analysis of the method, we may understand thenature of the approximation error and we will probably be able to successfully implement themethod subject to a desired level of accuracy. If, through appropriate analysis of Consequently,the analysis of numerical methods is an extremely important part of the field.

5

Page 6: NUMERICAL ANALYSIS · 2015-10-21 · (a) Nonlinear algebraic equations in one variable - chapter 3 - we investigate the bisection method, linear interpolation, Newton’s method,

6 1. INTRODUCTION

1.1.2 Types of methods.

In these notes, we study the following methods:

(a) Nonlinear algebraic equations in one variable - chapter 3 - we investigate the bisectionmethod, linear interpolation, Newton’s method, and fixed-point iteration.

(b) Systems of linear equations - chapter 4 - we investigate the Jacobi method that can be usedto find numerical solutions to large systems of linear equations.

(c) Approximation of functions and data sets - chapter 5 - we investigate polynomial and La-grange interpolation, least-squares polynomial fitting, and Chebyshev series.

(d) Numerical differentiation - chapter 6 - Approximations to derivatives of various order usingTaylor series.

(e) Numerical integration (quadrature) - chapter 7 - we study the Trapezium and Simpsonmethods, based on Lagrange interpolation, used to approximate definite integrals.

(f) Initial-value problems - chapter 8 - Euler’s method, modified Euler method, Runge-Kuttamethods of orders two and four, used to approximate initial-value problems arising fromordinary differential equations.

We will devote our efforts to the derivation and error analysis of most of these methods, and wewill demonstrate the methods by means of numerical examples. Consequently, to a large extent,these notes are theoretical in nature.

1.2 Number representations and round-off errors

Numbers play an important part of numerical analysis (and mathematics in general with a wholefield dedicated to their study). We normally think of numbers as constant-valued entities and usethe numerals 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, and combinations thereof, to represent them, e.g. 2, 42, 5345,etcetera. A k-digit number is represented by using k numerals. It should be clear the k must be anatural number, and we refer to the number as a finite digit number. It is also quite possible for anumber to be a ∞-digit number, we simply refer to such a number as an infinitely digit number.The natural numbers, integers, and rational numbers may all be represented as finite digit numberswhile the irrational and real numbers are mostly infinite digit numbers. For example, 1 is a 1-digitnumber, 12 is a 2-digit number and 87543 is a 5-digit number.

1.2.1 Decimal number representation

In the study of numerical analysis, we might want to make use of a finite precision device, e.g. acalculator or computer, to perform computations. Finite precision devices tend to have limitedmemory and might only be able to store and represent finite digit numbers quite accurately. Dueto this memory constraint, there is a very specific way of representing numbers and using thesenumbers in computations within a finite precision environment.

Consider the mathematical constant π, which we know to be an irrational number and maybe represented as the fraction 22

7 . A finite precision device cannot interpret the meaning of thesymbol π and we rather make use of 22

7 in computations.We know that π can also be written as

3.14159265358979323846264338327950288419716939937510 . . .

We call this representation of the number the decimal representation or decimal form of the number.As another example, we know that we can represent 1

2 as 0.5. Most real numbers are representedthis way.

We define the normalised floating-point form of a number to be

± 0.d1d2 . . . dk × 10n, (1.3)

Page 7: NUMERICAL ANALYSIS · 2015-10-21 · (a) Nonlinear algebraic equations in one variable - chapter 3 - we investigate the bisection method, linear interpolation, Newton’s method,

1. INTRODUCTION 7

where di, called a decimal digit, is an integer-valued number with 1 ≤ d1 ≤ 9 and 0 ≤ di ≤ 9, foreach i = 2, 3, . . . , k. We call any number represented by (1.3) a k-digit decimal number. Thus, πin normalised decimal floating-point form is

0.314159265358979323846264338327950288419716939937510 . . .

and the normalised floating-point form of 18 , i.e. 0.125, which is a 3-digit decimal number.

Consider a positive real number y with the normalised floating-point form

y = 0.d1d2 . . . dkdk+1dk+2 . . .× 10n.

The finite floating-point form of y, which we denote fl(y), is obtained by terminating y after kdecimal digits. This termination is done in one of two ways. The first way, called truncation orchopping, is done by simply getting rid of the digits dk+1dk+2 . . . , which produces

fl(y) = 0.d1d2 . . . dk × 10n.

The second way, called rounding, is done by adding 5×10n−(k+1) to y and then chopping the resultto obtain the floating-point form

fl(y) = 0.δ1δ2 . . . δk × 10n.

When rounding, if dk+1 ≥ 5, we add 1 to dk to obtain fl(y), this is called rounding up; if dk+1 < 5,we simply chop off all the digits after the first k digits, this is called rounding down. It should beclear that rounding down yields δi = di for each i = 1, 2, 3, . . . , k, but this is not necessarily thecase when rounding up.

1.2.2 Error

Round-off error refers to errors in representing numbers in a finite precision environment. Forexample, we know that

π = 3.14159265358979323846264338327950288419716939937510...

but in most desktop computers we find that

π = 3.14159265358979.

In other words, due to memory constraints as mentioned earlier, the value of π is rounded off to 14decimal places. In a finite precision device this round-off process is applied to all numerical values,so that round-off error is present most of the time (an obvious exception is the integers, which donot have a fractional part). The digits lost in this rounding-off process constitute the round-offerror. By and large, we do not expect round-off error to significantly compromise calculationsperformed on a computer (round-off error is typically of the order of 10−15), although sometimesround-off errors may be amplified in the course of a computation. We generally find that theapproximation errors mentioned previously are far more significant than round-off error, and sowe restrict our study of error to approximation errors rather than round-off errors in these notes.Indeed, it is appropriate to regard approximation errors as a consequence of the mathematicalnature of the numerical method itself, whereas round-off errors may be seen as a technologicallimitation—the price we pay for using finite-precision devices.

Page 8: NUMERICAL ANALYSIS · 2015-10-21 · (a) Nonlinear algebraic equations in one variable - chapter 3 - we investigate the bisection method, linear interpolation, Newton’s method,

Chapter 2

SERIES EXPANSIONS

2.1 Introduction

Sequences and series play an important role in numerical analysis. For example, Newton’s method(see §3.4) generates a sequence of approximations to the root of a non-linear equation.

We review the theory of sequences and series and describe a useful power series that may beused to approximate functions about a given point.

2.2 Sequences

A sequence of real numbers is a function from the natural numbers N = {1, 2, . . .} onto the realnumbers R, i.e.

1 7→ x1

2 7→ x2

3 7→ x3

4 7→ x4

...

n 7→ xn

...

Thus f(n) = xn. The numbers x1, x2, x3, . . . , xn, . . . , in the range of the function, are called theelements or terms of the sequence. A sequence is called infinite if it has an infinite amount ofterms, otherwise it is called finite.

Example 2.1. Consider the following

1 7→√1

2 7→√2

3 7→√3

4 7→√4

...

8

Page 9: NUMERICAL ANALYSIS · 2015-10-21 · (a) Nonlinear algebraic equations in one variable - chapter 3 - we investigate the bisection method, linear interpolation, Newton’s method,

2. SERIES EXPANSIONS 9

This is indeed a sequence, because the numbers on the left are in N and the numbers on the rightare in some subset of R. We note that the sequence is generated by the function f(n) =

√n.

A sequence is denoted by its elements x1, x2, x3, . . . , or using the shorter notation (xn)∞n=1,

where n ∈ N. This latter notation is simplified to (xn) if clear from context that we are dealingwith an infinite or a finite sequence. Parentheses are deliberately used to emphasize the importanceof ordering in a sequence. If we consider the set {1, 2, 3, 4} and rewrite it as {4, 3, 2, 1}, then it isstill considered to be the same set. However, when we consider the sequence (1, 2, 3, 4) and rewriteit as (4, 3, 2, 1), then the two sequences are considered to be two different. Why are these two

sequences considered to be different from each other?

Most often a sequence is defined by giving a formula for its nth term xn. For example, considerthe sequence of reciprocals of the odd numbers

(

1,1

3,1

5,1

7, . . .

)

.

This sequence may be written as(

1

2n+ 1: n ∈ N

)

or more simply

xn =1

2n+ 1,

where it is understood that n ∈ N. Another way of defining a sequence is to specify the value forx1 and giving a formula for xn+1 in terms of xn, the sequence is then said to be defined recursively

or inductively.

Example 2.2. Consider the Fibonacci sequence F = (fn) given by

1, 1, 2, 3, 5, 8, 13, 21, . . .

If we specify f1 = 1 and f2 = 1, then we may give the recursion formula for every other term inthe sequence as fn+1 = fn + fn−1, where n ≥ 2.

The limit of a sequence (xn) is the real number ℓ such that

limn→∞

xn = ℓ (2.1)

A sequence (xn) is called convergent if its limit ℓ exists; if this limit does not exist, then thesequence is called divergent. It should be noted that the limit of a sequence is unique. Given twosequences (xn) and (yn) such that limn→∞ xn = ℓ1 and limn→∞ yn = ℓ2, then

limn→∞

(xn ± yn) = ℓ1 ± ℓ2

limn→∞

(cxn) = cℓ1, c ∈ R

limn→∞

(xnyn) = ℓ1ℓ2

limn→∞

(xn

yn

)

=ℓ1ℓ2, yn 6= 0 and ℓ2 6= 0

limn→∞

(xn)(yn) = xy, x > 0 and xn > 0

There are numerous other useful limit theorems and the reader is referred to consult an analysistext.

Page 10: NUMERICAL ANALYSIS · 2015-10-21 · (a) Nonlinear algebraic equations in one variable - chapter 3 - we investigate the bisection method, linear interpolation, Newton’s method,

10 2. SERIES EXPANSIONS

Example 2.3. Consider the sequence(1n

). If n → ∞ then 1

n → 0 and thus

limn→∞

(1

n

)

= 0.

Hence 0 is the limit of the sequence.

A sequence (xn) is bounded if there exists numbers a, b ∈ R such that a < xn < b for all n ∈ N.The number a is called the lower bound of the sequence and the number b is called the upperbound of the sequence.

Example 2.4. Consider the sequence of even, positive integers (2, 4, 6, 8, . . . ). It should notbe difficult to see that the number 1 is a lower bound of this sequence. Next we consider thesequence of reciprocals of the even, positive integers

(12 ,

14 ,

16 ,

18 , . . .

). In this case, the number 1

is the upper bound of the sequence.

A sequence (xn) is called increasing if

x1 ≤ x2 ≤ x3 ≤ · · · ≤ xn ≤ xm ≤ · · ·

for all n < m and n,m ∈ N. Similarly, the sequence (xn) is called decreasing if

x1 ≥ x2 ≥ x3 ≥ · · · ≥ xn ≥ xm ≥ · · ·

for all n < m and n,m ∈ N. A sequence (xn) is called monotone if it is increasing or decreasing.It can be shown that a monotonic sequence is convergent if and only if it is bounded.

Example 2.5. A ball, with diameter ǫ, is dropped from a height h0. Each time it drops hmetres, it rebounds rh metres. Determine how many times the ball bounces before it stopsmoving.

Solution: We note that if the initial height was h0, then after the first bounce the ball willreach a height of h1 = rh0, the height after the second bounce would be h2 = rh1, and after nbounces the height would be hn = rhn−1. But it follows that

hn = rhn−1 = r(rhn−2

)= r2hn−2 = · · ·

and we conclude that hn = rnh0. Clearly, the bounces of the ball form a recursive sequence.The ball stops bouncing when |hn| ≤ ǫ. Since hn = rnh0, it follows that

rnh0 ≤ ǫ

rn ≤ ǫ

h0

n ln(r) ≤ ln

h0

)

∴ n ≥ ln(ǫ)− ln(h0)

ln(r)

If h0 = 8m, r = 0.7 and ǫ = 0.07m, then we find n ≥ 13.2858 and we conclude that it wouldtake 14 bounces before the balls stops.

Page 11: NUMERICAL ANALYSIS · 2015-10-21 · (a) Nonlinear algebraic equations in one variable - chapter 3 - we investigate the bisection method, linear interpolation, Newton’s method,

2. SERIES EXPANSIONS 11

2.3 Series

Informally, a series is the sum of the terms of a sequence. If we let (xn) be a sequence, then sumof the first k terms of this sequence, i.e.

sk = x1 + x2 + · · ·+ xk =

k∑

i=1

xi, k ≤ n

is called the kth partial sum of the sequence. Note that the partial sums form a sequence bythemselves, i.e.

s1 = x1

s2 = s1 + x2 (= x1 + x2)

s3 = s2 + x3 (= x1 + x2 + x3)

...

sn = sn−1 + xn (= x1 + x2 + x3 + · · ·+ xn−1 + xn)

...

This pair of sequences((xn), (sn)

)is called the series generated by the sequence (xn). The numbers

xi, i = 1, 2, . . . , n, in the partial sums are called the terms of the sequence. A series is called infinite

if it has an infinite amount of terms, otherwise it is called finite if it has a finite amount of terms.Instead of writing

((xn), (sn)

)every time to denote a series generated by (xn), it is convention

to use the notationn∑

i=1

xi = x1 + x2 + x3 + · · ·+ xn

if dealing with a finite series; for an infinite series one would similarly have

∞∑

i=1

xi = x1 + x2 + x3 + · · · .

The symbol Σ is the Greek letter sigma, and one often refers to the notation above as “sigma-notation”. When clear from context whether we are dealing with a finite or infinite series, thesigma-notation is shortened to

i xi.Let

∑∞i=1 xi be a series. If the sequence (sn) of partial sums of this series converges to the

limit s, then the series is called convergent and the limit s is called the sum of the series. The sumis denoted

s =

∞∑

i=1

xi

If this limit does not exist, then the series is said to be divergent.

Example 2.6. Consider the series∑∞

i=1 c, where c ∈ R is a constant. Clearly this infinite seriesdoes not have a sum and thus is divergent. However, if we were to consider the finite series∑n

i=1 c, then it should be clear that this series does have a sum and is convergent. The sum isnone other than s = nc.

Two very important questions arise when studying series.

1. Does the series converge or diverge?

2. What is the sum of the series if it is convergent?

Page 12: NUMERICAL ANALYSIS · 2015-10-21 · (a) Nonlinear algebraic equations in one variable - chapter 3 - we investigate the bisection method, linear interpolation, Newton’s method,

12 2. SERIES EXPANSIONS

Example 2.7. Given the infinite series

∞∑

i=0

ari = a+ ar + ar2 + ar3 + · · ·+ ari + · · · , (2.2)

where a ∈ R is a non-zero constant.Consider the nth partial sum sn = a + ar + ar2 + · · · + arn. If we multiply sn by r and

subtract the result from sn, then we obtain

sn − rsn = (a+ ar + ar2 + · · ·+ arn)− r(a+ ar + ar2 + · · ·+ arn)

= a+ ar + ar2 + · · ·+ arn − ar − ar2 − · · · − arn+1

= a− arn+1

sn(1− r) = a(1− rn+1)

and therefore

sn =a(1− rn+1)

1− r.

If 0 < |r| < 1, then the term rn+1 → 0 as n → ∞ and we obtain the sum of the geometric series(2.2) as

s =a

1− r. (2.3)

The series (2.2) is called a geometric series.

A simpler way of determining whether a series converges or diverges is to make use of thefollowing theorem:

Theorem 2.1 (Ratio Test). The series∑∞

n=0 an converges if

limn→∞

∣∣∣∣

anan−1

∣∣∣∣< 1

and diverges if

limn→∞

∣∣∣∣

anan−1

∣∣∣∣> 1.

If this limit is equal to 1, then we cannot conclude anything about the convergence or divergenceof the series.

Example 2.8. Let us reconsider the geometric series (2.2). By the ratio test, we now have

∣∣∣∣

xn

xn−1

∣∣∣∣=

∣∣∣∣

arn

arn−1

∣∣∣∣= |r|

and thus we require |r| < 1 for convergence. This concurs with our earlier analysis in example2.7.

2.4 Taylor series expansions

From analysis it is known that a continuous function may be approximated by finite or infiniteseries, and these approximations are normally done by power series expansions. A power series is

Page 13: NUMERICAL ANALYSIS · 2015-10-21 · (a) Nonlinear algebraic equations in one variable - chapter 3 - we investigate the bisection method, linear interpolation, Newton’s method,

2. SERIES EXPANSIONS 13

an infinite series of the form∞∑

i=0

aixi = a0 + a1x+ a2x

2 + · · ·+ anxn + · · · (2.4)

Example 2.7 is a special case of a power series. In the following sections we shall discuss a veryuseful power series expansion—the Taylor series expansion of a function—which is a powerfulanalytical and numerical tool in applied mathematics and is used extensively in later chapters.

2.4.1 Taylor’s Theorem (1715)

We consider a function f that has continuous derivatives up to (n+1)th order on an interval [a, b].From the fundamental theorem of calculus we have

f(b) = f(a) +

∫ b

a

f ′(x) dx.

Repeated integration by parts yields

f(b) = f(a) + (x− b)[f ′(x)

]b

a+

∫ b

a

(x − b)f ′′(x) dx

= f(a) + (b − a)f ′(a) +

[(b − x)2

2f ′′(x)

]b

a

+

∫ b

a

(b − x)2

2f ′′′(x) dx

= f(a) + (b − a)f ′(a) +(b − a)2

2!f ′′(a)

+

[

− (b− x)3

2× 3f ′′′(x)

]b

a

+

∫ b

a

(b− x)3

2× 3f (4)(x) dx

= f(a) + (b − a)f ′(a) +(b − a)2

2!f ′′(a)

+(b − a)3

3!f ′′′(a) +

∫ b

a

(b − x)3

3!f (4)(x) dx

After n steps we have Taylor’s Theorem:

f(b) = f(a) + (b − a)f ′(a) + · · ·+ (b− a)n

n!f (n)(a) +Rn

Rn =

∫ b

a

(b− x)n

n!f (n+1)(x) dx

With the substitutions b → x, a → x0, x → t we obtain the more familiar form

f(x) = f(x0) + (x− x0)f′(x0) + · · ·+ (x− x0)

n

n!f (n)(x0) +Rn

Rn =

∫ x

x0

(x− t)n

n!f (n+1)(t) dt

(2.5)

We refer to Rn as the residual term.

2.4.2 Taylor series

Consider a function f for which derivatives of all orders exist at x0. In other words, we may write(2.5) for arbitrary n. The power series in (x− x0) on the right-hand side of (2.5) will converge toa finite value if lim

n→∞Rn = 0. Hence, we may expand f(x) then as an infinite power series:

f(x) =

∞∑

n=0

(x− x0)n

n!f (n)(x0) (2.6)

The convergence, or lack thereof, of the series (2.6) may be investigated by means of estimates ofRn. Cauchy and Lagrange have given estimates for the residual term (see §2.4.3), but we couldalso make use of theorem 2.1.

Page 14: NUMERICAL ANALYSIS · 2015-10-21 · (a) Nonlinear algebraic equations in one variable - chapter 3 - we investigate the bisection method, linear interpolation, Newton’s method,

14 2. SERIES EXPANSIONS

Example 2.9. We want to write f(x) = ex as an infinite power series. Since ex and all itsderivatives exist at x = 0, we choose x0 in (2.6). Then

f(x) = ex f(0) = 1

f ′(x) = ex f ′(0) = 1

......

f (n)(x) = ex f (n)(0) = 1

and so

ex =

∞∑

n=0

xn

n!= 1 + x+

x2

2!+

x3

3!+ · · ·

We investigate the convergence of this series using theorem 2.1:

ex =∞∑

n=0

an an =xn

n!

Hence ∣∣∣∣

anan−1

∣∣∣∣=

(xn

n!

)/(xn−1

(n− 1)!

)

=x

n

so that ∣∣∣∣

anan−1

∣∣∣∣=

|x|n

→ 0 as n → ∞

Thus, this series converges for all values of x.

Example 2.10. We obtain the so-called binomial expansion by determining the Taylor seriesof f(x) = (1 + x)p for all real values of p. Let x0 = 0. Then

f(x) = (1 + x)p f(0) = 1

f ′(x) = p(1 + x)p−1 f ′(0) = p

f ′′(x) = p(p− 1)(1 + x)p−2 f ′′(0) = p(p− 1)

......

f (n) = p(p− 1) · · · (p− n+ 1)(1 + x)p−n f (n)(0) = p(p− 1) · · · (p− n+ 1)

and so

(1 + x)p =

∞∑

n=0

(p

n

)

xn (2.7)

where (p

n

)

=p (p− 1) · · · (p− n+ 1)

n!

are called the binomial coefficients. We note that(p0

)= 1.

A special case is p = 12 , e.g.

(1 + x)1

2 = 1 +1

2x+

(12

) (− 1

2

)

2!x2 + · · ·

= 1 +1

2x− 1

8x2 + · · ·

Page 15: NUMERICAL ANALYSIS · 2015-10-21 · (a) Nonlinear algebraic equations in one variable - chapter 3 - we investigate the bisection method, linear interpolation, Newton’s method,

2. SERIES EXPANSIONS 15

We use theorem 2.1 to test the convergence of this series. From (2.7) the series has the form

(1 + x)p =

∞∑

n=0

an

with

an =p(p− 1) · · · (p− n+ 1)

n!xn.

Hence

anan−1

=p(p− 1) · · · (p− n+ 2)(p− n+ 1)xn

(1)(2) · · · (n− 1)n× (1)(2) · · · (n− 1)

p(p− 1) · · · (p− n+ 2)xn−1

and so ∣∣∣∣

anan−1

∣∣∣∣=

∣∣∣∣

(p− n+ 1)x

n

∣∣∣∣=

∣∣∣∣

p+ 1

n− 1

∣∣∣∣|x| .

Clearly∣∣∣

an

an−1

∣∣∣→ |x| as n → ∞, and so this series converges only if |x| < 1.

Example 2.11. Find ex to an accuracy of ǫ. We calculate here the series

1 + x+x2

2!+ · · ·+ xN

N !,

where the Nth term is the first one for which∣∣∣xN

N !

∣∣∣ < ǫ. A numerical complication that arises is

that 69! ≈ 10100 and that n! cannot be evaluated using a pocket calculator for n ≥ 70. Insteadwe make use of the recursion relation (from example 2.9)

a0 = 1 an =(x

n

)

an−1 n > 0

We obtain e1 = 2.718282 with 10 terms. Note the required accuracy: ǫ = 10−6, therefore six

decimal places are shown.

2.4.3 Lagrange estimate of the error term

Lagrange obtained an estimate of the error term Rn in (2.5) which is very useful for analyticalpurposes. The generalized mean-value theorem for integral calculus allows us to write the residualterm as

Rn = f (n+1)(ξx)

∫ x

x0

(x− t)n

n!dt

where x0 < ξx < x. The integral in the residual term is now easily determined to be

Rn = f (n+1) (ξx)

[−1

n!× (x − t)n+1

(n+ 1)

]x

x0

=(x− x0)

n+1

(n+ 1)!f (n+1) (ξx) .

The series in (2.5) now becomes

f(x) = f(x0) + (x− x0)f′(x0) + · · ·

+(x − x0)

n

n!f (n)(x0) +

(x− x0)n+1

(n+ 1)!f (n+1)(ξx).

(2.8)

It is often useful to define x = x0 + h. Then (2.8) becomes

f(x0 + h) = f(x0) + hf ′(x0) + · · ·

+hn

n!f (n)(x0) +

hn+1

(n+ 1)!f (n+1)(ξx)

(2.9)

Page 16: NUMERICAL ANALYSIS · 2015-10-21 · (a) Nonlinear algebraic equations in one variable - chapter 3 - we investigate the bisection method, linear interpolation, Newton’s method,

16 2. SERIES EXPANSIONS

where x0 < ξ < x0 + h.

2.4.4 Expansion of multivariable functions

If a function is dependent on more than one variable, we use consecutive Taylor expansions withrespect to each of the variables. Since all other variables are held constant while expanding withrespect to a particular variable, all derivatives in the expansion are partial. Here, we expand afunction of two variables. We consider f(x0 + h, y0 + k) and use (2.9) to obtain an expansion withrespect to x (holding y constant) and then we expand each term of this expansion with respect toy (holding x constant), i.e.

f(x0 + h, y0 + k) = f(x0, y0 + k) + h∂f

∂x

∣∣∣∣(x0,y0+k)

+h2

2!

∂2f

∂x2

∣∣∣∣(x0,y0+k)

+ · · ·

= f(x0, y0) + k∂f

∂y

∣∣∣∣(x0,y0)

+k2

2!

∂2f

∂y2

∣∣∣∣(x0,y0)

+ · · ·

+∂

∂y

(

h∂f

∂x

∣∣∣∣(x0,y0+k)

+h2

2!

∂2f

∂x2

∣∣∣∣(x0,y0+k)

+ · · ·)

= f(x0, y0) + k∂f

∂y

∣∣∣∣(x0,y0)

+k2

2!

∂2f

∂y2

∣∣∣∣(x0,y0)

+ · · ·

+ h

(∂f

∂x

∣∣∣∣(x0,y0)

+ k∂2f

∂y∂x

∣∣∣∣(x0,y0)

+ · · ·)

+h2

2!

(∂2f

∂x2

∣∣∣∣(x0,y0)

+∂3f

∂y∂x2

∣∣∣∣(x0,y0)

· · ·)

+ · · ·

= f(x0, y0) +

(

h∂f

∂x

∣∣∣∣(x0,y0)

+ k∂f

∂y

∣∣∣∣(x0,y0)

)

+

(

h2

2!

∂2f

∂x2

∣∣∣∣(x0,y0)

+ hk∂2f

∂y∂x

∣∣∣∣(x0,y0)

+k2

2!

∂2f

∂y2

∣∣∣∣(x0,y0)

)

+ · · ·

and in summary

f(x0 + h, y0 + k) =∞∑

n=0

∞∑

m=0

hnkm

n!m!

∂n+mf

∂xn∂ym

∣∣∣∣(x0,y0)

.

The series for a function of more than two variables is analogous.

Page 17: NUMERICAL ANALYSIS · 2015-10-21 · (a) Nonlinear algebraic equations in one variable - chapter 3 - we investigate the bisection method, linear interpolation, Newton’s method,

Chapter 3

NONLINEAR EQUATIONS

3.1 Introduction

Generally speaking, nonlinear equations and, in particular, so-called transcendental equations,cannot be solved analytically, and so may only be solved numerically. We consider the solutionof nonlinear equations in one variable, although we briefly describe a method for a system of twononlinear equations at the end of this chapter.

3.2 The bisection method

Consider the equation f(x) = 0, where f is assumed to be continuous. By the intermediate valuetheorem, if an interval [x1, x2] can be found on which f changes sign, i.e.

f(x1)f(x2) < 0,

then f has at least one real root on the interval.Assume that f has only one root on [x1, x2], denote this root as x0. The interval is now halved

by determining

x3 =x1 + x2

2.

This value x3 may be regarded as an approximation to x0. The approximation may be improvedby iterating (repeating) the halving process. At each iteration there are two possibilities:

(a) f(x1)f(x3) < 0. The root thus lies on [x1, x3], and x2 is replaced by x3.

(b) f(x3)f(x2) < 0. The root lies on [x3, x2], and x1 is replaced by x3.

The halving process is iterated until a specified accuracy ǫ in the function value is reached, that is

|f(x3)| < ǫ. (3.1)

Convergence. Since any curve on a small enough interval may be approximated by a straightline, we have that f(x3) will converge to f(x0), in the vicinity of x0, at the same rate that

η = |x0 − x3|

converges to zero. For the nth iteration we have

ηn ≈ ηn−1

2.

The bisection method is thus said to be linearly convergent.

17

Page 18: NUMERICAL ANALYSIS · 2015-10-21 · (a) Nonlinear algebraic equations in one variable - chapter 3 - we investigate the bisection method, linear interpolation, Newton’s method,

18 3. NONLINEAR EQUATIONS

Example 3.1. Solve f(x) = sinx−0.625x = 0 to an accuracy of 8 decimal places in the functionvalue.

We show the values for the first four iterations in the following table:

iteration x1 x3 x2 f(x1) f(x3) f(x2)

1 1 1.5 2 +0.216 +0.060 −0.3412 1.5 1.75 2 +0.060 −0.110 −0.3413 1.5 1.625 1.75 +0.060 −0.171 −0.1104 1.5 1.5625 1.625 +0.060 +0.023 −0.171

After 25 iterations we findx = 1.59934789 rad (91.635884◦)

3.3 Linear interpolation

Although the bisection method is reliable, it is also slow. This is because very little informationabout f(x) is used—indeed, only the sign of f is used. In the linear interpolation method we alsomake use of the numerical values of f(x).

Consider the equation f(x) = 0. Let (x1, y1) and (x2, y2) be two points on the curves y = f(x)in the vicinity of the root x = x0. We approximate the curve in this region by a straight line throughthe two points. The zero point x3 of the straight line may be regarded as an approximation to theroot x0.

The value of x3 is obtained from the equation for the straight line

y − y1 =

(y2 − y1x2 − x1

)

(x− x1).

The point (x3, 0) lies on this line so that

0− y1 =

(y2 − y1x2 − x1

)

(x3 − x1)

and so

x3 =x1y2 − x2y1

y2 − y1.

The interpolation process is now iterated by finding the straight line through (x2, y2) and (x3, y3)and hence the approximation x4, and so on. In general, the (i − 1)th iteration uses (xi−1, yi−1)and (xi, yi) to find xi+1:

xi+1 =xi−1yi − xiyi−1

yi − yi−1. (3.2)

For a given accuracy ǫ this process is repeated until the condition (3.1) is satisfied.

Convergence. Let the error in x after the (i−1)th iteration be denoted by ηi. In other words,xi = x0 + ηi. Then from equation (3.2) it follows that

x0 + ηi+1 =(x0 + ηi−1)yi − (x0 + ηi)yi−1

yi − yi−1

and so

ηi+1 =ηi−1f(x0 + ηi)− ηif(x0 + ηi−1)

f(x0 + ηi)− f(x0 + ηi−1).

Each function may be expanded in a Taylor series about x0:

f(x0 + ηi) = f(x0) + ηif′(x0) +

1

2η2i f

′′(x0) + · · ·

= 0 + ηif′(x0) +

1

2η2i f

′′(x0) + · · ·

Page 19: NUMERICAL ANALYSIS · 2015-10-21 · (a) Nonlinear algebraic equations in one variable - chapter 3 - we investigate the bisection method, linear interpolation, Newton’s method,

3. NONLINEAR EQUATIONS 19

We assume that f ′(x0) 6= 0 and f ′′(x0) 6= 0. Since ηi is small (by assumption) we have, to thelowest order in ηi

ηi+1 ≈ ηi−1

[ηif

′(x0) +12η

2i f

′′(x0)]− ηi

[ηi−1f

′(x0) +12η

2i−1f

′′(x0)]

ηif ′(x0)− ηi−1f ′(x0)

=1

2

(ηiηi−1 (ηi − ηi−1) f

′′(x0)

(ηi − ηi−1) f ′(x0)

)

=

(f ′′(x0)

2f ′(x0)

)

ηiηi−1

≡ Aηiηi−1, where A is a constant. (3.3)

We attempt to satisfy this relationship by assuming

ηi = Kηai−1 ⇐⇒ ηi+1 = Kηai

where K is some constant, so that, from (3.3), we have

ηi+1 ≈ Aηi

(1

Kηi

) 1

a

.

But

ηi+1 = Kηai

from our earlier assumption, and since the powers of ηi must be the same on both sides of theequation, it follows that

1 +1

a= a

which gives

a2 − a− 1 = 0

which has the root

a =1 +

√5

2≈ 1.618

which is the also called the golden mean number. Hence

ηi+1 ≈ Kη1.618i .

This rate of convergence is termed superlinear. (The other root a ≈ −0.62 corresponds to diver-gence.)

Example 3.2. Solve f(x) = sinx − 0.625x = 0 accurate to 8 decimal places in the functionvalue.

The values for the first 3 iterations are shown in the following table.

i xi xi+1 yi yi+1 xi+2 yi+2

1 1 2 0.2165 −0.3407 1.3885 0.11562 2 1.3885 −0.3407 0.1156 1.5434 0.03503 1.3885 1.5434 0.1156 0.0350 1.6106 −0.0074

After 6 iterations we obtain x0 = 1.59934789 rad (compare with 25 iterations for the bisectionmethod).

Page 20: NUMERICAL ANALYSIS · 2015-10-21 · (a) Nonlinear algebraic equations in one variable - chapter 3 - we investigate the bisection method, linear interpolation, Newton’s method,

20 3. NONLINEAR EQUATIONS

3.4 Newton’s method

For this method we assume that f is at least twice differentiable. We now use both the values f(x)and its first derivative to solve f(x) = 0. Let x1 be an initial estimate of the root x0, and draw atangent line at the point (x1, f(x1)) to the curve of f . The x-intercept of the tangent line, denoteit x2, is presumably a better estimate of x0 than x1 was. The slope of the tangent line is f ′(x1)and is determined by

f ′(x1) =f(x2)− f(x1)

x2 − x1.

However, since x2 is the x-intercept of the tangent line, we have f(x2) = 0 and thus

f ′(x1) =f(x1)

x1 − x2.

Solving this last equation for x2 we obtain

x2 = x1 −f(x1)

f ′(x1).

This process can be repeated and we find, in general, after the ith iteration we have

xi+1 = xi −f(xi)

f ′(xi). (3.4)

Note: The above result could also have been obtained by calculating the error η for an initialestimate x1 by solving

f(x1 + η) = 0.

We expand the LHS in a Taylor series about x = x1

f(x1) + ηf ′(x1) +η2

2!f ′′(x1) + · · · = 0.

For small η, f(x1) + ηf ′(x1) ≈ 0 and so

η ≈ − f(x1)

f ′(x1).

Newton’s method is thus equivalent to a first-order Taylor expansion of the function f(x).

Convergence. Let the error in x after the ith iteration be denoted by ηi. In other words,xi = x0 + ηi. From equation (3.4)

x0 + ηi+1 = x0 + ηi −f(x0 + ηi)

f ′(x0 + ηi).

A Taylor expansion about x = x0 for both f(x0 + ηi) and f ′(x0 + ηi) gives

ηi+1 = ηi −f(x0) + ηif

′(x0) +12η

2i f

′′(x0) + · · ·f ′(x0) + ηif ′′(x0) + · · · .

Expanding the denominator using

1

1 + x= 1− x+ x2 − x3 + · · ·

we find

1

f ′(x0) + ηif ′′(x0) +O(η2i )=

1

f ′(x0)(

1 + ηif ′′(x0)f ′(x0)

+O(η2i ))

=1

f ′(x0)

1

1 + ηif ′′(x0)f ′(x0)

+O(η2i )

=1

f ′(x0)

(

1− ηif ′′(x0)

f ′(x0)+O(η2i )

)

Page 21: NUMERICAL ANALYSIS · 2015-10-21 · (a) Nonlinear algebraic equations in one variable - chapter 3 - we investigate the bisection method, linear interpolation, Newton’s method,

3. NONLINEAR EQUATIONS 21

To lowest order in η we have

ηi+1 ≈ ηi −1

f ′(x0)

(

1− ηif ′′(x0)

f ′(x0)

)(

0 + ηif′(x0) +

η2i2f ′′(x0)

)

≈(f ′′(x0)

2f ′(x0)

)

η2i . (3.5)

The convergence is said to be quadratic.

It is important to note that (3.3) and (3.5) give estimates for the convergence rate only if

convergence actually occurs. It is possible that both the linear interpolation method and Newton’smethod may diverge.

Example 3.3. Find the root of f(x) = sinx − 0.625x = 0 correct to 8 decimal places in thefunction value.

Equation (3.4) is iterated using

f(x) = sinx− 0.625x

andf ′(x) = cosx− 0.625

with an initial estimate x = 1.5. The results of the process are shown in the following table:

i xi f(xi) f ′(xi) ∆xi = − f(xi)f ′(xi)

1 1.5 0.060 −0.554 0.1082 1.608 −0.0059 −0.662 −0.008843 1.59941 −3.9× 10−5 −0.654 −6.0× 10−5

4 1.59934789 −2.1× 10−9

After 4 iterations the root x = 1.59934789 rad is found.

Calculation hints

(a) Sometimes f ′ is a cumbersome analytical expression. In such cases f ′ may be estimatednumerically by

f ′(xi) ≈f(xi + h)− f(xi)

h

where h is small. One should be aware of complications that may arise from numericaldifferentiation (see chapter 6 for better approximations. Linear interpolation is indeedNewton’s method with simple numerical differentiation).

(b) When f(x) = 0 has more than one root, it is sometimes found that both linear interpolationand Newton’s method converge to the same root, for any initial estimate. Say x0 is such aroot. Then we may write

f(x) = (x − x0)g(x).

Once the root x0 is found, it may be eliminated from the problem by subsequently solving

g(x) =f(x)

x− x0.

3.5 Fixed-point iteration

If an equation can be written in the form

x = g(x) (3.6)

Page 22: NUMERICAL ANALYSIS · 2015-10-21 · (a) Nonlinear algebraic equations in one variable - chapter 3 - we investigate the bisection method, linear interpolation, Newton’s method,

22 3. NONLINEAR EQUATIONS

then a root of the equation may be regarded as a fixed point that is mapped to itself under themap x = g(x). The iteration process

xi+1 = g(xi) (3.7)

may then be used, possibly, to find the root.

Example 3.4. Find the positive root of x = 2 sinx correct to 8 decimal places.The following table shows 6 iterations of (3.7) with g(x) = 2 sinx, using initial value x = 2:

i xi g(xi)

1 2 1.822 1.82 1.943 1.94 1.874 1.87 1.915 1.91 1.886 1.88 1.90

The required accuracy is actually achieved after 39 iterations and we find x0 = 1.89549427.

A transcendental equation of the form (3.6) can often be written in this form in several ways.For example, ex = 3x2 may be written as

x = ln 3x2

or

x = ±√

ex

3.

Convergence. We now obtain an analytical condition for convergence. Consider the error inx after the ith iteration,

xi+1 − x0 = g(xi)− g(x0)

where x0 is the root of (3.6). From the mean-value theorem of differential calculus we have

g(xi)− g(x0)

xi − x0= g′(ξi)

where x0 < ξi < xi. We can thus rewrite the ith error as

xi+1 − x0 = g′(ξi)(xi − x0).

Iterating this recursion relation i times gives

xi+1 − x0 = g′(ξi)g(ξi−1) · · · g′(ξ1)(x1 − x0).

Now let

m = max (|g′(ξi)|) .

Then we have

|xi+1 − x0| ≤ mi |x1 − x0| .

For convergence we must have that |xi+1 − x0| → 0 as i → ∞, which will only be true if m < 1.

Page 23: NUMERICAL ANALYSIS · 2015-10-21 · (a) Nonlinear algebraic equations in one variable - chapter 3 - we investigate the bisection method, linear interpolation, Newton’s method,

3. NONLINEAR EQUATIONS 23

Condition for convergence: For the iteration scheme (3.7) to converge, we require

|g′(x)| < 1 (3.8)

in the neighbourhood of the root.

Example 3.5. We investigate the convergence for the case in example 3.4.For x = g(x) = 2 sinx we have g′(x) = 2 cosx. Hence, for convergence we require

|cosx| < 1

2

and so we obtain an interval of convergence

1.047 < x < 2.094

The root x0 = 1.895 indeed lies on this interval.

Note: Condition (3.8) may be applied to any iterative method that can be written in the form(3.6). Newton’s method may be written as x = g(x) with

g(x) = x− f(x)

f ′(x)

and so

g′(x) = 1−(f ′(x)

)2 − f(x)f ′′(x)(f ′(x)

)2 .

Then we must have ∣∣∣∣∣

f(x)f ′′(x)(f ′(x)

)2

∣∣∣∣∣< 1

in the neighbourhood of the root.

3.6 Systems of nonlinear equations

We describe Newton’s method for two simultaneous nonlinear equations. The extension to systemsof more than two equations can be found in most standard texts.

Consider two equations in unknowns x and y:

f1(x, y) = 0

f2(x, y) = 0(3.9)

As for the one-dimensional Newton’s method, we try to find the corrections (ηx, ηy) to an initialguess (x1, y1) such that (3.9) is satisfied:

f1(x1 + ηx, y1 + ηy) = 0

f2(x1 + ηx, y1 + ηy) = 0

A first-order Taylor expansion yields

f1(x1, y1) + ηx

(

∂f1∂x

∣∣∣∣(x1,y1)

)

+ ηy

(

∂f1∂y

∣∣∣∣(x1,y1)

)

≈ 0

f2(x1, y1) + ηx

(

∂f2∂x

∣∣∣∣(x1,y1)

)

+ ηy

(

∂f2∂y

∣∣∣∣(x1,y1)

)

≈ 0

Page 24: NUMERICAL ANALYSIS · 2015-10-21 · (a) Nonlinear algebraic equations in one variable - chapter 3 - we investigate the bisection method, linear interpolation, Newton’s method,

24 3. NONLINEAR EQUATIONS

which may be written as

[∂f1∂x

∂f1∂y

∂f2∂x

∂f2∂y

]

(x1,y1)

[ηxηy

]

≈[−f1(x1, y1)−f2(x1, y1)

]

so that[ηxηy

]

[∂f1∂x

∂f1∂y

∂f2∂x

∂f2∂y

]

(x1,y1)

−1[−f1(x1, y1)−f2(x1, y1)

]

The square matrix here is known as a Jacobian matrix, and is evaluated at the point (x1, y1).

Page 25: NUMERICAL ANALYSIS · 2015-10-21 · (a) Nonlinear algebraic equations in one variable - chapter 3 - we investigate the bisection method, linear interpolation, Newton’s method,

Chapter 4

SYSTEMS OF LINEAREQUATIONS

4.1 Introduction

In this chapter we consider the numerical solution of a system of linear equations. The numericalmethod we describe is an iterative one, known as the Jacobi method.

4.2 Solvability

Consider m equations in n unknowns

a11x1 + a12x2 + · · ·+ a1nxn = b1

a21x1 + a22x2 + · · ·+ a2nxn = b2

...

am1x1 + am2x2 + · · ·+ amnxn = bm

which have the matrix representationAx = b. (4.1)

From linear algebra the following is known regarding the solution of (4.1):

(a) Generally, there are no solutions if m > n.

(b) Generally, there are infinitely many solutions if m < n.

(c) If m = n then A is a square matrix and possibly solvable.

4.3 Cramer’s rule

For m = n we define D = detA. Cramer’s rule differentiates between three cases:

(a) If D = 0 and b 6= 0 then, in general, there are no solutions.

(b) If b = 0 and D 6= 0 then there is only the trivial solution x = 0. Thus, a necessary conditionfor nontrivial solutions, if b = 0, is that D = 0.

(c) The general case is when D 6= 0 and b 6= 0. From Cramer’s rule it follows that if Dj is thedeterminant obtained when the jth column of A is replaced by b, then the solution is givenby

xj =Dj

Dj = 1, 2, . . . , n. (4.2)

25

Page 26: NUMERICAL ANALYSIS · 2015-10-21 · (a) Nonlinear algebraic equations in one variable - chapter 3 - we investigate the bisection method, linear interpolation, Newton’s method,

26 4. SYSTEMS OF LINEAR EQUATIONS

Determining (4.2) is equivalent to inverting the matrix equation (4.1), i.e.

x = A−1b.

In practice (4.2) is not used because of the large amount of computational effort required: it canbe shown that (n − 1)n! multiplications and n!− 1 additions are needed, which is approximatelynn! arithmetical operations in all.

4.4 The Jacobi method

If the diagonal elements aii of A are all nonzero, then we may implement an iterative technique tosolve (4.1)), known as the Jacobi method.

LetA = D+ L+ U

where D is the matrix of diagonal entries of A, L is the lower triangular part of A, and U is theupper triangular part of A. This gives

Ax = (D+ L+ U)x

= Dx+ (L+ U)x = b

so thatx = D

−1(b− (L+ U)x

)(4.3)

provided that aii 6= 0. Note that the computation of D−1 is straightforward; since D is a diagonalmatrix, its inverse is obtained simply by taking the reciprocal of its elements (this requires no morethan n arithmetical operations). Equation (4.3) suggests the iteration scheme

x(k) = D−1(b− (L+ U)x(k−1)

), k = 0, 1, 2, . . . (4.4)

where k denotes the iteration count. Clearly, the implementation of this method requires aninitial guess x(0). It is interesting to note that (4.4)) is a form of fixed-point iteration, as seenin the previous chapter, although here it is of a multivariable nature (those variables being thecomponents xi of x).

It can be shown that convergence to the exact solution x is guaranteed provided

|aii| >n∑

j=1i6=j

|aij | (4.5)

for i = 1, 2, . . . , n. In other words, on each row, the magnitude of the diagonal element must exceedthe sum of the magnitudes of all the other elements on that row, and this must hold for all rows inA. An indication of the quality of the approximate solution x(k) may be determined by computingthe residual

r(k) = Ax(k) − b

and the iteration process is stopped when the magnitude of r(k) is less than some imposed tolerance.It can be shown that the Jacobi method requires about n2 arithmetical operations per iteration;

in comparison with a computational implementation of Cramer’s rule we have, as measure ofrelative efficiency,

Mn2

n× n!=

Mn2

nn(n− 1)!=

M

(n− 1)!

where M is the number of Jacobi iterations. Clearly, if n is large we would expect the Jacobimethod to be more efficient.

Page 27: NUMERICAL ANALYSIS · 2015-10-21 · (a) Nonlinear algebraic equations in one variable - chapter 3 - we investigate the bisection method, linear interpolation, Newton’s method,

4. SYSTEMS OF LINEAR EQUATIONS 27

Example 4.1. Consider

A =

5 3 1−2 3 06 −1 8

=

5 0 00 3 00 0 8

︸ ︷︷ ︸

D

+

0 3 10 0 00 0 0

︸ ︷︷ ︸

U

+

0 0 0−2 0 06 −1 0

︸ ︷︷ ︸

L

b =

30−7

Clearly, A satisfies (4.5) so that the Jacobi method may be used. Starting with

x(0) =

222

we find, after 40 iterations,

x(40) =

0.611842105264070.40789473683653−1.28289473683631

r(40) =

−0.06−0.180.57

× 10−10

with∣∣r(40)

∣∣ = 6.1× 10−11. The true solution is

x =

0.611842105263160.40789473684210−1.28289473684211

and we see that the difference between each of these entries and those in x(40) is less than 10−11.

We note that there are other types of iterative methods for solving linear systems, such as theGauss-Seidel method and successive over-relaxtion (SOR), but they are similar in spirit to theJacobi method, which is the simplest of the three. Like the Jacobi method, these other methodsalso require that the diagonal entries of A must all be nonzero. Furthermore, for large n, all theseiterative methods become relatively more efficient (with respect to arithmetic computation) thandirect inversion.

Page 28: NUMERICAL ANALYSIS · 2015-10-21 · (a) Nonlinear algebraic equations in one variable - chapter 3 - we investigate the bisection method, linear interpolation, Newton’s method,

Chapter 5

APPROXIMATION METHODS

5.1 Introduction

In this chapter we investigate two related problems: the approximation of given functions by other,simpler functions, and the fitting of known functions to given data. In the cases studied here, weapproximate a continuous function by means of a polynomial.

5.2 Polynomial interpolation

Consider a function y(x) given in the form of the coordinates (xi, yi), i = 0, 1, . . . , n. We mayapproximate the function with a polynomial pn(x) of degree n that is exactly equal to y(x) at then+ 1 given points

yi = pn(xi) = a0 + a1xi + a2x2i + · · ·+ anx

ni . (5.1)

We note that there are n+1 coefficients ai as well as n+1 points (xi, yi). The polynomial in (5.1)is known as an interpolating polynomial.

There are n+ 1 unknowns ai that must be determined from the n+ 1 linear equations

a0 + a1x0 + · · ·+ anxn0 = p(x0) = y0

a0 + a1x1 + · · ·+ anxn1 = p(x1) = y1

...

a0 + a1xn + · · ·+ anxnn = p(xn) = yn

which can be written compactly in matrix form as

1 x0 · · · xn0

1 x1 · · · xn1

......

. . ....

1 x0 · · · xn0

a0a1...an

=

y0y1...yn

If det(xij

)6= 0, these equations have a unique solution. In practice it is difficult and/or inefficient to

solve these equations directly, and so we investigate easier and/or faster methods. Firstly, though,we state a few points of general importance.

We may rightly ask whether this interpolating polynomial is unique. Assume that it is not,and thus there are two interpolating polynomials

pn(x) = a0 + a1x+ a2x2 + · · ·+ anx

n

qn(x) = b0 + b1x+ b2x2 + · · ·+ bnx

n

28

Page 29: NUMERICAL ANALYSIS · 2015-10-21 · (a) Nonlinear algebraic equations in one variable - chapter 3 - we investigate the bisection method, linear interpolation, Newton’s method,

5. APPROXIMATION METHODS 29

ThenQ(x) = pn(x)− qn(x)

= (a0 − b0) + (a1 − b1)x+ (a2 − b2)x2 + · · ·+ (an − bn)x

n

is a polynomial of degree n. But Q(x) = 0 at the n+ 1 points {x0, x1, x2, . . . , xn}. However, sinceQ(x) is of degree n, it may only have n roots. This contradiction is resolved only if Q(x) = 0,which implies pn(x) = qn(x). We conclude that the interpolating polynomial is unique.

Error analysis. We obtain an estimate of the error made when using the polynomial pn(x)instead of the function y(x). We know that y(x) = pn(x) at xi, i = 0, 1, 2, . . . , n. Now consider

F (x) = y(x)− pn(x) − C

n∏

i=0

(x − xi). (5.2)

Clearly, F (x) = 0 at each of the nodes {x0, x1, . . . , xn}. Consider any point xn+1 /∈ {x0, x1, . . . , xn}.We choose C such that F (xn+1) = 0, which gives

C =y(xn+1)− pn(xn+1)∏n

i=0(xn+1 − xi). (5.3)

Assume y(x), and hence F (x), is continuous. From the constructions (5.2) and (5.3) it followsthat F (x) = 0 at the n+2 nodes {x0, x1, . . . , xn, xn+1}. Hence, by the Generalized Rolle’s Theorem,there exists a point ξ such that

F (n+1)(ξ) = 0.

If we differentiate (5.2) we obtain

0 = F (n+1)(ξ)

= y(n+1)(ξ) − 0− C(n+ 1)!

and so

C =y(n+1)(ξ)

(n+ 1)!,

which yields, using (5.3),

y(xn+1)− pn(xn+1) =y(n+1)(ξ)

(n+ 1)!

n∏

i=0

(xn+1 − xi).

But xn+1 was chosen arbitrarily, so that this error expression

y(x)− pn(x) =y(n+1)(ξ(x))

(n+ 1)!

n∏

i=0

(x − xi). (5.4)

is true for all x. It is easily verified that (5.4) is also true at {x0, x1, . . . , xn}.

5.3 Lagrange’s method

We now describe a method developed by Lagrange that is a shortcut for determining the coefficientsai in (5.1).

For each of the points (xi, yi), i = 0, 1, . . . , n, we construct an nth degree polynomial that isequal to zero at each of the other points x0, x1, . . . , xi−1, xi+1, . . . , xn

Li(x) = A(x − x0)(x − x1) · · · (x − xi−1)(x− xi+1) · · · (x− xn). (5.5)

Furthermore, we demand that this polynomial has the value 1 when x = xi

1 = A(xi − x0)(xi − x1) · · · (xi − xi − 1)(xi − xi+1) · · · (xi − xn)

Page 30: NUMERICAL ANALYSIS · 2015-10-21 · (a) Nonlinear algebraic equations in one variable - chapter 3 - we investigate the bisection method, linear interpolation, Newton’s method,

30 5. APPROXIMATION METHODS

from which we obtain

A =1

(xi − x0)(xi − x1) · · · (xi − xi−1)(xi − xi+1) · · · (xi − xn)

so that

Li(x) =(x − x0)(x − x1) · · · (x− xi−1)(x− xi+1) · · · (x− xn)

(xi − x0)(xi − x1) · · · (xi − xi − 1)(xi − xi+1) · · · (xi − xn).

The nth degree polynomial through the points (xi, yi) is then given by

pn(x) =

n∑

i=0

yiLi(x). (5.6)

where the Li(x) are known as the Lagrange coefficient polynomials. We may test if this is therequired polynomial by substituting x = xk into equation (5.6)

pn(xk) =n∑

i=0

yiLi(xk)

= y0L0(xk) + y1L1(xk) + · · ·+ ykLk(xk) + · · ·+ ynLn(xk)

= 0 + 0 + · · ·+ yk(1) + · · ·+ 0

= yk.

Example 5.1. Approximate the sine function with a polynomial that is equal to sinx at x =0, π4 ,

π2 . Determine the true error at x = π

6 and compare it to an easily calculable upper boundof the error.

The coordinates of the three points that the interpolating polynomial must pass throughare shown the following table:

i xi yi = sinxi

0 0 01 π

41√2

2 π2 1

We first determine the polynomials defined in (5.5)

L0(x) =

(x− π

4

) (x− π

2

)

(0− π

4

) (0− π

2

) =8

π2

(

x2 − 3π

4x+

π2

8

)

L1(x) =(x− 0)

(x− π

2

)

(π4 − 0

) (π4 − π

2

) = − 16

π2

(

x2 − π

2x)

L2(x) =(x− 0)

(x− π

4

)

(π2 − 0

) (π2 − π

4

) =8

π2

(

x2 − π

4x)

The interpolating polynomial is given by

p2(x) = y0L0(x) + y1L1(x) + y2L2(x)

= 0 +1√2L1 + (1)L2

= −8(√

2− 1)

π2x2 +

2(2√2− 1

)

πx

We determine the approximation error at x = π6

∣∣∣sin

6

)

− p2

6

)∣∣∣ = |0.5− 0.517| = 0.017

Page 31: NUMERICAL ANALYSIS · 2015-10-21 · (a) Nonlinear algebraic equations in one variable - chapter 3 - we investigate the bisection method, linear interpolation, Newton’s method,

5. APPROXIMATION METHODS 31

It is interesting to compare this error with the upper limit (5.4)

∣∣∣sin

6

)

− p2

6

)∣∣∣ ≤

max[0,π/2] |cosx|3!

∣∣∣∣∣

2∏

i=0

2

)∣∣∣∣∣

=1

6

∣∣∣

6− 0)(π

6− π

4

)(π

6− π

2

)∣∣∣

= 0.024

We see that using (5.4) does indeed give, in this case, an upper bound for the magnitude of theapproximation error.

5.4 Least-squares curve fitting

A function y = y(x) may be approximated by an nth degree polynomial that passes through eachdata point, as in §5.2 and §5.3 . However, if we believe that the relationship y(x) is in fact linear,then it would make more sense to find the “best” straight line that approximates the function. Weneed a criterion that allows us to determine the fitting function such that its deviation from thegiven points is minimized. The deviation ∆i at point xi is the difference between the fit f(x) andthe actual function y(x), i.e.

∆i = f(xi)− yi.

We examine a few optimization criteria, given n data points.

Minimization of∑

i∆i: Since errors may be both positive and negative, a positive error

and negative error summed will give a sum that is less in magnitude than either error. Furthermore,since −1+ 1 = −2+ 2 = −3+ 3 = · · · = 0 it is clear that the sum cannot give a unique minimum.This means that such a fitting criterion cannot allow the fitting function to be uniquely determined.

Minimization of∑

i|∆i|: When we have an error range (y−, y+), y− < y+ around the y

coordinate of a data point (x, y), then the straight line fit f(x) = mx+ c passing between (x, y−)and (x, y+) such that y− ≤ f(x) ≤ y+ yields

|f(x)− y−|+ |f(x)− y+| ≤ |y+ − f(x) + f(x)− y−| = |y+ − y−|which is independent of m and c. Again, the fitting function cannot be determined uniquely.

Minimization of∑

i∆

2

i: Let f(x) be a function fitting the data. Suppose we have two data

points with the same x coordinates but with different y coordinates, namely (x, y1) and (x, y2).We have that

S =∑

i

∆2i = (f(x) − y2)

2 + (f(x)− y1)2 = e2 + (e + d)2,

where e = f(x)− y2 and d = y2 + y1. Then it follows that

dS

de= 2e+ 2(e+ d) = 2(2e+ d)

andd2S

de2= 4 > 0.

Therefore S will be a minimum if e = d2 . This means that the value of f(x) is the mean of the

two y coordinates; a result which is both unique and intuitively acceptable and from mathematicalstatistics this norm is known to be the correct choice. The function f(x) is therefore chosen sothat

S =

n∑

i=0

[f(xi)− yi]2 (5.7)

is a minimum. We will see that, in the case of polynomial fitting, the norm (5.7) gives a uniqueresult.

Page 32: NUMERICAL ANALYSIS · 2015-10-21 · (a) Nonlinear algebraic equations in one variable - chapter 3 - we investigate the bisection method, linear interpolation, Newton’s method,

32 5. APPROXIMATION METHODS

5.5 Least-squares polynomial fitting

A wide variety of functions may be used in least-squares curve fitting. We will leave the fitting oftrigonometric, exponential and logarithmic functions etc. to the student as self-study, and discussonly the use of polynomials as fitting functions.

We consider the case where f(x) in (5.7) is an mth degree polynomial pm(x), with m ≤ n.Then pm(x) must be chosen such that

S =

n∑

i=0

[pm(xi)− yi]2

(5.8)

is a minimum. Sincepm(x) = a0 + a1x+ · · ·+ amxm (5.9)

we must demand that∂S

∂ak= 0 for k = 0, 1, . . . ,m. (5.10)

From (5.8) we then have

∂S

∂ak= 2

n∑

i=0

[pm(xi)− yi]∂pm∂ak

(xi) for k = 0, 1, . . . ,m.

From (5.9) we have that∂pm∂ak

(xi) = xki

and so∂S

∂ak= 2

n∑

i=0

[pm(xi)− yi]xki for k = 0, 1, . . . ,m. (5.11)

Furthermore,

∂2S

∂a2k= 2

n∑

i=0

xki x

ki ≥ 0 for k = 0, 1, . . . ,m,

so that the requirement in (5.10) does indeed give a minimum for S. This value is obtained from(5.10) and (5.11):

n∑

i=0

pm(xi)xki =

n∑

i=0

yixki k = 0, 1, . . . ,m. (5.12)

The system in (5.12) consists of m + 1 equations in the m + 1 unknowns ak; the ak are thusdetermined uniquely.

From (5.9) we obtain a more explicit form for (5.12):

a0(n+ 1) + a1∑

i

xi + · · ·+ am∑

i

xmi =

i

yi (k = 0)

a0∑

i

xi + a1∑

i

x2i + · · ·+ am

i

xm+1i =

i

xiyi (k = 1)

...

a0∑

i

xmi + a1

i

xm+1i + · · ·+ am

i

x2mi =

i

xmi yi (k = m)

To fit a straight line, for example, we have m = 1 and

p1(x) = a0 + a1x

and the coefficients ak are obtained from

a0(n+ 1) + a1∑

i

xi =∑

i

yi

a0∑

i

xi + a1∑

i

x2i =

i

xiyi(5.13)

Page 33: NUMERICAL ANALYSIS · 2015-10-21 · (a) Nonlinear algebraic equations in one variable - chapter 3 - we investigate the bisection method, linear interpolation, Newton’s method,

5. APPROXIMATION METHODS 33

Variance A question arises regarding the order of the fitting polynomial. If we increase thedegree of the polynomial to n (number of data points = n+1) then the fitting polynomial becomesan interpolating polynomial, which has zero deviation (since an interpolating polynomial passesthrough each point). How may we measure the quality of the fit for various degrees? Mathematicalstatistics tells us that we choose the degree for which the variation σ2 shows a minimum, where

σ2 =

i∆2i

n−m.

Example 5.2. Fit a straight line to the data points in the following table:

i xi yi

0 1 2.041 2 4.122 3 5.643 4 7.184 5 9.205 6 12.04

Using the data in the table, we find

n+ 1 = 6∑

i

xi = 21

i

yi = 40.22

i

x2i = 91

i

xiyi = 174.16

Substitution into equation (5.13) gives the two simultaneous equations

6a0 + 21a1 = 40.22

21a0 + 91a1 = 174.16

which are solved to give

a0 = 0.0253

a1 = 1.9080

The fit is thusp1 (x) = 1.9080x+ 0.0253.

Example 5.3. In the following table the coordinates of six data points are given. Fit polyno-mials of degrees 1 to 4 to this data, and decide which is the best fit.

x 0 0.8 1.4 2.1 2.7 3.4y 0.015 0.644 1.926 4.442 7.274 11.621

The fitting polynomials, and variance for each, are given in the following table:

Page 34: NUMERICAL ANALYSIS · 2015-10-21 · (a) Nonlinear algebraic equations in one variable - chapter 3 - we investigate the bisection method, linear interpolation, Newton’s method,

34 5. APPROXIMATION METHODS

Degree Fitting polynomial σ2

1 p1(x) = −1.601 + 3.416x 2.12 p2(x) = 0.018− 0.043x+ 1.016x2 0.00103 p3(x) = 0.015− 0.023x+ 0.999x2 + 0.003x3 0.00144 p4(x) = 0.017− 0.113x+ 1.142x2 − 0.064x3 + 0.010x4 0.0026

It is clear that the variance for all those with degree of two or higher are of the same order ofmagnitude, and that the optimal fit is the one with degree two.

5.6 Approximation with Chebyshev polynomials

One disadvantage of polynomial approximation is related to the fact that polynomial maximaand minima are spread unevenly on any interval: On [−1, 1],

∣∣xk∣∣ has maxima at −1 and 1 and

a minimum at 0. We now seek related functions that have evenly spaced maxima and minima,and for which the maxima and minima over a given interval are as small as possible. Possiblecandidates are, for example, the cosine functions: cos θ, cos 2θ, cos 3θ, . . . .

5.6.1 Definition

The Chebyshev polynomial of the nth degree is defined by

Tn (x) = cos(n arccosx). (5.14)

Here n is an integer and only the cases with n ≥ 0 need to be studied, since it follows from thedefinition that Tn = T−n.

We note that Tn (x) is defined on [−1, 1] only, due to the presence of the arccos function in(5.14). From the definition it follows

T0(x) = 1 and T1(x) = x.

Higher order Chebyshev polynomials are generated using a recursion formula, given by

Tm+n(x) + Tm−n(x) = 2Tm(x)Tn(x).

For the particular case n = 1 it follows that

Tm+1 (x) = 2xTm (x)− Tm−1 (x) (5.15)

and we find, for example,

T2(x) = 2xT1(x) − T0(x)

= 2x2 − 1

T3(x) = 2xT2(x) − T1(x)

= 4x3 − 3x

(5.16)

The relationships in (5.15) and (5.16) may be inverted to give powers of x in terms of Tn:

1 = T0

x = T1

x2 =1

2(T2 + 1) =

T2 + T0

2

x3 =1

4(T3 + 3x) =

T3 + 3T1

4

(5.17)

Page 35: NUMERICAL ANALYSIS · 2015-10-21 · (a) Nonlinear algebraic equations in one variable - chapter 3 - we investigate the bisection method, linear interpolation, Newton’s method,

5. APPROXIMATION METHODS 35

Zero points: From definition (5.14) it follows that

Tn(ξ) = 0 for n arccos ξ = (2r + 1)π

2,

where r is an integer, and thus the zero points of Tn(x) occur at

ξr = cos

(2r + 1

2nπ

)

, r = 0, 1, . . . , n− 1. (5.18)

We note that Tn has n zero points.

Extreme points: From definition (5.14) it follows that

Tn(x) = ±1 for n arccosx = rπ,

where r is an integer and thus we have the extreme points

xr = cos( r

nπ)

, r = 0, 1, . . . , n, (5.19)

of Tn. We note that Tn has n+ 1 extreme points and Tn(xr) = (−1)r.

Orthogonality: Consider the integral

Imn =

∫ 1

−1

Tm(x)Tn(x)√1− x2

dx.

If we make the substitution

x = cos θ

dx = − sin θ dθ√

1− x2 = sin θ

the integral becomes

Imn = −∫ 0

π

cosmθ cosnθ

sin θsin θ dθ

=

∫ π

0

cosmθ cosnθ dθ

=1

2

∫ π

0

[cos((m+ n)θ

)+ cos

((m− n)θ

)]dθ

There are three distinct possibilities as far as the choice of m and n is concerned.

1. If m = n = 0, then

Imn =1

2

∫ π

0

(1 + 1) dθ = π.

2. If m = n 6= 0, then

Imn =1

2

∫ π

0

[cos(2nθ) + 1] dθ =π

2.

3. If m 6= n, then

Imn =1

2

[sin(m+ n)θ

m+ n+

sin(m− n)θ

m− n

0

= 0.

In summary,

∫ 1

−1

Tm(x)Tn(x)√1− x2

dx =

π m = n = 0π2 m = n 6= 0

0 m 6= n

(5.20)

Thus, the Chebyshev polynomials are said to be orthogonal with respect to the weight function1√

1−x2on the interval [−1, 1].

Page 36: NUMERICAL ANALYSIS · 2015-10-21 · (a) Nonlinear algebraic equations in one variable - chapter 3 - we investigate the bisection method, linear interpolation, Newton’s method,

36 5. APPROXIMATION METHODS

5.6.2 Minimal property

From equations (5.16) it should be clear that the coefficient of xn in Tn(x) is equal to 2n−1. Theimportance of Chebyshev polynomials arises from the following remarkable result:

Theorem 5.1. Consider the set Pn of all polynomials of degree n and with the coefficient ofxn equal to 1, on the interval [−1, 1]. If pn(x) ∈ Pn, then

αn = maxx∈[−1,1]

|pn(x)|

is a minimum if

pn(x) =1

2n−1Tn(x).

Proof. Assume that there is a polynomial pn(x) with the coefficient of xn equal to 1, that ispn(x) ∈ Pn, and for which

αn = maxx∈[−1,1]

|pn(x)| <∣∣∣∣

Tn(x)

2n−1

∣∣∣∣≤ 1

2n−1

everywhere on [−1, 1]. The last inequality follows from definition (5.14) where |Tn(x)| ≤ 1 and so

∣∣∣∣

1

2n−1Tn(x)

∣∣∣∣≤ 1

2n−1on [−1, 1].

For the extreme points xr, r = 0, 1, . . . , n, from (5.19) we have

2−n+1Tn(x0)− pn(x0) > 0

2−n+1Tn(x1)− pn(x1) < 0

...

2−n+1Tn(xn)− pn(xn) > 0

for n even (the inequalities reverse for n odd). The function

F (x) = 2−n+1Tn(x) − pn(x)

thus changes sign n times on [−1, 1] and so must have n roots. But, by construction, F (x) is apolynomial of degree n− 1. Thus, the assumption regarding the existence of pn is thus incorrect.Therefore, if pn(x) ∈ Pn, then

αn ≥ Tn(x)

2n−1

with equality only if αn is a minimum. Q.E.D.

We may use theorem 5.1 to reduce the error in polynomial interpolation. If pn(x) is aninterpolating polynomial that approximates a function y(x) defined on [−1, 1], recall that the errorfor polynomial interpolation is given by

y(x)− pn(x) =y(n+1)(ξ)

(n+ 1)!

n∏

i=0

(x − xi).

It follows that

maxx∈[−1,1]

|y(x)− pn(x)| ≤1

(n+ 1)!max

x∈[−1,1]

∣∣∣y(n+1)(x)

∣∣∣ maxx∈[−1,1]

∣∣∣∣∣

n∏

i=0

(x − xi)

∣∣∣∣∣.

Page 37: NUMERICAL ANALYSIS · 2015-10-21 · (a) Nonlinear algebraic equations in one variable - chapter 3 - we investigate the bisection method, linear interpolation, Newton’s method,

5. APPROXIMATION METHODS 37

Clearly,∏n

i=0(x − xi) is an element of Pn and therefore

maxx∈[−1,1]

∣∣∣∣∣∣

n∏

j=0

(x− xj)

∣∣∣∣∣∣

≥ 1

2n−1.

One notices that the nodes xi are the roots of the polynomial∏n

i=0(x− xj), and we may write

Tn(x)

2n−1=

n∏

i=0

(x− x̄i)

where x̄i are the zeroes of Tn(x). We can thus better our interpolation if we replace the nodes xi

with the Chebyshev nodes x̄i.We are not restricted to the interval [−1, 1] and can apply this minimisation on an interval

[a, b] by the linear change of variable

xj =

[(a+ b) + (b − a)x̄j

]

2

for j = 0, 1, . . . , n− 1.Another application of theorem 5.1 is reducing the degree of a known approximation poly-

nomial. Let pn(x) = a0 + a1x + · · · + an−1xn−1 + anx

n be a nth degree interpolating polyno-mial approximating the function y(x). Consider now a (n − 1)th degree polynomial pn−1(x) =b0 + b1x+ · · ·+ bn−1x

n−1. We want maxx∈[−1,1] |pn(x)− pn−1(x)| to be as small as possible. Notethat

pn(x) − pn−1(x)

an=

(a0 − b0

an

)

+

(a1 − b1an

)

x+ · · ·+(an−1 − bn−1

an

)

xn−1 + xn

is indeed a monic polynomial. Since

maxx∈[−1,1]

∣∣∣∣

pn(x) − pn−1(x)

an

∣∣∣∣≥ max

x∈[−1,1]

∣∣∣∣

Tn(x)

2n−1

∣∣∣∣

and the minimum will be obtained when we have equality, that is

pn(x) − pn−1(x)

an=

Tn(x)

2n−1,

we can thus choosepn−1(x) = pn(x) −

an2n−1

Tn(x).

5.6.3 Expansion of a function in terms of Chebyshev poly-

nomials

We investigate the possibility of approximating a given function using an nth order expansion interms of Chebyshev polynomials, i.e.

f(x) ≈ 1

2c0T0(x) + c1T1(x) + c2T2(x) + · · ·+ cnTn(x). (5.21)

There are two ways to obtain such an expansion, and we will illustrate each by means of anexample.

Method 1: “Economization” of a power series. If the powers of x in a knownseries expansion are expressed in terms of Chebyshev polynomials and the series is truncated afterthe term cn−1Tn−1(x), then the resulting error will essentially be given by cnTn(x) and so willoscillate between cn and −cn.

Page 38: NUMERICAL ANALYSIS · 2015-10-21 · (a) Nonlinear algebraic equations in one variable - chapter 3 - we investigate the bisection method, linear interpolation, Newton’s method,

38 5. APPROXIMATION METHODS

Example 5.4. Economize the Taylor series for the exponential function

ex = 1 + x+x2

2!+

x3

3!+

x4

4!+

x5

5!+ · · · .

We use (5.17) to write the powers of x in terms of Tn, i.e.

ex = T0 + T1 +1

2

(T0 + T2

2

)

+1

6

(3T1 + T3

4

)

+1

24

(3T0 + 4T2 + T4

8

)

+1

120

(10T1 + 5T3 + T5

16

)

+ · · ·

Next we collect terms in Tn for the first six terms, and truncate after T3 to obtain

ex ≈ 81

64T0 +

217

192T1 +

13

48T2 +

17

384T3.

Finally use (5.16) to write the Tn in terms of powers of x:

ex ≈ 191

192+

383

384x+

13

24x2 +

17

96x3 = p(x).

If we truncate the Taylor series after the 3rd-order term, we obtain

ex ≈ 192

192+

384

384x+

12

24x2 +

16

96x3 = q(x).

It is clear that p(x) and q(x) are almost identical, but it is the subtle difference between the twothat significantly affects the quality of the approximations. The error for these two approxima-tions on [−1, 1] is shown in the following table.

x |ex − p(x)| |ex − q(x)|0 0.005 0

0.05 0.005 10−7

0.1 0.005 10−6

0.2 0.004 0.00010.5 0.002 0.0030.8 0.005 0.021 0.007 0.05

It is clear that even though the Taylor series is better for small values of x, the Chebyshev seriesseems to “spread” the error evenly over the whole interval.

Method 2: Direct application of the orthogonality property. We multiply

(5.21) by Tk(x)√1−x2

and integrate over [−1, 1]. From (5.20) it follows that

∫ 1

−1

f(x)Tk(x)√1− x2

dx = 0 + 0 + · · ·+ π

2ck + · · ·+ 0

and so

ck =2

π

∫ 1

−1

f(x)Tk(x)√1− x2

dx.

The substitution x = cos θ together with the definition (5.14) gives a more compact form for theintegral

ck =2

π

∫ π

0

f(cos θ) cos(kθ) dθ

Page 39: NUMERICAL ANALYSIS · 2015-10-21 · (a) Nonlinear algebraic equations in one variable - chapter 3 - we investigate the bisection method, linear interpolation, Newton’s method,

5. APPROXIMATION METHODS 39

An obvious disadvantage of this method is that sometimes difficult integrals may have to bedetermined.

Example 5.5. Expand f(x) = arcsinx in terms of Chebyshev polynomials.We find the coefficients by

ck =2

π

∫ π

0

arcsin(cos θ) cos(kθ) dθ

=2

π

∫ π

0

arcsin(

sin(π

2− θ))

cos(kθ) dθ

=2

π

∫ π

0

2− θ)

cos(kθ) dθ

We identify two cases:

1. If k = 0, then

c0 =2

π

∫ π

0

2− θ)

dθ =2

π

2θ − θ2

2

0

= 0.

2. If k 6= 0, then

ck =

[sin(kθ)

k

0

− 2

π

([θ sin(kθ)

k

0

−∫ π

0

sin(kθ)

kdθ

)

= − 2

π

[cos(kθ)

k2

0

=2

πk2[1− (−1)k

].

It follows that ck = 0 when k is even and ck = 4πk2 when k is odd.

We thus have

arcsinx =4

π

∞∑

k=0

1

(2k + 1)2T2k+1(x)

=4

π

[

T1(x) +T3(x)

9+

T5(x)

25+ · · ·

]

.

If we truncated this series after j terms (i.e. when k = j − 1), the last term in the series is

4T2j−1(x)

π(2j − 1)2.

We know that max |T2j−1| = 1, so the residual term R of the series, i.e. the sum of all the termsfor k ≥ j, satisfies

|R| = 4

π

∞∑

k=j

1

(2k + 1)2|T2k+1(x)|

≤ 4

π

∞∑

k=j

1

(2k + 1)2

≤ 4

π

∣∣∣∣

∫ ∞

j

1

(2x+ 1)2dx

∣∣∣∣

=2

(2j + 1)π.

Page 40: NUMERICAL ANALYSIS · 2015-10-21 · (a) Nonlinear algebraic equations in one variable - chapter 3 - we investigate the bisection method, linear interpolation, Newton’s method,

40 5. APPROXIMATION METHODS

Hence, if a tolerance of ǫ was imposed, we would have

|R| ≤ ǫ

2

(2j + 1)π≤ ǫ

∴ j ≥ 1

πǫ− 1

2

and so we see that if ǫ is very small, then j must be very large for the desired tolerance to besatisfied.

Page 41: NUMERICAL ANALYSIS · 2015-10-21 · (a) Nonlinear algebraic equations in one variable - chapter 3 - we investigate the bisection method, linear interpolation, Newton’s method,

Chapter 6

NUMERICALDIFFERENTIATION

6.1 Introduction

Suppose we wish to estimate the derivative of a function f(x) at some point x, given only discretedata points (xi, f(xi)). One approach would be to determine an interpolating or fitting polynomial,and then differentiate that polynomial analytically. However, it is also possible to estimate thederivative using a direct numerical method.

6.2 First derivative

Consider the Taylor expansions

f(x− h) = f(x)− hf ′(x) +h2

2f ′′(x)− h3

3!f ′′′(x) +

h4

4!f (4)(x)− · · · (6.1)

f(x+ h) = f(x) + hf ′(x) +h2

2f ′′(x) +

h3

3!f ′′′(x) +

h4

4!f (4)(x) + · · · (6.2)

Subtracting (6.1) from (6.2) yields

f(x+ h)− f(x− h) = 2hf ′(x) +2h3

3!f ′′′(x) + · · · (6.3)

and we truncate the infinite series on the right of the equality to give the approximation

f(x+ h)− f(x− h) ≈ 2hf ′(x)

which we can rewrite as

f ′(x) ≈ f(x+ h)− f(x− h)

2h. (6.4)

This is the finite-difference representation of the first derivative of f(x) at x.

Note: The truncated terms h3

3! f′′′(x) + · · · from (6.3) constitute the approximation error, i.e.

∣∣∣∣f ′(x) − f(x+ h)− f(x− h)

2h

∣∣∣∣=

∣∣∣∣

2h2

3!f ′′′(x) + · · ·

∣∣∣∣

The error would tend toward zero as h → 0 and (6.4) would become exact. Since we are workingwith Taylor expansions, we may replace the error by the Lagrange estimate of the error

∣∣∣∣

2h2

3!f ′′′(x) +

2h4

5!f (5)(x) + · · ·

∣∣∣∣≤∣∣∣∣

2h2

3!f ′′′(ξ)

∣∣∣∣

41

Page 42: NUMERICAL ANALYSIS · 2015-10-21 · (a) Nonlinear algebraic equations in one variable - chapter 3 - we investigate the bisection method, linear interpolation, Newton’s method,

42 6. NUMERICAL DIFFERENTIATION

where x < ξ < x + h. Due to the function being unknown, we cannot determine its higher-orderderivatives analytically and it would be difficult to determine an upper bound on the Lagrangeestimate of the error and therefore we analyse the behaviour of h as it is changed. If 0 < h < 1,then

∣∣a0h

2 + a1h4 + a2h

6 + · · ·∣∣ ≤ M

∣∣h2∣∣ for some positive constant M ∈ R. We introduce the

notation O(·) to indicate this boundedness; the approximation error above can then be rewrittenas ∣

∣∣∣

2h2

3!f ′′′(x) +

2h4

5!f (5)(x) + · · ·

∣∣∣∣∈ O(h2).

The behaviour of the error pending changes in the step size can then be illustrated by the followingexample. Suppose that the approximation error is given by e(h) = 10h2 and thus e(h) ∈ O(h2) bythe previous statements. If h = 0.1, then e (0.1) = 0.1. If the step size were to be halved h∗ = h/2 =0.05, then the error becomes e(0.05) = 0.025; halving the error further yields e(0.025) = 0.00625.Therefore, as the step size is decreased the error will also decrease proportional to h2. Since theerror in (6.4) is of order h2, we require that h be reasonably small in order for (6.4) to be reasonablyaccurate.

6.3 Second derivative

If we add (6.1) and (6.2) we obtain

f(x− h) + f(x+ h) = 2f(x) + h2f ′′(x) +O(h4)

which yields

f ′′(x) =f(x+ h) + f(x− h)− 2f(x)

h2(6.5)

with an error of O(h2). This is the finite-difference representation of the second derivative of f(x)at x. Since the error is O(h2) we would expect that, if h is small enough for (6.4) to be accurate,then (6.5) will also be accurate. Both (6.4) and (6.5) are known as central-difference formulae.

Note: If we use the notation xi−1 = x− h, xi = x, xi+1 = x+ h we have

f ′(xi) =f(xi+1)− f(xi−1)

xi+1 − xi−1. (6.6)

Using the subscripted notation we have

f ′′(xi) = 4

(f(xi+1) + f(xi−1)− 2f(xi)

(xi+1 − xi−1)2

)

. (6.7)

We can simplify the notation in (6.6) and (6.7) more by letting yi = f(xi), yi+1 = f(xi+1),yi−1 = f(xi−1), etc. Then (6.6) becomes

y′i =yi+1 − yi−1

xi+1 − xi−1=

yi+1 − yi−1

2h

and (6.7) becomes

y′′i =yi+1 + yi−1 − 2yi

h2.

Note: The approximation formula for f ′(xi) is dependent on the values of f(x) at the neigh-bouring points xi−1 and xi+1 and that the approximation formula for f ′′(xi) is dependent on thevalues of f(x) at xi−1, xi and xi+1. Since the approximation error is proportional to h2, we seethat as h is reduced so the error is reduced. The converse is also true: if h is large then the errorwill be large. Numerical differentiation must thus be used with caution, particularly if h is large(the discrete data points are far apart).

Page 43: NUMERICAL ANALYSIS · 2015-10-21 · (a) Nonlinear algebraic equations in one variable - chapter 3 - we investigate the bisection method, linear interpolation, Newton’s method,

6. NUMERICAL DIFFERENTIATION 43

6.4 Higher-order derivatives

There are higher-order expressions that may be derived. We will not go into the details of theirderivation (the principles are the same as for the expressions above), but we will state them forcompleteness.

Central-difference, O(h2)

y′i =yi+1 − yi−1

2h

y′′i =yi+1 − 2yi + yi−1

h2

y′′′i =yi+2 − 2yi+1 + 2yi−1 − yi−2

2h3

y(4)i =

yi+2 − 4yi+1 + 6yi − 4yi−1 + yi−2

h4

Central-difference, O(h4)

y′i =−yi+2 + 8yi+1 − 8yi−1 + yi−2

12h

y′′i =−yi+2 + 16yi+1 − 30yi + 16yi−1 − yi−2

12h2

y′′′i =−yi+3 + 8yi+2 − 13yi+1 + 13yi−1 − 8yi−2 + yi−3

8h3

y(4)i =

−yi+3 + 12yi+2 − 39yi+1 + 56yi − 39yi−1 + 12yi−2 − yi−3

6h4

Forward-difference, O(h)

y′i =yi+1 − yi

h

y′′i =yi+2 − 2yi+1 + yi

h2

y′′′i =yi+3 − 3yi+2 + 3yi+1 − yi

h3

y(4)i =

yi+4 − 4yi+3 + 6yi+2 − 4yi+1 + yih4

Forward-difference, O(h2)

y′i =−yi+2 + 4yi+1 − 3yi

2h

y′′i =−yi+3 + 4yi+2 − 5yi+1 + 2yi

h2

y′′′i =−3yi+4 + 14yi+3 − 24yi+2 + 18yi+1 − 5yi

2h3

y(4)i =

−2yi+5 + 11yi+4 − 24yi+3 + 26yi+2 − 14yi+1 + 3yih4

Backward-difference, O(h)

y′i =−yi−1 + yi

h

y′′i =yi−2 − 2yi−1 + yi

h2

y′′′i =−yi−3 + 3yi−2 − 3yi−1 + yi

h3

y(4)i =

yi−4 − 4yi−3 + 6yi−2 − 4yi−1 + yih4

Page 44: NUMERICAL ANALYSIS · 2015-10-21 · (a) Nonlinear algebraic equations in one variable - chapter 3 - we investigate the bisection method, linear interpolation, Newton’s method,

44 6. NUMERICAL DIFFERENTIATION

Backward-difference, O(h2)

y′i =yi−2 − 4yi−1 + 3yi

2h

y′′i =−yi−3 + 4yi−2 − 5yi−1 + 2yi

h2

y′′′i =3yi−4 − 14yi−3 + 24yi−2 − 18yi−1 + 5yi

2h3

y(4)i =

−2yi−5 + 11yi−4 − 24yi−3 + 26yi−2 − 14yi−1 + 3yih4

The forward-difference and backward-difference formulae should only be used when data points tothe left or right of xi are not available. The central-difference expressions generally give betterresults.

Example 6.1. The following table shows discrete data points corresponding to the functionsinx on the interval [0, π2 ]. We have used h = π

20 .

i xi sinxi

1 0 02 0.15707 0.156433 0.31415 0.309014 0.47123 0.453995 0.62831 0.587786 0.78539 0.707107 0.94247 0.809018 1.09955 0.891009 1.25663 0.9876810 1.41371 0.9876811 1.57079 1

In the following table we show the various derivatives calculated using the various expressionsgiven above, at the point x = π

4 .

y′(π4

)y′′(π4

)y′′′(π4

)y(4)

(π4

)

Exact 0.70710 −0.70710 −0.70710 0.70710

CD O(h2) 0.70420 −0.70565 −0.70275 0.70420CD O(h4) 0.70709 −0.70710 −0.70708 0.70709FD O(h) 0.64878 −0.80735 −0.52088 0.88734FD O(h2) 0.71219 −0.72553 −0.72996 0.76774BD O(h) 0.75962 −0.58657 −0.85001 0.45212BD O(h2) 0.71355 −0.72009 −0.74348 0.74088

The central-difference expressions give better results, and the O(h4) results have an error ofbetter than 10−4. Also, the results for the O(h2) forward-difference and backward differenceexpressions are considerably better than those for the corresponding O(h) expressions.

Page 45: NUMERICAL ANALYSIS · 2015-10-21 · (a) Nonlinear algebraic equations in one variable - chapter 3 - we investigate the bisection method, linear interpolation, Newton’s method,

Chapter 7

NUMERICAL INTEGRATION

7.1 Introduction

Definite integrals may be determined analytically by the following methods:

(a) Direct integration.

(b) By means of substitution.

(c) Integration by parts.

(d) Using a recursion formula.

(e) Integration in the complex plane.

(f) Series expansion of the integrand.

If none of these methods can be used, then a numerical method may be implemented. In thischapter, we consider two techniques based on polynomial interpolation. We also consider theapproximation error associated with these techniques, to the extent that we are able to control theaccuracy of the approximation.

7.2 Newton-Cotes formulae

The Newton-Cotes formulae for numerical integration, also called interpolatory quadrature, arederived by using interpolatory polynomial approximations of the integrand.

Suppose a function y = f(x) is known everywhere on [x0, xn]. The interval [x0, xn] is nowdivided into n equally sized subintervals, each of length h where

h =xn − x0

n.

The function y = f(x) is approximated by the interpolating polynomial pn(x) that passes throughthe points (xk, yk), where

xk = x0 + kh

yk = f(xk)

and k = 0, 1, . . . , n. The integral of pn(x) over [x0, xn] is taken as an approximation of∫ xn

x0

f(x) dx.

Recall from (5.6) we have

pn(x) =

n∑

k=0

ykLk(x)

where

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

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

45

Page 46: NUMERICAL ANALYSIS · 2015-10-21 · (a) Nonlinear algebraic equations in one variable - chapter 3 - we investigate the bisection method, linear interpolation, Newton’s method,

46 7. NUMERICAL INTEGRATION

Since xk = x0 + kh, it is natural to make the substitution x = x0 + sh, where s is a continuousvariable:

Lk(s) =sh(sh− h) · · ·

[sh− (k − 1)h

][sh− (k + 1)h

]· · · (sh− nh)

kh(kh− h) · · ·[kh− (k − 1)h

][kh− (k + 1)h

]· · · (kh− nh)

Both the numerator and denominator are divided by hn

Lk(s) =s(s− 1) · · · (s− k + 1)(s− k − 1) · · · (s− n)

k(k − 1) · · · (1)(−1) · · · (k − n)

From the substitution we also have dx = h ds, and so

∫ xn

x0

pn(x) dx =

∫ n

0

(n∑

k=0

ykLk(s)

)

h ds.

Since integration is a linear operation the order of integration and summation may be swapped,so that

∫ xn

x0

pn(x) dx = (nh)1

n

n∑

k=0

yk

∫ n

0

Lk(s) ds

and hence∫ xn

x0

f(x) dx ≈∫ xn

x0

pn(x) dx = (xn − x0)

n∑

k=0

Cnk yk (7.1)

where

Cnk =

1

n

∫ n

0

Lk(s) ds

are the so-called quadrature weights, sometimes known as the Cotes numbers. We will study thetrapezium rule (n = 1) and Simpson’s rule (n = 2).

7.3 Trapezium rule

For n = 1 (linear interpolation) there are two Cotes numbers

C10 =

∫ 1

0

L0 ds =

∫ 1

0

s− 1

0− 1ds =

1

2

C11 =

∫ 1

0

L1 ds =

∫ 1

0

s− 0

1− 0ds =

1

2

From (7.1) we have∫ x1

x0

f(x) dx ≈ 1

2(x1 − x0)(y0 + y1)

=1

2(x1 − x0)

[f(x0) + f(x1)

]. (7.2)

This is simply the area of the trapezium formed by the interpolation polynomial, the x-axis andthe x-intercepts on [x0, x1].

If f(x) is nonlinear we might expect the approximation error to be large, particularly if the

interval of integration is large. Therefore, to evaluate the integral∫ b

af(x) dx in a manner which

allows the error to be controlled, we subdivide the interval [a, b] into N subintervals, each of length

h =b − a

N=

xN − x0

N(7.3)

and the linear approximation (7.2) is performed on each of these subintervals. With

xk = x0 + kh

yk = f(xk)

Page 47: NUMERICAL ANALYSIS · 2015-10-21 · (a) Nonlinear algebraic equations in one variable - chapter 3 - we investigate the bisection method, linear interpolation, Newton’s method,

7. NUMERICAL INTEGRATION 47

for k = 0, 1, . . . , N , we have

∫ b

a

f(x) dx ≈ 1

2h(y0 + y1) +

1

2h(y1 + y2) + · · ·+ 1

2h(yN−1 + yN )

=h

2(y0 + 2y1 + 2y2 + · · ·+ 2yN−1 + yN ) (7.4)

This is known as the composite trapezium rule. Equation (7.4) may also be written as

∫ b

a

f(x) dx ≈ h

2

y0 + yN + 2

N−1∑

j=1

yj

.

Approximation error: In order to study the approximation error in the composite trapez-ium rule, we first obtain an estimate for the error on the first subinterval in (7.4)

∆1 =

∫ a+h

a

f(x) dx − h

2

[f(a) + f(a+ h)

]

A Taylor series expansion of f(x) is made about x = a:

∆1 =

∫ a+h

a

[

f(a) + (x− a)f ′(a) +(x− a)2

2!f ′′(a) + · · ·

]

dx

− h

2

[f(a) + f(a+ h)

]

= [x]a+ha f(a) +

[(x− a)2

2

]a+h

a

f ′(a) +

[(x− a)3

6

]a+h

a

f ′′(a) + · · ·

− h

2

[f(a) + f(a+ h)

]

= hf(a) +h2

2f ′(a) +

h3

6f ′′(a) + · · ·

− h

2

[

2f(a) + hf ′(a) +h2

2f ′′(a) + · · ·

]

To lowest order in h we have

∆1 ≈ −h3

12f ′′(a).

For the total approximation error we have

|∆| ≤ |∆1|+ |∆2|+ · · ·+ |∆N |

≈ h3

12

(|f ′′(a)|+ |f ′′(a+ h)|+ · · ·+ |f ′′(a+ (N − 1)h)|

)

≤ h3

12NM

whereM = max

x∈[a,b]|f ′′(x)| .

Thus, we obtain an upper bound for the approximation error

|∆| ≤ h3

12

(b− a

h

)

M =h2 (b− a)M

12. (7.5)

Since the computing time is determined by N , it follows from (7.3) that it is wise to make has large as possible, for a given accuracy. The important term in (7.5) is the power of h. We seethat the trapezium rule is a practical computational method, since ∆ = O(h2).

Page 48: NUMERICAL ANALYSIS · 2015-10-21 · (a) Nonlinear algebraic equations in one variable - chapter 3 - we investigate the bisection method, linear interpolation, Newton’s method,

48 7. NUMERICAL INTEGRATION

Example 7.1. Determine

I =

∫ 2

0

ex dx

correct to 4 decimal places.From (7.5) we have that

|∆| = h2

12(2 − 0)M ≤ 10−4

where

M = maxx∈[0,2]

∣∣∣∣

d2

dx2ex∣∣∣∣= e2.

Thus, we obtain an upper bound for the size of each subinterval

h ≤(6× 10−4

e2

) 1

2

= 0.0090

and hence a lower bound for the number of subintervals

N ≥ 2

h= 222.22,

and so we choose N = 223, h = 2223 . From (7.4) we have

Itrap =1

2

(2

223

)(

e0 + 2e2

223 + 2e4

223 + · · ·+ 2e444

223 + e2)

= 6.38910

Analytically, we findI = e2 − 1 = 6.38906

and we see that the approximation error is of the correct magnitude

|∆| = |I − Itrap| = 4× 10−5.

7.4 Simpson’s rule

For n = 2 (quadratic interpolation) there are three Cotes numbers:

C20 =

1

2

∫ 2

0

(s− 1)(s− 2)

(0− 1)(0− 2)ds =

1

6

C21 =

1

2

∫ 2

0

(s− 0)(s− 2)

(1− 0)(1− 2)ds =

4

6

C22 =

1

2

∫ 2

0

(s− 0)(s− 1)

(2− 0)(2− 1)ds =

1

6

Equation (7.1) gives the following approximation for the integral:

∫ x2

x0

f(x) dx ≈ (x2 − x0)

(1

6y0 +

4

6y1 +

1

6y2

)

(7.6)

Again, to determine∫ b

af(x) dx with error control, it is necessary to subdivide [a, b] into subinter-

vals, and in this case, an even number 2N . The size of each subinterval is

h =b− a

2N.

Page 49: NUMERICAL ANALYSIS · 2015-10-21 · (a) Nonlinear algebraic equations in one variable - chapter 3 - we investigate the bisection method, linear interpolation, Newton’s method,

7. NUMERICAL INTEGRATION 49

The quadratic approximation is performed on each pair of subintervals. With

xk = x0 + kh

yk = f(xk)

and k = 0, 1, . . . , 2N , it follows from (7.6) that

∫ b

a

f(x) dx ≈ 2h

6

[(y0 + 4y1 + y2) + (y2 + 4y3 + y4) + · · ·

+ (y2N−2 + 4y2N−1 + y2N)].

(7.7)

This is known as the composite Simpson’s rule. Equation (7.7) may also be written as

∫ b

a

f(x) dx ≈ h

3

(

y0 + y2N + 4y1 +N−1∑

k=1

(2y2k + 4y2k+1)

)

.

Approximation error: Similar to the procedure followed for the composite trapezium rule,we first find the approximation error on the first two subintervals:

∆1 =

∫ a+2h

a

f(x) dx− h

3

[f(a) + 4f(a+ h) + f(a+ 2h)

]

We perform a Taylor expansion of the integrand, f(a+ h) and f(a+ 2h):

∆1 =

∫ a+2h

a

[

f(a) + (x− a)f ′(a) +(x− a)2

2!f ′′(a) +

(x− a)3

3!f ′′′(a)

+(x− a)4

4!f (4)(a) + · · ·

]

dx− h

3

[

f(a) + 4

(

f(a) + hf ′(a) +h2

2!f ′′(a)

+h3

3!f ′′′(a) +

h4

4!f (4)(a) + · · ·

)

+

(

f(a) + 2hf ′(a) +(2h)2

2!f ′′(a)

+(2h)3

3!f ′′′(a) +

(2h)4

4!f (4)(a) + · · ·

)]

=

(

2hf(a) + 2h2f ′(a) +4h3

3f ′′(a) +

2h4

3f ′′′(a) +

4h5

15f (4)(a) + · · ·

)

− h

3

(

6f(a) + 6hf ′(a) + 4h2f ′′(a) + 2h3f ′′′(a) +5h4

6f (4)(a) + · · ·

)

The terms of order h to h4 cancel identically, and we have to lowest order in h

∆1 = −h5

90f (4)(a).

Thus, for the total approximation error on [a, b], we have

|∆| ≤ |∆1|+ |∆2|+ · · ·+ |∆2N |

=h5

90

(∣∣∣f (4)(a)

∣∣∣+∣∣∣f (4)(a+ 2h)

∣∣∣+ · · ·+

∣∣∣f (4)(a+ (2N − 2)h)

∣∣∣

)

≤ h5

90NK

whereK = max

x∈[a,b]

∣∣∣f (4)(x)

∣∣∣ . (7.8)

Since hN = b−a2 , it follows that

|∆| ≤ h4(b − a)K

180. (7.9)

Page 50: NUMERICAL ANALYSIS · 2015-10-21 · (a) Nonlinear algebraic equations in one variable - chapter 3 - we investigate the bisection method, linear interpolation, Newton’s method,

50 7. NUMERICAL INTEGRATION

We see that∆ = O(h4)

and Simpson’s method is clearly “faster” than the trapezium method, i.e. it will require fewersubintervals to achieve the same accuracy.

Example 7.2. Determine

I =

∫ 2

0

ex dx

correct to 4 decimal places.From (7.8) we have

K = maxx∈[0,2]

ex = e2

and from (7.9) we have

h ≤(

180 |∆|K(b− a)

) 1

4

=

(180× 10−4

2e2

) 1

4

= 0.187

and so

2N ≥ b− a

h= 10.7

∴ N ≥ 5.35

We choose N = 6, h = 212 = 1

6 . Equation (7.7) then gives

∫ 2

0

ex dx ≈ 1

18

[

e0 + e2 + 4(

e1

6 + e3

6 + · · ·+ e11

6

)

+ 2(

e2

6 + e4

6 + · · ·+ e10

6

)]

= 6.38908

We compare the Simpson approximation with the exact value of the integral

|∆| = |I − ISimpson| = 2.7× 10−5

We see that the error is as expected(≤ 10−4

). We also see that Simpson’s method only requires

13 evaluations of f(x), whereas the Trapezium rule required 223 such evaluations.

7.5 An analytical complication

If∫ b

a f(x) dx exists but the integrand f(x) does not exist somewhere on [a, b], then the numericalevaluation of the integral requires particular care. We consider this case by way of an example.

Example 7.3. Determine

I =

∫ 1

0

x− 1

2 cosxdx.

The integrand f(x) = cosx√x

does not exist at x = 0, and so the integral cannot be determined

using either the Trapezium rule or Simpson’s rule. However, the singularity at x = 0 is of theform x− 1

2 and the integral does indeed exist. To facilitate numerical evaluation we first integrateby parts:

I =[

2x1

2 cosx]1

0+

∫ 1

0

2x1

2 sinxdx = 2 cos 1 + I1

Page 51: NUMERICAL ANALYSIS · 2015-10-21 · (a) Nonlinear algebraic equations in one variable - chapter 3 - we investigate the bisection method, linear interpolation, Newton’s method,

7. NUMERICAL INTEGRATION 51

where the integrand in

I1 =

∫ 1

0

2x1

2 sinxdx

exists everywhere on [0, 1] and so I1 may be determined numerically.

Page 52: NUMERICAL ANALYSIS · 2015-10-21 · (a) Nonlinear algebraic equations in one variable - chapter 3 - we investigate the bisection method, linear interpolation, Newton’s method,

Chapter 8

NUMERICAL METHODS FORORDINARY DIFFERENTIALEQUATIONS

8.1 Introduction

Ordinary differential equations (ODEs) arise in the modelling of systems in the physical, engineer-ing, biological, behavioural, economic and other sciences. The solution of such equations is a veryimportant part of applied mathematics, and the analytical solution of such equations is an activeand fruitful area of research. In practice, however, most ODEs are not solvable by analytical means,and so numerical methods must be used. In this chapter, we focus our attention on initial-valueproblems (IVPs) of the form

dy

dx= f(x, y), y(x0) = y0. (8.1)

As an example, we describe a case that arises in biological research. An ecologist determinesthe following facts regarding an isolated field mouse population:

(a) The birth rate is proportional to the population N .

(b) For a constant food supply the mortality rate is proportional to N1.7.

(c) The proportionality constant k varies with the food supply and is given as a function oftime t in following table.

t (months) 1 2 3 4 5 6 7 8k (months−1 × 10−4) 36 11 1 4 13 28 43 56

For N = N(t) it follows from (a)-(c) that

dN

dt= aN − k(t)N1.7. (8.2)

Of course, this equation may only be solved uniquely if N is known at some specific time t0. Inother words, we need an initial value

N(t0) = N0.

It should be clear that (8.2) cannot be solved analytically and so a numerical method must be usedto obtain N for any given value of t.

52

Page 53: NUMERICAL ANALYSIS · 2015-10-21 · (a) Nonlinear algebraic equations in one variable - chapter 3 - we investigate the bisection method, linear interpolation, Newton’s method,

8. ORDINARY DIFFERENTIAL EQUATIONS 53

8.2 One-step methods

To solve (8.1) on a large interval, we subdivide the interval into n subintervals, each of length h(usually referred to as the step size), and then make the approximation

y(xm+1) ≈ ym+1 = ym + hF (xm, ym), m = 0, 1, . . . , n, (8.3)

consecutively on each subinterval. We use a notation here that will appear throughout thischapter—the exact value of y at xm is denoted y(xm) and the approximate value of y at xm

is denoted ym. Note also that y(x0) = y0 because the initial value is known exactly.In (8.3) the expression

ym+1 = ym + hF (xm, ym) (8.4)

is known as an explicit one-step method, where the function F (x, y) is characteristic of the particularmethod.

In the next three sections we will describe various one-step methods, and their characteristicfunctions F (x, y).

8.3 Euler’s method

The solution y = y(x) of (8.1) may be represented as a curve in the xy- plane. The Euler methoduses a simple geometrical insight—over a small interval any curve may be approximated by astraight line. The function y(x) is approximated by a straight line on the interval [x0, x0+h]. Theline equals y(x0) at x0 and its slope is equal to that of y(x) at x0.

For small h the y-value y1 of the tangent line at x1 will, we assume, be a good approximation

to that of the curve y = y(x). From (8.1) we have

∆y

h=

dy

dx

∣∣∣∣(x0,y0)

= f(x0, y0)

and so∆y = y1 − y0 = hf(x0, y0).

We thus have the approximation

y(x1) ≈ y1 = y0 + hf(x0, y0).

More generally, on the (m+ 1)th subinterval we have

ym+1 = ym + hF (xm, ym) (8.5)

whereF (xm, ym) = f(xm, ym).

8.4 The modified Euler method

In principle, it would seem that greater accuracy could be achieved if we used the trapezium ruleto integrate. We multiply (8.1) by dx to obtain

dy = f(x, y) dx

which we integrate and apply the trapezium rule to the RHS:

∫ y(x1)

y0

dy =

∫ x1

x0

f(x, y) dx

y(x1)− y0 =

∫ x0+h

x0

f(x, y) dx

≈ h

2

[f(x0, y0) + f(x1, y1)

]

Page 54: NUMERICAL ANALYSIS · 2015-10-21 · (a) Nonlinear algebraic equations in one variable - chapter 3 - we investigate the bisection method, linear interpolation, Newton’s method,

54 8. ORDINARY DIFFERENTIAL EQUATIONS

We now have the approximation

y(x1) ≈ y1 = y0 +h

2

[f(x0, y0) + f(x1, y1)

].

The unknown y1 appears on both sides of this equation and may, of course, be found numerically(using Newton’s method, for example). In practice, however, we find that it is sufficient to makean approximation for y1 on the RHS using the Euler method (8.5)

y∗1 = y0 + hf(x0, y0)

The equation thus becomes

y(x1) ≈ y1 = y0 +h

2

[f(x0, y0) + f(x1, y

∗1)].

For the (m+ 1)th subinterval we have

y∗m+1 = ym + hf(xm, ym)

ym+1 = ym +h

2

[f(xm, ym) + f(xm+1, y

∗m+1)

] (8.6)

This is the modified Euler method. The quantity y∗m+1 is sometimes referred to as the predictor,and ym+1 as the corrector.

The method may be written in the same form as (8.4) by letting

F (xm, ym) =f(xm, ym) + f(xm + h, ym + hf(xm, ym))

2.

and thus we obtain

ym+1 = ym + h

(f(xm, ym) + f(xm + h, ym + hf(xm, ym))

2

)

.

8.5 The Runge-Kutta methods

In a Runge-Kutta method of the nth order, the function y(x) in (8.1) is, in principle, written as aTaylor series of order n. We describe here two cases that are generally used.

8.5.1 The second-order Runge-Kutta method (RK2)

Consider the following attempt to approximate y(x1) :

k1 = hf(x0, y0)

k2 = hf(x0 + αh, y0 + βk1)

y1 = y0 + ak1 + bk2

(8.7)

We note that the term k1 represents the Euler approximation. The term bk2 may thus be regardedas an attempt to improve this approximation. The four unknowns a, b, α and β are obtained byrequiring that (8.7) agrees as closely as possible with a Taylor expansion of 2nd-order:

y1 ≈ y(x1)

= y(x0 + h)

= y(x0) + hy′(x0) +h2

2!y′′(x0) + · · ·

= y(x0) + hf(x0, y0) +h2

2

[fx + fyf

]

(x0,y0)+ · · · (8.8)

Page 55: NUMERICAL ANALYSIS · 2015-10-21 · (a) Nonlinear algebraic equations in one variable - chapter 3 - we investigate the bisection method, linear interpolation, Newton’s method,

8. ORDINARY DIFFERENTIAL EQUATIONS 55

where we have used

y′′(x) =df(x, y)

dx=

∂f

∂x+

∂f

∂y

dy

dx= fx + fyf.

Equation (8.7) is also expanded to 2nd-order, using the multivariable Taylor series:

y1 = y0 + ahf(x0, y0) + bhf(x0 + αh, y0 + βk1)

= y0 + ahf(x0, y0) + bh[f(x0, y0 + βk1) + αhfx(x0, y0 + βk1) + · · ·

]

= y0 + ahf(x0, y0) + bh[(f(x0, y0) + βk1fy(x0, y0) + · · ·

)

+αh(fx(x0, y0) + βk1fxy(x0, y0) + · · ·

)]

= y0 + (a+ b)hf(x0, y0) + h2[βbfyf + αbfx

]+ · · · (8.9)

Equating (8.8) and (8.9)), term for term, yields

a+ b = 1 αb =1

2βb =

1

2

Here, we have three equations in four unknowns; one unknown may thus be chosen. A convenientchoice is, for example, b = 1

2 which gives

a =1

2α = β = 1.

For the (m+ 1)th interval we now have

k1 = hf(xm, ym)

k2 = hf(xm + h, ym + k1)

ym+1 = ym +1

2

(k1 + k2

)

= ym + hF (xm, ym)

where

F (xm, ym) =f(xm, ym) + f(xm + h, ym + hf(xm, ym))

2.

We note that the 2nd-order Runge-Kutta method derived here is, in fact, identical to the modifiedEuler method derived previously. A different choice for b would have yielded a different method.For example, the choice b = 1

3 gives a = 23 , α = β = 3

2 .

8.5.2 The fourth-order Runge-Kutta method (RK4)

Here, we have

k1 = hf(x0, y0)

k2 = hf(x0 + ph, y0 + αk1)

k3 = hf(x0 + qh, y0 + βk1 + γk2)

k4 = hf(x0 + rh, y0 + µk1 + νk2 + λk3)

y1 = y0 + ak1 + bk2 + ck3 + dk4

There are 13 unknowns in these equations. Expanding y(x1) = y(x0 + h) and y1 in Taylor seriesto 4th-order, and equating term for term, as done for RK2, we find 11 equations. By choosing

p = q =1

2

Page 56: NUMERICAL ANALYSIS · 2015-10-21 · (a) Nonlinear algebraic equations in one variable - chapter 3 - we investigate the bisection method, linear interpolation, Newton’s method,

56 8. ORDINARY DIFFERENTIAL EQUATIONS

we obtain

β = µ = ν = 0

α = γ =1

2λ = r = 1

a = d =1

6

b = c =1

3

On the (m+ 1)th interval we have, for the 4th-order Runge-Kutta method (RK4)

k1 = hf(xm, ym)

k2 = hf

(

xm +h

2, ym +

1

2k1

)

k3 = hf

(

xm +h

2, ym +

1

2k2

)

k4 = hf(xm + h, ym + k3)

ym+1 = ym +1

6k1 +

2

6k2 +

2

6k3 +

1

6k4

= ym + hF (xm, ym)

where

hF (xm, ym) =1

6k1 +

2

6k2 +

2

6k3 +

1

6k4.

8.6 Approximation error in one-step methods

Recall that an explicit one-step method for solving an IVP has the form

ym+1 = ym + hF (xm, ym).

As shown, the Euler method, the modified Euler method, RK2 and RK4 are all explicit one-stepmethods.

Define the local error at xm in an explicit one-step method as by

εm = y(xm−1) + hF(xm−1, y(xm−1)

)− y(xm).

Note the use of the exact value y(xm) in this definition. The global error at xm in an explicitone-step method is given by

∆m = ym − y(xm)

which is simply the difference between the approximate value ym and the exact value y(xm).

We seek to investigate the propagation of errors in an explicit one-step method. With y(x0) =y0 (because the initial value is known exactly), we have

∆1 = y1 − y(x1)

= y0 + hF (x0, y0)− y(x1)

= ε1

Page 57: NUMERICAL ANALYSIS · 2015-10-21 · (a) Nonlinear algebraic equations in one variable - chapter 3 - we investigate the bisection method, linear interpolation, Newton’s method,

8. ORDINARY DIFFERENTIAL EQUATIONS 57

and

∆2 = y2 − y(x2)

=[y1 + hF (x1, y1)

]− y(x2)

=[y(x1) + ∆1

]+ hF

(x1, y(x1) + ∆1

)− y(x2)

=(y(x1) + ∆1

)+ h

[

F(x1, y(x1)

)+∆1Fy(x1, ξ1)

]

− y(x2)

=[y(x1) + hF (x1, y(x1))− y(x2)

]+∆1

[1 + hFy(x1, ξ1)

]

= ε2 + α1ε1

whereα1 = 1 + hFy(x1, ξ1).

Repeating this process, we obtain

∆3 = ε3 + α2ε2 + α2α1ε1

and∆4 = ε4 + α3ε3 + α3α2ε2 + α3α2α1ε1,

and in general,

∆n =n∑

j=1

n−1∏

k=j

αk

εj

whereαk = 1 + hFy(xk, ξk)

with y(xk) < ξk < y(xk) + ∆k.If |hFy(xk, ξk)| is small then αk ≈ 1, and so

∆n ≈n∑

j=1

εj ,

which is simply an accumulation of local errors. However, this is generally not expected to be thecase, particularly if Fy(xk, ξk) has large magnitude. Note also, if the α’s have magnitude largerthan one, then the term in ε1 could make the most significant contribution to the global error. Ifthe local error has the form

εj = Ejhr+1

where Ej is an appropriate coefficient, then the global error ∆n is

∆n =

n∑

j=1

βjhr+1 =

1

n

n∑

j=1

βj

(nh)hr = β̄(xn − x0)hr

where

βj =

n−1∏

k=j

αk

Ej and β̄ =1

n

n∑

j=1

βj

and we have used nh = xn − x0. Note that ∆n is O (hr).

Order of local errors: For Euler’s method we have

y(xm+1) = y(xm) + hf(xm, y(xm)) +O(h2)

and soεm+1 = y(xm) + hf(xm, y(xm))− y(xm+1) = O(h2)

Page 58: NUMERICAL ANALYSIS · 2015-10-21 · (a) Nonlinear algebraic equations in one variable - chapter 3 - we investigate the bisection method, linear interpolation, Newton’s method,

58 8. ORDINARY DIFFERENTIAL EQUATIONS

which gives r = 1. For the modified Euler method and RK2 we have

y(xm+1) = y(xm) + hF (xm, y(xm)) +O(h3)

due to the fact that y(xm)+hF (xm, y(xm)) is, by construction, equivalent to a second-order Taylorseries (the O(h3) term represents the residual term). Hence, we have

εm+1 = y(xm) + hF (xm, y(xm))− y(xm+1) = O(h3)

and so r = 2. Similarly, we have r = 4 for RK4.

Example 8.1. In the following table we compare the methods derived above for finding y(1)from

dy

dx= x+ y

with y(0) = 0. The stepsize h used in each calculation is indicated. The exact solution at y(1)is 0.71828.

Method h y(1) |∆| at x = 1Euler 1

8 0.56578 0.15

Modified Euler 14 0.69486 0.02

RK4 12 0.71735 0.0009

RK4 14 0.71821 0.00007

Clearly, the higher the order of the method, the more accurate the result. Note that even witha smaller stepsize, Euler’s method is less accurate than the others.