You are on page 1of 137

1

Scientific Computing 2
Lecture Notes in Scientific Computing
MA311-M

Animesh Renanse

Department of Electrical & Electronics Engineering, Indian


Institute of Technology, Guwahati

January 2, 2021
Contents

1 Introduction 7
1.1 Lecture 0 : Course Introduction . . . . . . . . . . . . . . . . . 7
1.1.1 Course Overview and References . . . . . . . . . . . . 7
1.1.2 Evaluation Policy . . . . . . . . . . . . . . . . . . . . . 7

2 Errors in Numerical Computation 9


2.1 Real Numbers, Machine Numbers, Rounding . . . . . . . . . 9
2.1.1 Rounding . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.1.2 Machine Arithmetic . . . . . . . . . . . . . . . . . . . 12

3 The Solution of Non-Linear Equations by Bisection Method 15


3.1 The Bisection Method . . . . . . . . . . . . . . . . . . . . . . . 15
3.2 Error Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

4 Newton-Raphson Method 19
4.1 Geometric Interpretation . . . . . . . . . . . . . . . . . . . . . 20
4.2 Error Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

5 System of Non-Linear Equations 23


5.1 Newton’s Iteration on Non-Linear system of n variables . . . 24

6 The Fixed-Point Method 27


6.1 Fixed Point of a function . . . . . . . . . . . . . . . . . . . . . 27
6.2 Performance Analysis . . . . . . . . . . . . . . . . . . . . . . 30

7 Newton’s Method from Fixed Point Method & Multiple Roots 33


7.1 Newton’s method on Multiple Roots . . . . . . . . . . . . . . 34

8 Interpolation 37
8.1 Lagrange’s Interpolating Polynomial . . . . . . . . . . . . . . 38
8.1.1 Construction of Lagrange’s Interpolating Polynomial 39
8.2 Error in Lagrange’s Interpolation . . . . . . . . . . . . . . . . 41

3
Scientific Computing 4

8.2.1 Example use in Linear Interpolation Error . . . . . . . 42


8.2.2 Example use in Rounding Error Analysis for Linear
Interpolation . . . . . . . . . . . . . . . . . . . . . . . 43
8.2.3 Drawback in Lagrange Interpolation formula . . . . . 44
8.3 Newton’s Interpolation . . . . . . . . . . . . . . . . . . . . . . 44
8.3.1 Explicit formula for computing Divided Differences . 46
8.4 Error in Newton’s Interpolation . . . . . . . . . . . . . . . . . 48
8.5 Relation between Divided Differences and it’s Derivatives . 48
8.5.1 More Insights into Divided Difference . . . . . . . . . 50
8.6 Application of Newton’s Interpolation : Inverse Interpolation 51
8.7 Hermite Interpolation . . . . . . . . . . . . . . . . . . . . . . 52
8.7.1 Example with n=1 . . . . . . . . . . . . . . . . . . . . 53
8.7.2 Uniqueness of Hermite Interpolating Polynomial . . 54
8.8 Hermite Interpolation based on Divided Differences . . . . . 55
8.9 Spline Interpolation . . . . . . . . . . . . . . . . . . . . . . . . 57
8.9.1 Cubic Spline Interpolation . . . . . . . . . . . . . . . . 58
8.9.2 Derivation of Cubic Spline . . . . . . . . . . . . . . . . 59
8.10 Minimizing Property of Cubic Splines . . . . . . . . . . . . . 61

9 Numerical Differentiation 65
9.1 Differentiation via Polynomial Interpolation . . . . . . . . . 66
9.1.1 Simplification of Error Eq. 9.3 . . . . . . . . . . . . . . 67
9.1.2 Discretization . . . . . . . . . . . . . . . . . . . . . . . 70
9.2 Approximation of Derivatives via Taylor’s Theorem . . . . . 72

10 Numerical Integration 75
10.1 Many rules of choosing the interpolating points . . . . . . . 76
10.1.1 Rectangle Rule . . . . . . . . . . . . . . . . . . . . . . 76
10.1.2 Mid-point Rule . . . . . . . . . . . . . . . . . . . . . . 77
10.1.3 Trapezoidal Rule . . . . . . . . . . . . . . . . . . . . . 77
10.1.4 Simpson’s Rule . . . . . . . . . . . . . . . . . . . . . . 78
10.1.5 Corrected Trapezoidal Rule . . . . . . . . . . . . . . . 79
10.2 Error Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
10.2.1 Error in Rectangle Rule . . . . . . . . . . . . . . . . . 81
10.2.2 Error in Mid-Point Rule . . . . . . . . . . . . . . . . . 82
10.2.3 Error in Trapezoidal Rule . . . . . . . . . . . . . . . . 82
10.2.4 Error in Simpson’s Rule . . . . . . . . . . . . . . . . . 82
10.2.5 Error in Corrected Trapezoidal Rule . . . . . . . . . . 83
10.3 Composite Methods . . . . . . . . . . . . . . . . . . . . . . . 83
10.3.1 Composite Rectangle Rule . . . . . . . . . . . . . . . . 84
10.3.2 Composite Mid-Point Rule . . . . . . . . . . . . . . . 85

CONTENTS
5 Scientific Computing

10.3.3 Composite Trapezoid Rule . . . . . . . . . . . . . . . 85


10.3.4 Composite Simpson’s Rule . . . . . . . . . . . . . . . 86
10.3.5 Composite Corrected Trapezoidal Rule . . . . . . . . 86
10.4 Gauss Quadrature Rule . . . . . . . . . . . . . . . . . . . . . . 87
R1
10.4.1 Special case when w( x ) = 1 and −1 g( x )dx ≈ ∑kj=0 A j g( x j ) 88
10.4.2 An Alternate Approach through Newton’s Interpo-
lation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90

11 Numerical Solutions to IVPs for ODEs : One-Step Method 93


11.1 Taylor-Series Method . . . . . . . . . . . . . . . . . . . . . . . 94
11.1.1 Taylor’s Algorithm of Order k . . . . . . . . . . . . . . 94
11.2 Euler’s Method . . . . . . . . . . . . . . . . . . . . . . . . . . 95
11.3 Runge-Kutta Method . . . . . . . . . . . . . . . . . . . . . . . 96
11.4 Systems of Differential Equations . . . . . . . . . . . . . . . . 99

12 Numerical Solutions to IVPs for ODEs : Multi-Step Methods 101


12.0.1 Adams-Bashford Method . . . . . . . . . . . . . . . . 102
12.1 Predictor-Corrector Methods . . . . . . . . . . . . . . . . . . 103
12.1.1 Second-Order Predictor-Corrector Method . . . . . . 104
12.1.2 The Adams-Moulton Method . . . . . . . . . . . . . . 106
12.2 Stability of Multi-Step Methods 1 . . . . . . . . . . . . . . . . 107
12.2.1 Example : Stability of Milne’s Method . . . . . . . . . 109

13 Solutions of Linear Difference Equations 111


13.1 Solutions to homogeneous LDE . . . . . . . . . . . . . . . . . 111
13.2 Solution to Non-homogeneous LDE with constant coefficients113

14 Finite Difference Approximations to Derivatives 115


14.1 Finite Difference Approximations to Derivatives . . . . . . . 116
14.1.1 Functions of one-variable . . . . . . . . . . . . . . . . 116
14.1.2 Functions of two-variables . . . . . . . . . . . . . . . 117
14.2 The Heat Equation . . . . . . . . . . . . . . . . . . . . . . . . 118
14.2.1 Schmidt’s Explicit Scheme . . . . . . . . . . . . . . . . 119
14.2.2 Euler’s Implicit Scheme . . . . . . . . . . . . . . . . . 120
14.2.3 Crank-Nicolson Scheme . . . . . . . . . . . . . . . . . 121
14.2.4 Richardson’s Scheme . . . . . . . . . . . . . . . . . . . 122
14.2.5 DuFort-Frankel Explicit Scheme . . . . . . . . . . . . 122
14.2.6 Weighted Average Approximation . . . . . . . . . . . 123
14.3 Consistency & Stability of Finite Difference Equations . . . . 124
1 This section contains some details which are rigorously explained in the following
chapter.

CONTENTS
Scientific Computing 6

14.4 Stability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126


14.5 Stability Analysis by Matrix Method . . . . . . . . . . . . . . 128
14.5.1 Basic Elements of Matrix Theory . . . . . . . . . . . . 129
14.6 Stability Analysis by von Neumann Method & Lax Equiva-
lence Theorem . . . . . . . . . . . . . . . . . . . . . . . . . . . 132

CONTENTS
Chapter 1

Introduction

1.1 Lecture 0 : Course Introduction


Date : September 4, 2020

We’ll be learning about various numerical techniques to solve some dif-


ficult problems arising in Engineering. We need a measure to analyze per-
formance of such methods, thus performance analysis. Then we also need
to design these computational procedures formally and then implement
them on a computing machine.

1.1.1 Course Overview and References


• Iterative methods for non-linear equations, interpolation, numerical
differentiation and integration, one step and multi-step methods for
ODEs and numerical solutions of PDEs by Finite Difference Methods
(FDMs).

• Kincaid and Cheney; Numerical Analysis: Mathematics of Scientific


Computing

• G.D. Smith, Numerical Solutions of Partial Differential Equations

• Software Requirements : MATLAB

1.1.2 Evaluation Policy


• Two assignments : each 10%

• Two quizzes : each 10%

7
Scientific Computing 8

• Four assignments : each 5%

• Viva Voce : each 10%

• End Semester exam : 30%

Weekly Meeting for questions: Every Friday 10 AM - 10:55 AM

CHAPTER 1. INTRODUCTION
Chapter 2

Errors in Numerical Computation

Lecture 2, September 9, 2020

2.1 Real Numbers, Machine Numbers, Round-


ing
True values are not stored exactly in a computer, it always undergo a
rounding or chopping, and additional operators introduce more errors.

Real Numbers: We adopt binary number system.

x∈R
 
x = ± bn 2 n + bn − 1 2 n − 1 + · · ·

where n is some integer and the binary digits bi takes the value either 0 or
1. Hence we can write in general that,

x = ± (bn bn−1 · · · b0 b−1 b−2 · · · )2

to remind us that we are dealing with binary numbers.

Remark: It’s not true that a finite decimal number will have a finite repre-
sentation in a binary computer. However, to a finite binary number there
always corresponds a finite decimal representation.

Machine Numbers: Two kinds,

9
Scientific Computing 10

• Floating-point number
• Fixed-point number

Floating Point number


Let R (t, s) be the set of real floating point numbers on a computer, it im-
plies that if,

x ∈ R (t, s) implies and is implied by x = f .2e

where,

f = ± ( b− 1 b− 2 · · · b− t ) 2 , e = ± ( c s − 1 c s − 2 · · · c 0 ) 2

Here, t is the number of binary digits allowed by the computer in the frac-
tional part and s is the number of binary digits in the exponent. f is re-
ferred as the mantissa and e is referred to as the exponent of x.

Formula : The largest and smallest magnitude of a floating point number


is given by,
 s
f lmax ( x ) = max | x | = 1 − 2−t 22 −1
x ∈R(t,s)
s (2.1)
f lmin ( x ) = min | x | = 2−2
x ∈R(t,s)

The trivially used terms overflow and underflow refers to the respective
cases when during the course of the computation the number produced
have a modulus greater than f Lmax and less than f lmin .
However, we can still increase the precsion of the computation by intro-
ducing twice the number of allowed digits in the mantissa, i.e. R (2t, s),
this is called double-precision number.

Fixed Point number

This is just the special case that x = f =⇒ e = 0 .

2.1.1 Rounding
Let,

!
x ∈ R, x = ± ∑ b− k 2 − k 2e
k =1

CHAPTER 2. ERRORS IN NUMERICAL COMPUTATION


11 Scientific Computing

be the exact real number in floating point form, thus the rounded number
is,
!
t

x ∈ R, ± ∑ ∗ −k
b− k2 2e (2.2)
k =1

Now, two types of rounding are possible,

• Chopping: x = chop ( x ), it implies that

e∗ = e

b− k = b− k

for all k = 1, 2, · · · , t.

• Symmetric rounding: The rounding up or rounding down in dec-


imal arithmetic based on the first discarded digit. Example, If the
discarded digit ≥ 5, then we round up and otherwise.

Note: In binary arithmetic, if the first discarded binary digit is


1 then we round up and if it is 0, then we round down.

More concretely, we can write the chop and rd operation as the following,

x = rd ( x )
 
 1 −t e  (2.3)
rd ( x ) = chop  x + .2 .2
 
2

 | {z } 
1
adds 2 to make it compatible

In the case of chopping, the absolute error can be calculated as,




| x − chop ( x )| = ± ∑ b−k 2 2
−k e

k = t +1

(2.4)
≤ ∑ 2− k . 2e = 2− t . 2e
k = t +1

CHAPTER 2. ERRORS IN NUMERICAL COMPUTATION


Scientific Computing 12

Similarly, we can calculate the relative error in the case of chopping as,

2− t 2e

x − chop ( x )

± ∑ ∞ b− k 2 − k 2 e

x
k =1
2− t 2e

1 (2.5)
. 2e
|2 {z }
this is minimized

≤ 2 . 2− t

? Note that the upper bound on the relative error is not dependent on e.

??Remark: The machine dependent term eps = 2−t is also called the ma-
chine precision .

Similarly, for the rounding, we can find the relative error to be upper
bounded by the following inequality,

x − rd ( x )
≤ 2− t (2.6)
x

for convenience, we write this in the following equivalent form,

rd ( x ) = x (1 + ε) , |ε| ≤ eps (2.7)

2.1.2 Machine Arithmetic


Definition : Let ◦ denote arithmetic operation (=, +, −, ×, /). Let x, y ∈
R (t, x ) and let f l ( x ◦ y) denote the machine produced result of the arithmetic
operation, then,

f l ( x ◦ y) = x ◦ y (1 + ε) , |ε| ≤ eps (2.8)

Multiplication

Consider values x (1 + ε x ) and y 1 + ε y of x and y contaminated by rel-
ative errors ε x and ε y respectively, in this case, the relative error in the

CHAPTER 2. ERRORS IN NUMERICAL COMPUTATION


13 Scientific Computing

product is,

rd ( x.y) ≈ xy 1 + ε x + ε y

xy − rd ( xy)
=⇒ ≈ εx + εy
xy
ε x.y = ε x + ε y

where we neglect higher order interaction terms of error in product.

Division
x (1 + ε x ) x  
 = (1 + ε x ) 1 − ε y + ε2y − . . .
y 1 + εy y
x 
≈ 1 + εx − εy
y
therefore,
ε yx = ε x − ε y

?Addition and Subtraction


xε x + yε y
 

x (1 + ε x ) + y 1 + ε y = ( x + y ) 1 + , x + y 6= 0
x+y
Therefore, we have the interesting case that,
x y
ε x +y = εx + εy (2.9)
x+y x+y

Therefore, now the relative error also depends on the inputs! Thus the
addition is a benign operation. The error in Eq. 2.9 is called cancellation
error. This type of cancellation error should be avoided in the calcula-
tions as much as possible, thus try to avoid addition and subtraction
directly as much as possible.
√ √
Example 2: If y = x + δ − x, x > 0, |δ| is very small. To avoid can-
cellation error, one should write
δ
y= √ √
x+δ+ x
Thus finding equivalent representations is an important concept for direct Addi-
tion and Subtraction as concretely shown in above example (and in slides).

CHAPTER 2. ERRORS IN NUMERICAL COMPUTATION


Scientific Computing 14

CHAPTER 2. ERRORS IN NUMERICAL COMPUTATION


Chapter 3

The Solution of Non-Linear


Equations by Bisection Method

We want to find the real root of the following type of equations,


f (x) = 0
where f : [ a, b] → R. Here the function f ( x ) might be any of the following,
• a polynomial in x
• a transcendental function
• any combination of the above two.
There is no closed form method to find solutions to such equations, like
the following
e− x − sin x = 0
Thus to solving these, one has to look for approximate methods.

Note that before asking the question that what are the solutions of f ( x ),
we should first answer the question that whether there exists solutions of
f ( x ) = 0 or not. In that extent, we have the following theorem,

Theorem 3.0 : (Bolzano’s Theorem) Assume that f ∈ C [ a, b] and f ( a) f (b) <


0. Then there exists atleast one number r ∈ ( a, b) such that f (r ) = 0.

3.1 The Bisection Method


Given f ∈ C [ a, b] be such that f ( a0 ) f (b0 ) < 0, then the bisection method
can be explained by the following algorithm,

15
Scientific Computing 16

Algorithm

For n = 0, 1, 2, ... do:


a n + bn
1. Set cn = 2 .

2. If | f (cn )| < e (prescribed tolerance), then accept cn , STOP.

3. If f ( an ) f (cn ) < 0, then set an+1 = an and bn+1 = cn , goto Step 1.

4. else set an+1 = cn and bn+1 = bn , goto Step 1.

Remark : To avoid cancellation error, compute the mid-point cn instead


as the following,
bn − a n
cn = an +
2

3.2 Error Analysis


Let [ a0 , b0 ], [ a1 , b1 ], · · · , be successive intervals arising in the algorithm above
with the following holding true,

a0 ≤ a1 ≤ · · · ≤ b0 and b0 ≥ b1 ≥ · · · ≥ a0

We thus have,
1
bn + 1 − a n + 1 = ( bn − a n )
2
Note that the sequence { an } is bounded above and hence converges (in-
creasing or decreasing sequence which is bounded) . Similarly, {bn } also con-
verges.

Since,
1 1
bn − a n = (bn−1 − an−1 ) = · · · = n (b0 − a0 )
2 2
it thus follows that,

1
lim bn − lim an = lim (b0 − a0 )
n→∞ n→∞ n → ∞ 2n

=⇒ lim an = lim bn = r (say)


n→∞ n→∞

CHAPTER 3. THE SOLUTION OF NON-LINEAR EQUATIONS BY


BISECTION METHOD
17 Scientific Computing

Hence, we now see that

lim f ( an ) f (bn ) ≤ 0 =⇒ f 2 (r ) ≤ 0 =⇒ f (r ) = 0
n→∞

But suppose we stop the process at the timestep n, thus we’ll have the
interval [ an , bn ]. Then the best estimate of the root will clearly be cn = an +2 bn .
The error at this timestep en will then be,

1 1
en = |r − c n | ≤ (bn − an ) = n+1 (b0 − a0 )
|2 {z } 2
len of half inter.

Theorem 3.1 : Assume that f ∈ C [ a, b]. Let [ a0 , b0 ], [ a1 , b1 ], · · · , [ an , bn ], · · ·


denotes the intervals in the bisection method. Then lim an and lim bn exists,
n→∞ n→∞
a n + bn
are equal and represent a zero of f . If r = lim cn , where cn = 2 , then,
n→∞

|r − cn | ≤ 2−(n+1) (b0 − a0 )

CHAPTER 3. THE SOLUTION OF NON-LINEAR EQUATIONS BY


BISECTION METHOD
Scientific Computing 18

CHAPTER 3. THE SOLUTION OF NON-LINEAR EQUATIONS BY


BISECTION METHOD
Chapter 4

Newton-Raphson Method

We will first introduce the method for single variable function and then
we will extend it to non-linear functions.

Let x0 be an initial approximation to r and let h be the correction given


to x0 such that
f ( x0 + h ) = 0
Assumption : We assume that f 0 ( x ) exist and is continuous.

Now, by Taylor’s theorem,

0 = f ( x0 + h) = f ( x0 ) + h f 0 ( x0 ) + higher order terms ...

Neglecting the higher order terms for sufficiently small h (note that we are
hence linearizing the original equation), we simply get

f ( x0 )
h=−
f 0 ( x0 )

Hence the first approximation to the exact root is given by

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

Now we repeat the above procedure by substituting our initial approxi-


mation to be x1 . Hence setting x0 ← x1 and repeat the above procedure to
have,
f (x )
h=− 0 1
f ( x1 )

19
Scientific Computing 20

and obtain the second approximation as


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

In general,after nth step an approximaion to the exact root becomes,

f ( xn )
x n +1 = x n − , n≥0
f 0 ( xn )

which is the Newton-Raphson Method.

4.1 Geometric Interpretation


The nth approximation of the root by the Newton-Raphson’s method is
given geometrically by drawing the tangent to f ( x ) at the point xn and
determining the point of intersection of input axes (X-axis in the case of
single variable functions) with this tangent.

More concretely, the equation of the tangent to f at ( x0 , y0 ) is given by,

y − f ( x0 ) = f 0 ( x0 )( x − x0 )

Now the above tangent line meets the x-axis at y = 0, which gives us,
f ( x0 )
x1 ≈ x = x0 −
f 0 ( x0 )
which is just the first approximation.

4.2 Error Analysis


We need some definitions before diving into analysis of Newton’s method.

Definition : (Order of Convergence) Let { xn } be a sequence of real numbers


tending to a limit r and set en = xn − r. If there exists a number p and a con-
stant C > 0 such that
|e |
lim n+1p = C
n→∞ | en |

then p is called the order of convergence of the sequence { xn } and C is called


the asymptotic error constant.

CHAPTER 4. NEWTON-RAPHSON METHOD


21 Scientific Computing

Now, let r be a root of f ( x ) = 0. Let xn be the approximation to r ob-


tained by the Newton Raphson’s method after the nth iteration. Defining
the error en = r − xn , we thus get,

(r − xn )2 00
0 = f (r ) = f ( xn + (r − xn )) = f ( xn ) + (r − xn ) f 0 ( xn ) + f ( ηn )
2
where ηn lies between r and xn . Now solving for r from the above equa-
tions gives us

f ( xn ) (r − xn )2 f 00 ( xn )
r = xn − − . 0
f 0 ( xn ) 2 f ( xn )
(r − xn )2 f 00 ( xn )
= x n +1 − . 0
2 f ( xn )
hence the r − xn+1 = en+1 is given by,

e2n f 00 ( xn ) 1 f 00 (r )
e n +1 = − . 0 ≈ − 0 e2n = Ce2n
2 f ( xn ) 2 f (r )
Hence, the Newtons’s method converges quadratically.

NOTE: Newton’s method yields quadratic convergence only under the


following assumptions
1. r is a simple root of ( x ) = 0, i.e. r should not be a repeated root of f .

2. f 0 ( x ) should not be too small in the neighborhood of he initial choice


x0 , otherwise the steps taken would be too high for convergence.

3. The initial approximation x0 should be chosen very close to the root,


as there are examples, like piecewise defined functions in which f 0 ( x0 )
could be zero, and hence again, the steps would be infinitely large.
But under certain conditions, we can concretely say that the Newton’s
method converges to a root, as stated in the following theorem.

Theorem 4.2 : Let f ∈ C2 ([ a, b]) and the following conditions be satisfied:


1. f ( a) f (b) < 0.

2. f 0 ( x ) 6= 0 ∀ x ∈ [ a, b].

3. f 00 ( x ) is either ≥ 0 or ≤ 0 for all x ∈ [ a, b].

CHAPTER 4. NEWTON-RAPHSON METHOD


Scientific Computing 22

4. At the endpoints a and b,

| f ( a)| | f (b)|
0
< b − a and 0 < b−a
| f ( a)| | f (b)|

Then the Newton’s method converges to the unique root r of f ( x ) = 0 in [ a, b]


for any starting value x0 ∈ [ a, b].

REMARK : The regularity conditions implies the following,

• Bolzano’s Theorem, there exists atleast one root of f ( x ) = 0 in [ a, b].

• Since the function f is now strictly increasing or decreasing, then


there exists only one solution in the interval [ a, b].

• Since the function is now either concave from upward or downward,


thus the derivative f 0 is either increasing or decreasing in [ a, b].

• To make sure the step size isn’t more than the size of the interval
itself.

CHAPTER 4. NEWTON-RAPHSON METHOD


Chapter 5

System of Non-Linear Equations

We extend the Newton’s linearization technique now to system of non-


linear equations. For that aim, we first consider system of two variables
and then extend the same idea to any system of n variables.

Consider the system of two non-linear equations in two independent vari-


ables x1 and x2 as,
f 1 ( x1 , x2 ) = f 2 ( x1 , x2 ) = 0

Let ( x10 , x20 ) be the initial approximation to the exact solution and let the
h01 and h02 be the corrections given to x10 and x20 respectively so that,

f 1 ( x10 + h01 , x20 + h02 ) = f 2 ( x10 + h01 , x20 + h02 ) = 0

Then using Taylor’s expansion upto linear terms would yield

∂ f1 ∂f
f 1 ( x10 + h01 , x20 + h02 ) ≈ f 1 ( x10 , x20 ) + h01 0
+ h02 10
∂x1 ∂x2
∂f ∂f
f 2 ( x10 + h01 , x20 + h02 ) ≈ f 2 ( x10 , x20 ) + h01 10 + h02 10
∂x1 ∂x2

where the partial derivatives are evaluated at ( x10 , x20 ).

Rewriting the above equation in the matrix form,

Jh = −f

23
Scientific Computing 24

where J is the Jacobian matrix J( f 1 , f 2 ), the correction vector h and the


vector f are given by,
 ∂f ∂f 
1 1
0 ∂x20 
J=  ∂x1
∂ f2 ∂ f2
∂x0 ∂x20
 0 1
h1
h=
h02
f ( x0 , x0 )
 
f = 1 10 20
f 2 ( x1 , x2 )
If J is invertible, then the correction vector h is determined simply by,

h = − J −1 f

and then the the first approximation would simply become,

x11 = x10 + h01 , x21 = x20 + h02

and then we can repeat the whole method to get even finer approxima-
tions. Hence, more generally, we get,
 n +1   n   n 
x1 x1 h1
n +1 = x n + h n
x2 2 2

Remark : Few things to keep in mind are as follows,


• At each stage or timestep, we need to solve the following linear sys-
tem,  n
f 1 ( x1n , x2n )
 
h1
J n =−
h2 f 2 ( x1n , x2n )
• The Stopping Criterion is, given the tolerance tol,
|h1n | + |h2n | < tol

5.1 Newton’s Iteration on Non-Linear system of


n variables
Now, we extend the idea introduced earlier for system of 2 variables to a
more general n variables.

CHAPTER 5. SYSTEM OF NON-LINEAR EQUATIONS


25 Scientific Computing

Consider the system,


f(x) = 0
T T
where f = f 1 , f 2 , . . . , f n and x = x1 , x2 , . . . , xn .

The linearization of above equation thus yields the following,

f(x + h) ≈ f(x) + f0 (x)h (5.1)


T
where the n long correction vector h = h1 , h2 , . . . , hn and the Jacobian
matrix of f is,  
∂ f1 ∂ f1
· · ·
0
 ∂x. 1 . ∂xn
.. 
f (x) = J =  .
 . . . . 
∂ fn ∂ fn
∂x · · · ∂xn 1

Then, the correction vector h is simply obtained by,

h = − J −1 f ( x ) (5.2)

after this, we simply get the iteration formula as,

x n +1 = x n + h n
(5.3)
h n = − J −1 f ( x n )

Hence, the whole process can be simply stated as the following,

Retrieve the initial point for the current timestep, then calculate the cor-
rection vector for this timestep by solving the 5.2, add this correction to
the initial point to get the new approximation, substitute the new approx-
imation as the initial approximation for the next timestep. Stop when the
nth power of ln norm of correction vector is less than the tolerance tol hy-
perparameter.

CHAPTER 5. SYSTEM OF NON-LINEAR EQUATIONS


Scientific Computing 26

CHAPTER 5. SYSTEM OF NON-LINEAR EQUATIONS


Chapter 6

The Fixed-Point Method

In this chapter, we look at a new method for computing the roots of a


non-linear function using the properties of it’s fixed point.

6.1 Fixed Point of a function


Definition : (Fixed Point) Let f : R → R be a real valued function. A point x0
is called a fixed point of f if f ( x0 ) = x0 .

Note that the equation f ( x ) = 0 can be put in the following form,

x = g( x )

with which, we can thus conclude that any fixed-point of g above is a so-
lution of f ( x ) = 0.

For example, consider the function f ( x ) = x2 − x − 2. Then, the possi-


ble choices for g( x ) are as follows,

• g( x ) = x2 − 2

• g( x ) = x + 2
2
• g( x ) = 1 + x

x 2 − x −2
• g( x ) = x − m , m 6= 0

We hence get the following definition,

27
Scientific Computing 28

Definition : (Iteration Function) A function g( x ) is called an iteration func-


tion for another function f ( x ), if

g( x ) = x

implies f ( x ) = 0.

Note that we have effectively reduced our problem of determining the


solution of f ( x ) = 0 to the problem of determining a fixed point of the
function g( x ). Hence we just need to find the fixed point of the particular
iteration function to yield us the solution of f ( x ) = 0. For this particular
task, we thus have the following algorithm,

Algorithm :-

1. Given an iteration function g( x ) and a starting point x0 , compute

x n +1 = g ( x n ) , n = 0, 1, 2, . . .

until | xn − r | < e (eps is the hyperparameter tolerance.).

Note that to implement the above algorithm, one needs to ensure the fol-
lowing,

• For given x0 , we should be able to generate x1 , x2 , . . . .

• Sequence { xn } → r.

• r is a fixed point of g( x ), thus, r = g(r ).

A natural question which thus arises is that whether the above algorithm
will guarantee to find the fixed point of g (thus, finding solution of f ( x ) =
0 in the process), for that purpose, we have the following theorem.

Theorem 6.3 : (Existence of Fixed Point) Set I = [ a, b]. Let g( x ) be an it-


eration function satisfying the following conditions,

1. g : I → I.

2. g : I → I is continuous.

3. ∃ a constant 0 < K < 1 such that | g0 ( x )| ≤ K for all x ∈ I

CHAPTER 6. THE FIXED-POINT METHOD


29 Scientific Computing

Then, g( x ) has a unique fixed point r ∈ I and the sequence of iterations { xn }


generated by xn+1 = g( xn ) converges to r.

Proof : Clearly, we first need to show there is a fixed point of g in I. Note


that if g( a) = a or g(b) = b then it’s trivial. However in the case when
g( a) 6= a and g(b) 6= b, first note that g( a), g(b) ∈ I, so we can say that
g( a) > a and g(b) < b.

With this, we then define the following,

h( x ) = g( x ) − x

Clearly, h( x ) ∈ [0, b − a], therefore h( a) > 0 and h(b) < 0 and since h is
continuous, thus by Bolzano’s theorem, there is a point r ∈ I such that
h(r ) = 0 which simply means that g(r ) = r. Hence, there exists a fixed
point of g in I.

Now, to prove that the sequence of iterations generated by xn+1 = g( xn )


converges to r, consider that at a particular instant of the iteration n, we
are e distance away from r, which is, consider,

r − xn = e

If we now calculate e,

e = r − x n = g ( r ) − g ( x n −1 )

which can also be written via the first principle of derivative,

e = r − xn = g0 (ηn )(r − xn−1 )

for some ηn between xn and r.

Now, for iterations to converge,

| e n | ≤ K | e n −1 |
≤ K 2 | e n −2 |
≤ K n | e0 |
Therefore, in the limit n → ∞, since K < 1, en → 0. Which thus implies
that { xn } → r.

Note that we also have to prove the uniqueness of the fixed point, for

CHAPTER 6. THE FIXED-POINT METHOD


Scientific Computing 30

that simply consider two points r, r1 ∈ I which are also fixed points, so,
g(r ) = r and g(r1 ) = r1 . If we set x0 = r, then from the iteration,

x1 = g ( x0 ) = g (r ) = r

therefore, e0 = x0 − r1 = r − r1 and e1 = x1 − r1 = r − r1 . But we know


that en ≤ Ken−1 , therefore, we must have,

e1 ≤ Ke0

Thus, we can conclude that e0 = e1 = 0, which simply implies that r = r1 .

6.2 Performance Analysis


We have the following theorem for the order of the convergence of the
fixed point method.

Theorem 6.4 : Let r be the root of x = g( x ). Assume that g ∈ C m ( Nδ (r ))


for m ≥ 2 where Nδ (r ) denotes a neighbourhood of r. Also assume that,

g 0 ( r ) = · · · = g ( m −1) ( r ) = 0

Then, if the initial guess x0 ∈ Nδ (r ), the iteration given by,

x n +1 = g ( x n ) , n≥0

converges with order m and

( r − x n +1 ) (m ) (r )
m −1 g
lim = (− 1 ) .
n → ∞ (r − x n ) m
| {z m! }
finite value !

Proof : Consider the iteration,

x n +1 = g ( x n )

We can expand it using Taylor’s Theorem as follows,

m −1
( x n − r ) k g ( k ) (r ) ( x n − r ) m g ( m ) ( ηn )
x n +1 = g ( x n ) = ∑ k!
+
m!
k =0

CHAPTER 6. THE FIXED-POINT METHOD


31 Scientific Computing

Now, since g0 (r ) = · · · = g(m−1) (r ) = 0, therefore,

( x n − r ) m g ( m ) ( ηn )
x n +1 = r +
m!
therefore,
xn − r g ( m ) ( ηn )
=
( xn − r )m m!
finally, we get,
r − xn (m) ( η )
m −1 g n
m
= (− 1 )
(r − x n ) m!

CHAPTER 6. THE FIXED-POINT METHOD


Scientific Computing 32

CHAPTER 6. THE FIXED-POINT METHOD


Chapter 7

Newton’s Method from Fixed


Point Method & Multiple Roots

We now analyze the Newton’s method from Fixed Point method.

We know that the fixed point iteration algorithm for the iteration func-
tion of f converges with order m to a fixed point of the iteration function
(refer to previous Theorem 6.4).

Now, recall the Newton’s iteration,


f ( xn )
x n +1 = x n −
f 0 ( xn )
If we want to use fixed point method here, then we should have the fol-
lowing recurrence relation,
x n +1 = g ( x n )
Comparing the above two equations, we thus get g( x ) as,
f ( xn )
g( x ) = x −
f 0 ( xn )
We can indeed verify that g( x ) has the fixed point as r (the root of f ( x ) =
0),
f (r )
g (r ) = r − 0 =r
f (r )
Thus, now we have the iteration function for Newton’s Method. To, how-
ever prove the convergence of Newton’s method and convergence of iter-
ation, we invoke Theorem 6.4.

33
Scientific Computing 34

For this task, we would need to check derivative of the iteration function
g, thus,
( f 0 ( x ))2 − f ( x ) f 00 ( x ) f ( x ) f 00 ( x )
g0 ( x ) = 1 − =
( f 0 ( x ))2 ( f 0 ( x ))2
Again, for x = r, we get g0 as,

g0 ( x ) = 0

, thus we observe that,

f 00 (r )
g(r ) = r , g0 (r ) = 0 , g00 (r ) = 6= 0
f 0 (r )

Therefore from Theorem 6.4, Newton’s method has second order conver-
gence.

7.1 Newton’s method on Multiple Roots


Definition : (Root with multiplicity) If r ∈ I is a root of f ( x ) = 0 with
multiplicity m > 1, then

f ( x ) = ( x − r )m h( x ) , where h( x ) 6= 0

and h( x ) is continuous at x = r. Also, if h ∈ C m ( I ), then

f (r ) = f 0 (r ) = · · · = f (m−1) = 0 and f m (r ) 6= 0

Now, since we want to use Newton’s method to find the root of f ( x ) = 0


where f has root with multiplicity > 1, thus we first need to find it’s iter-
ation function.

Note that since f ( x ) = ( x − r )m h( x ) and

f 0 ( x ) = ( x − r ) m h 0 ( x ) + m ( x − r ) m −1 h ( x )

thus, we get the iteration function (discussed previously for Newton’s It-
eration) g( x ) simply as,

f (x) ( x − r )m h( x ) ( x − r )h( x )
g( x ) = x − 0
= x − =
f (x) m 0
( x − r ) h ( x ) + m( x − r ) m − 1 h( x ) ( x − r )h0 ( x ) + mh( x )

CHAPTER 7. NEWTON’S METHOD FROM FIXED POINT METHOD &


MULTIPLE ROOTS
35 Scientific Computing

Again, you can check that g( x ) has the fixed point as r, g(r ) = r.

Now, to find the order of convergence of Newton’s Method for function


f (which has root with higher multiplicity), we would again invoke the
Theorem 6.4. Now to use this theorem, we need to find the amount of
times we can differentiate g and still get a continuous function which is
not zero at the point x = r, so to check it, we start differentiating g as
follows,
 
0 h( x ) d h( x )
g (x) = 1 − − (x − r)
( x − r )h0 ( x ) + mh( x ) dx ( x − r )h0 ( x ) + mh( x )

Now this implies the following,

1
g 0 (r ) = 1 − 6= 0
m
Hence the convergence of Newton’s method for functions with multiple
roots is Linear (1st Order).

Now a natural question to ask is whether we can make the convergence bet-
ter?

Now, To regain the 2nd order convergence, notice in the above equation
that g0 ( x ) can become 0 if we had m (the multiplicity of the root r) multi-
plied with 2nd term of g0 ( x ). So, we can now simply modify the Newton’s
Iteration formula to the following,

f (x)
x n +1 = x n − m (7.1)
f 0 (x)

which thus implies that we have the modified iteration function g( x ) as,

f (x)
g( x ) = x − m
f 0 (x)

Hence, we can easily verify now that,

g (r ) = g 0 (r ) = 0

Thus, using Theorem 6.4, we can certainly claim that the modified New-
ton’s Iteration formula Eq. 7.1 for functions with multiple roots has sec-
ond order convergence.

CHAPTER 7. NEWTON’S METHOD FROM FIXED POINT METHOD &


MULTIPLE ROOTS
Scientific Computing 36

CHAPTER 7. NEWTON’S METHOD FROM FIXED POINT METHOD &


MULTIPLE ROOTS
Chapter 8

Interpolation

Approximation of functions with few values from it’s range.

To see why we would need this, consider two points P( x0 , f ( x0 )) and


Q( x1 , f ( x1 )). The linear curve joining PQ is,

f ( x1 ) − f ( x0 )
y − f ( x0 ) = ( x − x0 )
x1 − x0
If we set y = p( x ), then the above equation can be re-arranged to,

f ( x0 )( x − x1 ) − f ( x1 )( x − x0 )
p( x ) =
x0 − x1
= f ( x0 ) L0 ( x ) + f ( x1 ) L1 ( x )
x − x1 x − x0
where L0 ( x ) = x0 − x1 and L1 ( x ) = x0 − x1 .

Importantly observe that p( x0 ) = f ( x0 ) and p( x1 ) = f ( x1 ). Thus, we


get the correct value of f at the two points at which we know the value
of f . We in this chapter would extend this idea of fitting a linear curve
between points of any function to fitting a polynomial curve between the
points.

Definition : (Interpolation) Given a set of (n + 1) data points ( xi , f ( xi )) , i =


0, 1, . . . , n, where xi ’s are distinct, find a function p( x ) such that

p ( xi ) = f ( xi ) , i = 0, 1, . . . , n

The process of finding such a function p( x ) is called Interpolation. If p( x ) is a


polynomial then the process is called Polynomial Interpolation and p( x ) is called

37
Scientific Computing 38

Interpolating Polynomial.

? Clearly, such a definition raises the following three questions which are
important to answer,
1. Does such a p( x ) exists?
2. If p( x ) exists, then is it unique?
3. And if p( x ) exists, then how to construct it?
To answer the Question 1, we present the following theorem.

The Weierstrass Approximation Theorem for existence of p( x )

Theorem 8.5 : (The WAT) Let f ∈ C [ a, b]. Then for every e > 0, there is a
polynomial p( x ) such that
| p( x ) − f ( x )| < e ∀ x ∈ [ a, b]
This theorem thus guarantees the existence of a polynomial function p for
approximating any continuous function f in a bounded interval. Hence
the Question 1 is now answered in an affirmative manner.

To answer Question 2 & 3, we would need to look at particular methods


for finding the polynomial p( x ), we thus look at the first method of such
construction, the Lagrange’s Interpolation.

8.1 Lagrange’s Interpolating Polynomial


We here wish to find a polynomial p( x )
p ( x ) = a0 + a1 x + · · · + a n x n
where a0 , a1 , . . . , an are to be determined so that,
p( xi ) = f ( xi ) , i = 0, 1, . . . , n
The above condition thus forms a system of n + 1 equations as follows
a0 + a1 x0 + a2 x02 + · · · + an x0n = f ( x0 )
a0 + a1 x1 + a2 x12 + · · · + an x1n = f ( x1 )
.. ..
.=.
a0 + a1 xn + a2 xn2 + · · · + an xnn = f ( xn )

CHAPTER 8. INTERPOLATION
39 Scientific Computing

In Matrix form, we can write it to be,

Xa = F

where,

x0 x02 . . . x0n
 
 x x2 . . . x n 
 1 1 1
X =  .. .. .. 
. . ... . 
xn xn2 . . . xnn
 T
a = a0 a1 . . . a n
 T
F = f ( x0 ) f ( x1 ) . . . f ( x n )

Therefore, we can find the vector a quite easily. But, it can oly be the case
if X is invertible (or non-singular), to that extent, we have the following
definition.

Definition : (Vandermonde Matrix) The matrix X is called Vandermonde Ma-


trix and
det( X ) = ∏ ( xi − x j ) 6= 0
0≤ i < j ≤ n

Hence it implies that Xa = F has a unique solution, answering the


Question 2 in the process!

BUT! The inverse of Vandermonde Matrix is EXTREMELY COSTLY to


compute, we need to solve n + 1 linear equations!. Thus we do not use
this to construct Lagrangian Polynomial.

Now to answer Question 3 in the context of Lagrange’s Interpolation, we


see now how to construct p( x ) in a much more efficient manner.

8.1.1 Construction of Lagrange’s Interpolating Polynomial


Consider the special interpolating problem:

f ( xi ) = 1 , f ( x j ) = 0 for j 6= i for some i , 0 ≤ i ≤ n

We wish to find a polynomial of degree ≤ n with the given n zeros


x j , j 6= i

CHAPTER 8. INTERPOLATION
Scientific Computing 40

As shown in the opening example of this chapter, we can define the fol-
lowing,

Li ( x ) = c( x − x0 ) . . . ( x − xi−1 )( x − xi+1 ) . . . ( x − xn )

where c is some constant.

Clearly, we want Li ( xi ) = f ( xi ) = 1, therefore, we can find c as the follow-


ing,
1
c=
( xi − x0 ) . . . ( xi − xi−1 )( xi − xi+1 ) . . . ( xi − xn )
We would hence get the following form of Li ( x ),

x − xj
Li ( x ) = ∏ xi − x j i = 0, 1, . . . , n (8.1)
j 6 =i

Note that Li ( x ) is a product of n linear factors with deg( Li ( x )) = n. The


functions Li ( x ) are called Lagrange Basis Functions with the following
property satisfied for special inputs,
(
1 j=i
Li ( x j ) = , j = 0, . . . , n. (8.2)
0 j 6= i

We can thus construct the Lagrange Interpolating Polynomial for any gen-
eral problem now as,
n
p( x ) = ∑ f ( xi ) Li ( x ) (8.3)
i =0
= f ( x0 ) L0 ( x ) + · · · + f ( x n ) L n ( x )

We can, once again, see that p( x j ) = f ( x j ) , j = 0, 1, . . . , n.

We still however need to study whether this construction is unique or not


(Question 2), again, to that extent, consider q( x ) is another polynomial of
degree ≤ n such that,

q( xi ) = f ( xi ) , i = 0, 1, . . . , n

Now, define r ( x ) = p( x ) − q( x ). Since deg(r ( x )) ≤ n, therefore r ( xi ) =


p( xi ) − q( xi ) = 0 for all i = 0, 1, . . . , n. But since r ( x ) is of degree ≤ n with
n + 1 zeros, therefore, r ( x ) = 0 and thus p( x ) = q( x ).

CHAPTER 8. INTERPOLATION
41 Scientific Computing

Finally the formula


n
pn ( x ) = ∑ f ( xi ) Li ( x ) (8.4)
i =0

where Li ( x ) is as given in Eq. 8.1 is called the Lagrange’s formula for


Interpolating Polynomial.

8.2 Error in Lagrange’s Interpolation


Theorem 8.6 : (Interpolation Error) Let f ∈ C n+1 [ a, b]. If pn ( x ) is a polyno-
mial of degree ≤ n with pn ( xi ) = f ( xi ), i = 0, 1, . . . , n, where xi ’s are distinct
points in [ a, b], then for all t ∈ [ a, b], there exists ζ = ζ (t) ∈ ( a, b) such that,

n
f ( n +1) ( ζ ) n
E(t) = f (t) − pn (t) = f (t) − ∑ f ( x j ) L j (t) =
( n + 1) ! ∏
(t − x j )
j =0 j =0

Proof : If t = xi , i = 0, 1, . . . , n, then LHS = RHS trivially. However for


t 6= xi for all i, define the following,

E( x ) = f ( x ) − pn ( x )

where pn ( x ) = ∑nj=0 f ( x j ) L j ( x ).

Now set,
n
ψ( x )
G ( x ) = E( x ) −
ψ(t)
E(t) where ψ( x ) = ∏( x − x j )
j =0

Clearly, G ( x ) ∈ C n+1 [ a, b].

Now, further notice that,


ψ ( xi )
G ( xi ) = E ( xi ) − E(t) = 0 where i = 0, 1, . . . , n
ψ(t)

and
G (t) = E(t) − E(t) = 0
Therefore, G has n + 2 zeros on [ a, b]. By Mean Value Theorem, the G 0
has n + 1 distinct zeros in [ a, b], G 00 has n distinct zeros in [ a, b] and so on.

CHAPTER 8. INTERPOLATION
Scientific Computing 42

Hence the G (n+1) ( x ) has only one zero in [ a, b]. Therefore this implies that
there exists ζ ∈ [ a, b] such that G (n+1) (ζ ) = 0. Thus,

ψ ( n +1) ( x ) ( n + 1) !
G ( n +1) ( x ) = E ( n +1) ( x ) − E ( t ) = f ( n +1) ( x ) − E(t)
ψ(t) ψ(t)

Hence, putting x = ζ we get,

( n + 1) !
G ( n +1) ( ζ ) = 0 = f ( n +1) ( ζ ) − E(t)
ψ(t)

which implies,

f ( n +1) ( ζ ) f ( n +1) ( ζ ) n
( n + 1) ! ∏
E(t) = ψ(t) = (t − x j )
( n + 1) ! j =0

Remarks : Note that this error E(t) is only of theoretic importance as we


would need f (n+1) and we most of the time use interpolation when we
only have the data points, not the generating function f itself.

8.2.1 Example use in Linear Interpolation Error


In Linear Interpolation, we have two points, say, ( x0 , f ( x0 )) and ( x1 , f ( x1 )).
We construct the Interpolation Error for the Linear Interpolation through
the use of Theorem 8.6.
f 00 (ζ )
f ( t ) − p1 ( t ) = (t − x0 )(t − x1 )
2!
Now, if we assume that f 00 is upper bounded by M, i.e.,
00
f ( x ) ≤ M ∀ x ∈ [ x0 , x1 ]

With this, we can now form the bound on the error f (t) − p1 (t) as follows,
00
f (ζ )
| f (t) − p1 (t)| ≤ (t − x0 )(t − x1 )
2!
M
≤ |(t − x0 )(t − x1 )|
2
Now, to convert the bound in terms of x0 and x1 only, we should maximize
it. In doing so, we would need to find the maximum value of |(t − x0 )(t −

CHAPTER 8. INTERPOLATION
43 Scientific Computing

x1 )| over t ∈ [ x0 , x1 ], which can easily be seen to be achieved when t =


x0 + x1
2 , thus, we get the more general upper bound on the error as,

M
| f (t) − p1 (t)| ≤ ( x0 − x1 )2 (8.5)
8
Thus the Eq. 8.5 gives us the bound on the error that can be incurred in
Linear Interpolation over [ x0 , x1 ] when the f 00 ≤ M.

8.2.2 Example use in Rounding Error Analysis for Linear


Interpolation
Due to Rounding-Off in computer arithmetic, we incur error in calacula-
tion of function values, thus,
f ( x 0 ) = f 0 + e0 f ( x 1 ) = f 1 + e1
where e0 and e1 are rounding error.

Now, define the error ε( x ) as,


( x1 − x ) f 0 + ( x − x0 ) f 1
ε( x ) = f ( x ) − , x0 ≤ x ≤ x1
( x1 − x0 )
Now let’s substitute the approximation of f 0 = f ( x0 ) − e0 , f 1 = f ( x1 ) − e1
instead to get the following,
( x 1 − x ) f ( x 0 ) + ( x − x 0 ) f ( x 1 ) ( x 1 − x ) e0 + ( x − x 0 ) e1
ε( x ) = f ( x ) − +
( x1 − x0 ) ( x1 − x0 )
| {z } | {z }
Interpolation Error Rounding Error
= E( x ) + R( x )
(8.6)
Note that for Linear Interpolation Error, we found the bound in Eq. 8.5 and
Rounding Error are themselves bounded by max(|e0 |, |e1 |) as x ∈ [ x0 , x1 ].
Hence, to find a bound on Rounding Error in Linear Interpolation, we
simply combine these two results,
M
| E( x )| ≤ ( x1 − x0 )2
8 (8.7)
max | R( x )| ≤ max(|e0 |, |e1 |)
x0 ≤ x ≤ x1

Now, if the difference between x1 and x0 is h, then,


M
|ε( x )| ≤ h2 + max(|e0 |, |e1 |) (8.8)
8

CHAPTER 8. INTERPOLATION
Scientific Computing 44

8.2.3 Drawback in Lagrange Interpolation formula


The Eq. 8.4 shows the formula for Lagrangian Interpolation. Note that this
formula would create a new Polynomial each time the value of n increases,
that is, if we get more and more data, we cannot reuse the information con-
tained in the previous polynomials.

In practie, one is uncertain about how many interpolation points to use.


If one increases the Interpolation points then the functions Li ( x ) have to be
recomputed and the previous computation of Li ( x ) is essentially wasted.
In other words, in calculating pk ( x ), no obvious advanatage can be taken
of the fact that one already has pk−1 ( x ) available.

8.3 Newton’s Interpolation


Let ( xi , f ( xi )) , i = 0, 1, . . . , n be the set of n + 1 data points, where xi ’s are
distinct. We know that there exists a unique polynomial pn ( x ) of degree
≤ n by Theorem 8.5 such that,
p( xi ) = f ( xi ) , i = 0, 1, . . . , n
To see how the Interpolating Polynomial in Newton’s form overcome the
drawback of Lagrangian Interpolation, consider the following Interpolat-
ing Polynomial,
pn ( x ) = c0 + c1 ( x − x0 ) + c2 ( x − x0 )( x − x1 ) + · · · + cn ( x − x0 )( x − x1 ) . . . ( x − xn−1 )
n j −1
= ∑ c j q j (x) , where q j (x) = ∏ ( x − xk )
j =0 k =0
(8.9)
Note that the Polynomials q j ( x ) forms a basis for the Newton’s Interpo-
lating Polynomial in Eq. 8.9,
q0 ( x ) = 1
q1 ( x ) = ( x − x0 )
.. ..
.=.
q n ( x ) = ( x − x 0 ) . . . ( x − x n −1 )
Now, from the interpolating condition, we should have the following,
n
p n ( xi ) = ∑ c j q j ( xi ) = f ( xi ) , for all i = 0, 1, . . . , n (8.10)
j =0

CHAPTER 8. INTERPOLATION
45 Scientific Computing

Representing this as a matrix formulation yields us,

Ac = F (8.11)
 T  T
where Aij = q j ( xi ), c = c0 c1 . . . cn and F = f ( x0 ) f ( x1 ) . . . f ( xn ) .

It can be seen very easily that Matrix A is Lower Triangular as,


j −1
(
∏k=0 ( xi − xk ) if i > j − 1
q j ( xi ) = (8.12)
0 if i ≤ j − 1

To see the advantage of Newton’s Interpolation more closely, consider the


case when n = 2, for that, the Interpolating Polynomial would be,

p2 ( x ) = c0 + c1 ( x − x0 ) + c2 ( x − x0 )( x − x1 )
p2 ( x0 ) = c0
(8.13)
p2 ( x1 ) = c0 + c1 ( x1 − x0 )
p2 ( x2 ) = c0 + c1 ( x2 − x0 ) + c2 ( x2 − x0 )( x2 − x1 )

and for this case, the equivalent matrix form for interpolation condition
is,
    
1 0 0 c0 f ( x0 )
1 ( x1 − x0 ) 0   c1  =  f ( x1 )  (8.14)
1 ( x2 − x0 ) ( x2 − x0 )( x2 − x1 ) c2 f ( x2 )

? Now note that c0 only depends of f ( x0 ), x1 depends only on f ( x0 )


and f ( x1 ) and so on. Thus, we conclude that In general, cn depends on
f ( x0 ), . . . , f ( xn ), which we write as the following,

c n = f [ x0 , . . . , x n ] (8.15)

Hence we define the symbol f [ x0 , . . . , xn ] as the coefficients of qn when


p( x ) = ∑nk=0 ck qk ( x ) interpolates f at x0 , . . . , xn .

With the previous discussion, we arrive at the following form of Newton’s


formula for the interpolating polynomial,

pn ( x ) = f [ x0 ] + f [ x0 , x1 ]( x − x0) + f [ x0 , x1 , x2 ]( x − x0 )( x − x1 ) + . . .
+ f [ x0 , . . . , xn ]( x − x0 )( x − x1 ) . . . ( x − xn−1 )
(8.16)

CHAPTER 8. INTERPOLATION
Scientific Computing 46

or in more compact form,

n k −1
pn ( x ) = ∑ f [ x0 , . . . , x k ] ∏ ( x − x j )
k =0 j =0 (8.17)
| {z }
qk ( x )

And now it should be clear how the Eq. 8.17 does not changes the pk ’s
when new point is added. Note that when indeed a new point (n + 2) is
added, then all we need to calculate is f [ x0 , . . . , xn+1 ]( x − x0 ) . . . ( x − xn )
and add it to the pn ( x ), to yield us the required pn+1 ( x ).

Now the next question that arises, is how can we find f [ x0 , . . . , xk ] which
is the coefficient of qk ( x ) in Eq. 8.17? Note that this coefficient is called
divided differences, as explained next.

8.3.1 Explicit formula for computing Divided Differences


First note that,
p n ( x0 ) = f ( x0 ) = c0 = f [ x0 ]
Similarly,

pn ( x1 ) = f ( x1 ) = c0 + c1 ( x1 − x0 ) = f ( x0 ) + f [ x0 , x1 ]( x1 − x0 )

which simply implies that,

f ( x1 ) − f ( x0 )
f [ x0 , x1 ] =
x1 − x0

Hopefully, now the motivation behind the name divided differences would
be clear in reader’s mind.

Theorem 8.7 : In general, we can represent higher order divided differ-


ence of a function f using the following formula,

f [ x 1 , x 2 , . . . , x n ] − f [ x 0 , x 1 , . . . , x n −1 ]
f [ x0 , x1 , . . . , x n ] = (8.18)
x n − x0

Proof : Let pk ( x ) be the polynomial of degree ≤ k such that,

pk ( xi ) = f ( xi ) , i = 0, 1, . . . , k

CHAPTER 8. INTERPOLATION
47 Scientific Computing

Also, let q( x ) be the polynomial of degree ≤ n − 1 such that such that,


q( xi ) = f ( xi ) , i = 1, 2, . . . , n
With these two polynomials, we construct polynomial pn ( x ) as follows
x − x0
pn ( x ) = q( x ) + [q( x ) − pn−1 ( x )] (8.19)
x n − x0
Note how the above polynomial manages to be of degree atmost n by the
combination of q( x ) (degree ≤ n − 1) and pn−1 ( x ) (degree ≤ n − 1), where
a linear term is multiplied to the latter.

In Eq. 8.19, note that for i = 1, 2, . . . , n − 1, we have


x i − x0
p n ( xi ) = q ( xi ) + [q( xi ) − pn−1 ( xi )]
x n − x0 (8.20)
= f ( xi )
Hence we are also complying to the interpolating condition with the poly-
nomial pn ( x ) for i = 1, . . . , n − 1. But what about i = 0 and i = n?
pn ( x0 ) = q( x0 ) − [q( x0 ) − pn−1 ( x0 )] = pn−1 ( x0 ) = f ( x0 )
(8.21)
pn ( xn ) = q( xn ) = f ( xn )

So, we have pn which obeys the interpolating condition. Thus LHS and
RHS of Eq. 8.20 can be compared componentwise.

Now, in Eq. 8.19, consider the coefficients of x n in LHS and both parts
of RHS. Since both sides are equal, then so would be the coefficients,
Coefficient of x n in pn ( x ) = f [ x0 , . . . , xn ] (from Eq. 8.17)
1
Coefficient of x n in xq( x ) = f [ x1 , . . . , xn ] (q( x ) is only dependent on x1 , . . . , xn )
x n − x0
1
Coefficient of x n in xpn−1 ( x ) = f [ x0 , . . . , xn−1 ] (pn ( x ) is only dependent on x0 , x1 , . . . , xn )
x n − x0
(8.22)
we hence get
f [ x 1 , x 2 , . . . , x n ] − f [ x 0 , x 1 , . . . , x n −1 ]
f [ x0 , x1 , . . . , x n ] =
x n − x0

CHAPTER 8. INTERPOLATION
Scientific Computing 48

Small Example on Divided Differences


Using the Theorem 8.7, we can calculate the coefficients of Newton’s In-
terpolating polynomial pn ( x ) as,
f [ x0 ] = f ( x0 )
f [ x1 ] − f [ x0 ] f ( x1 ) − f ( x0 )
f [ x0 , x1 ] = =
x1 − x0 x1 − x0 (8.23)
f ( x2 )− f ( x1 ) f ( x1 )− f ( x0 )
f [ x1 , x2 ] − f [ x0 , x1 ] x2 − x1 − x1 − x0
f [ x0 , x1 , x2 ] = =
x2 − x0 x2 − x0

8.4 Error in Newton’s Interpolation


Theorem 8.8 : Let pn ( x ) be the polynomial of degree ≤ n such that pn ( xi ) =
f ( xi ) for all i = 0, 1, . . . , n. If t is a point such that t 6= x0 , x1 , . . . , xn , then,
n
f ( t ) − p ( t ) = f [ x0 , x1 , . . . , x n , t ] ∏ ( t − x j ) (8.24)
j =0

Proof : Looking at Eq. 8.17, we see that qn ( x ) only depends on x0 , . . . , xn−1 .


Hence, let q( x ) be the polynomial of degree ≤ n + 1
q( xi ) = f ( xi ) , i = 0, 1, . . . , n and q(t) = f (t)
which contains an extra interpolating point t. With this, we can obtain the
q( x ) by simply adding a new term to get pn+1 ( x ) term from p( x ), that is,
n
q ( x ) = p ( x ) + f [ x0 , x1 , . . . , x n , t ] ∏ ( x − x j )
j =0

and since q(t) = f (t),


n
f ( t ) = p ( t ) + f [ x0 , x1 , . . . , x n , t ] ∏ ( t − x j )
j =0

8.5 Relation between Divided Differences and


it’s Derivatives
Theorem 8.8 gives us the error in Newton’s Interpolation Method. How-
ever, note that we cannot evaluate the term f [ x0 , x1 , . . . , t] without know-
ing the value f (t)!.

CHAPTER 8. INTERPOLATION
49 Scientific Computing

But as we will see in this section, the number f [ x0 , x1 , . . . , xn , t] is closely


related to the (n + 1)th derivative of f ( x ).

Theorem 8.9 : Let f ∈ C k ([ a, b]). If x0 , x1 , . . . , xk are k + 1 distinct points


in [ a, b], then there exists ξ ∈ ( a, b) such that,

f (k) ( ξ )
f [ x0 , x1 , . . . , x k ] = (8.25)
k!

Proof : Clearly, the proof would involve the use of Mean Value Theorem
as it guarantees the existence of a point in the interval where f is continuously
differentiable such that divided differnece on endpoints is equal to the tangent line
at that point.

With that motivation, for k = 1,


f ( x1 ) − f ( x0 )
f [ x0 , x1 ] = = f 0 (ξ )
x1 − x0
for some ξ ∈ ( a, b).

Now, consider the following polynomial,

ek ( x ) = f ( x ) − pk ( x )

Note, that it has k + 1 zeros x0 , x1 , . . . , xk in [ a, b]. We can thus use the


Rolle’s Theorem which says that if a differntiable function in an open interval
attains same value at two points in that interval, then there exists a point in the
same open interval where the derivative is zero.

However, using Rolle’s Theorem, we can see that since ek is a polynomial


then ek0 ( x ) = 0 has atleast k zeros in ( a, b), ek00 = 0 has k − 1 zeros in ( a, b)
(k)
and so on. Finally, ek = 0 would only have one zero in ( a, b). That is,
there exists ξ ∈ ( a, b) such that
(k)
ekk (ξ ) = 0 =⇒ f (k) (ξ ) = pk (ξ )
(k)
Now, note from Eq. 8.17, that pk ( x ) = f [ x0 , . . . , xk ]k! We thus get the
required result,
f (k) ( ξ )
f [ x0 , x1 , . . . , x k ] =
k!

CHAPTER 8. INTERPOLATION
Scientific Computing 50

QED

With the Theorem 8.9 in hand which relates the kth divided difference with
the kth derivative of f , we can reform the Theorem 8.8 to get a new form
of error in Newton’s Interpolation as follows,

Theorem 8.10 : Let f ∈ C n+1 ([ a, b]). If pn ( x ) is a polynomial of degree ≤ n


such that,
pn ( xi ) = f ( xi ) , i = 0, 1, . . . , n
Then, for all t ∈ [ a, b], there exists ξ = ξ (t) ∈ ( a, b) such that,
n
f (n+1)(ξ )
f (t) − pn (t) =
( n + 1) ! ∏(t − x j ) (8.26)
j =0

Proof : Just use Theorem 8.8 in view of Theorem 8.9, QED.

We now see some more interesting relations between divided differences


and derivatives apart from Newton’s Interpolation Error.

8.5.1 More Insights into Divided Difference


1. Note that
f ( x ) − f ( x0 )
lim f [ x0 , x ] = lim = f 0 ( x0 )
x → x0 x → x0 x − x0
Which suggests that the first divided difference at two identical
points is the derivative of f at that point, i.e.
f [ x0 , x0 ] = f 0 ( x0 )

2. For any n + 1 distinct points x0 , x1 , . . . , xn in [ a, b] and any f ∈ C n [ a, b],


we have from Theorem 8.9 that
f (n) ( ξ )
f [ x0 , . . . , x n ] =
n!
Thus, if we let all xi → x0 for all i = 1, 2, . . . , n with ξ being con-
strained to be in between them, then ξ → x0 too. We thus obtain,

f ( n ) ( x0 )
f [ x0 , . . . , x0 ] = (8.27)
| {z } n!
n + 1 times

CHAPTER 8. INTERPOLATION
51 Scientific Computing

8.6 Application of Newton’s Interpolation : In-


verse Interpolation
An interesting application of Newton’s Interpolation is that of Inverse In-
terpolation, in which the aim is to approximate the solution of the non-linear
equation,
f (x) = 0 (8.28)
. Let x0 ≈ ξ and x1 ≈ ξ be two approximations of a root ξ of Eq. 8.28.
Assuming that f is monotone near ξ, then,

y = f ( x ) =⇒ x = f −1 (y) = g(y) (8.29)

Note that in view of Eq. 8.29, the root ξ is,

ξ = f −1 (0 ) = g (0 )

Hence our aim is to evaluate g(0).

Now, we compute

y0 = f ( x0 )
y1 = f ( x1 )

which implies that

x0 = g ( y0 )
x1 = g ( y1 )

We would now try to form an approximation of g(y), the inverse of f , in


order to find the value of g(0). For this, the first divided difference is,
g ( y0 ) − g ( y1 )
g [ y0 , y1 ] =
y0 − y1
Using the above, we can now improve the approximation of ξ by linear
interpolation (refer to Eq. 8.17 with x = 0) as follows,

x2 = x0 + (0 − y0 ) g [ y0 , y1 ] = x0 − y0 g [ y0 , y1 ] (8.30)

Note that we can now compute y2 = f ( x2 ). Hence, we can now compute


next approximation which would be quadratic as follows,

x3 = x2 + (0 − y0 )(0 − y1 ) g[y0 , y1 , y2 ] = x2 + y0 y1 g[y0 , y1 , y2 ]

CHAPTER 8. INTERPOLATION
Scientific Computing 52

and then continue to find y3 as,

y3 = f ( x3 ) =⇒ x3 = g(y3 )

Again, we can compute the next term in Newton’s Interpolation as fol-


lows,

x4 = x3 − y0 y1 y2 g[y0 , y1 , y2 , y3 ] , y4 = f ( x4 ) =⇒ x4 = g(y4 )

and so on, we can continue in this way to generate new points for inter-
polation for inverse function g. Note that in all above iterations, we were
keeping y = 0 as we need to find the value of interpolated polynomial at
0 only, we don’t care about other values.

In general xk → ξ with k → ∞.

8.7 Hermite Interpolation


Definition : Given n + 1 distinct points (nodes) x0 , x1 , . . . , xn and the val-
ues f ( xi ) = yi and f 0 ( xi ) = yi0 for i = 0, 1, . . . , n. Our Objective is to look
for a polynomial H ( x ) of degree at most 2n + 1 such that,

H ( xi ) = f ( xi ) = yi
and (8.31)
0 0
H ( xi ) = f ( xi ) = yi0

for all i = 0, 1, . . . , n. Therefore, we want to fit a polynomial of degree


atmost 2n + 1 by using the above 2n + 2 conditions by also exploiting the
conditions given on the derivatives of the function at the given points too.

In analogy with Lagrange’s Formula Eq. 8.3, we write


n n
H (x) = ∑ yi hi (x) + ∑ yi0 h̃i (x)
i =0 i =0

where hi ( x ) and h̃i ( x ) are polynomials of degree ≤ 2n + 1 and satisfies


the following properties,

hi0 ( x j ) = h̃i ( x j ) = 0 , i, j = 0, 1, . . . , n
(
0 i 6= j (8.32)
hi ( x j ) = h̃i0 ( x j ) =
1 i=j

CHAPTER 8. INTERPOLATION
53 Scientific Computing

Eq. 8.32 is needed for maintaining same functional and derivative values
at all given points. We can verify it also that,

H(xj ) = yj
H 0 ( x j ) = y0j

However, we still need to construct hi ( x ) and h̃i ( x ). For that, recall the
basis for Lagrange Interpolating polynomial as given in Eq. 8.1 (repeated
below for convenience),

x − xj
Li ( x ) = ∏ xi − x j i = 0, 1, . . . , n
j 6 =i

Now simply define,

hi ( x ) = 1 − 2Li0 ( xi )( x − xi ) ( Li ( x ))2 , 0 ≤ i ≤ n
 
(8.33)

h̃i ( x ) = ( x − xi ) ( Li ( x ))2 (8.34)

It can be seen that hi ( x ) and h̃( x ) in Eq. 8.33 & 8.34 obey the constraints of
Eq. 8.32. Hence, they are valid candidates for Hermite polynomials!

Therefore, the Hermite Polynomial in Lagrangian Form is,

n n
H (x) = ∑ yi hi (x) + ∑ yi0 h̃i (x) (8.35)
i =0 i =0

8.7.1 Example with n=1


Let us take an example where we take n = 1 and construct the Hermite
Interpolating polynomial in Lagrangian form with these two data points.

Therefore we have that,

f ( x0 ) = y0
f ( x1 ) = y1
f 0 ( x0 ) = y00
f 0 ( x1 ) = y10

CHAPTER 8. INTERPOLATION
Scientific Computing 54

Thus, we construct h0 , h1 , h̃0 & h̃1 as,

h0 ( x ) = [1 − 2L00 ( x0 )( x − x0 )]( L0 ( x ))2


h1 ( x ) = [1 − 2L10 ( x1 )( x − x1 )]( L1 ( x ))2
h̃0 ( x ) = ( x − x0 )( L0 ( x ))2
h̃1 ( x ) = ( x − x1 )( L1 ( x ))2

where,
x − x1
L0 ( x ) =
x0 − x1
x − x0
L1 ( x ) =
x1 − x0
1
L00 ( x ) =
x0 − x1
1
L10 ( x ) =
x1 − x0

8.7.2 Uniqueness of Hermite Interpolating Polynomial


To show the uniqueness, consider another Hermite interpolating polyno-
mial G ( x ) with degree ≤ 2n + 1 with G ( xi ) = yi and G 0 ( xi ) = yi0 for all
i = 0, 1, 2, . . . , n.

Now, simply construct,

R( x ) = G ( x ) − H ( x )

Clearly, R( xi ) = R0 ( xi ) = 0 ∀ i = 0, 1, . . . , n.

For points other than xi , note that R( x ) has n + 1 double roots at x =


x0 , x1 , . . . , xn . Therefore, we can write it as,

R( x ) = q( x )( x − x0 )2 ( x − x1 )2 . . . ( x − xn )2

for q( x ) 6= 0 is a polynomial.

Now, critically note that ( x − x0 )2 ( x − x1 )2 . . . ( x − xn )2 is of degree 2n + 2!!


Which is a contradiction as both G ( x ) and H ( x ) are of degree atmost
2n + 1.

Thus we are forced to conclude that R( x ) = 0. QED.

CHAPTER 8. INTERPOLATION
55 Scientific Computing

8.8 Hermite Interpolation based on Divided Dif-


ferences
Clearly, the divided differences form is much more accessible from com-
putablility standpoint as compared to Lagrangian form as discussed ear-
lier.

Consider that we are given functional values of f ( x ) at points z1 , z2 , . . . , z2n .


Writing this in Newton divided differences form yields us the following,

H ( x ) = f ( z1 ) + ( x − z1 ) f [ z1 , z2 ]
+ ( x − z1 )( x − z2 ) f [z1 , z2 , z3 ]
(8.36)
+...
+ ( x − z1 )( x − z2 ) . . . ( x − z2n−1 ) f [z1 , z2 , . . . , z2n ]
The error in the above approximation can be written as the following with
the help of Theorem 8.8 and a new interpolating point x 6= zi for all i,

f ( x ) − H ( x ) = ( x − z1 )( x − z2 ) . . . ( x − z2n ) f [z1 , . . . , z2n , x ] (8.37)

Now, let’s relax the condition of disjoint points z1 , . . . , z2n , in particular,


we set,
z1 , z2 → x1 , z3 , z4 → x2 , . . . , z2n−1 , z2n → xn
which enables us to write,
H ( x ) = f ( x1 ) + ( x − x1 ) f [ x1 , x1 ]
+ ( x − x1 )2 f [ x1 , x1 , x2 ]
+...
+ ( x − x 1 )2 . . . ( x − x n −1 )2 ( x − x n ) f [ x 1 , x 1 , . . . , x n , x n ]
(8.38)

Now, from the above equation we see that the H ( x ) is a polynomial of de-
gree ≤ 2n − 1.

Let’s see how the error term f ( x ) − H ( x ) has changed,

f ( x ) − H ( x ) = ( x − x 1 )2 . . . ( x − x n −1 )2 ( x − x n )2 f [ x 1 , x 1 , . . . , x n , x n , x ]

To check whether the interpolation condition is satisfied or not,

f ( xi ) − H ( xi ) = 0 for all i = 1, 2, . . . , n

CHAPTER 8. INTERPOLATION
Scientific Computing 56

Hence we are good so far!

Now, for the derivative condition of Hermite Interpolation, we see that,

d
f 0 ( x ) − H 0 ( x ) = ( x − x 1 )2 . . . ( x − x n −1 )2 ( x − x n )2 f [ x 1 , x 1 , . . . , x n , x n , x ]
( dx )
n
+ 2 f [ x1 , x1 , . . . , x n , x n , x ] ∑ ( x − x i ) ∏ ( x − x j )2
i =1 j 6 =i
(8.39)

and thus it’s easy to see that,

f 0 ( xi ) − H 0 ( xi ) = 0 for all i = 1, 2, . . . , n

? So it satisfies all the criterion for the Definition of Hermite Polynomial


in Eq. 8.31, and by the uniqueness of Hermite Interpolating Polynomial,
we conclude that H ( x ) is unique.

Hence, the desired Hermite Interpolating Polynomial for functional and


derivative data given for n points for a function f based on divided dif-
ferences is given by

H ( x ) = f ( x1 ) + ( x − x1 ) f [ x1 , x1 ]
+ ( x − x1 )2 f [ x1 , x1 , x2 ]
+...
+ ( x − x 1 )2 . . . ( x − x n −1 )2 ( x − x n ) f [ x 1 , x 1 , . . . , x n , x n ]
(8.40)

and the associated Error Formula is,


n
f (x) − H (x) = ∏ ( x − x j )2 f [ x1 , x1 , . . . , x n , x n , x ] (8.41)
j =1

? Note that for finding f [ x1 , x1 ], we will use Eq. 8.27.

Refer to the slides for a nice and simple example.

CHAPTER 8. INTERPOLATION
57 Scientific Computing

8.9 Spline Interpolation


The word Spline appears from an instrument with which craftsmen used
to draw smooth curves.

Spline Interpolation can be explained as a piecewise interpolation tech-


nique.

Definition : A spline is a function defined on a sequence of intervals by a


corresponding sequence of polynomials. At the points where the intervals
touch, the function and some of it’s derivatives are required to be contin-
uous.

Definition : (Linear Spline) Given a set of (n + 1) data points

( x0 , y0 ), ( x1 , y1 ), . . . , ( x n , y n )

with x0 < x1 · · · < xn . These points xi ’s are called knots and yi ’s are called
ordinates. These may be values of a function f at the points xi , i.e. f ( xi ) = yi .
A function S( x ) that satisfies the following conditions:
1. S( x ) is a linear function in the intervals [ xi , xi+1 ].

2. S( x ) is continuous in [ x0 , xn ].

3. S( xi ) = yi for i = 0, 1, . . . , n.
is called Linear Interpolating Spline.

A very natural question to ask now is that whether such a function even exists
or not?

To see that it exists, consider Si ( x ) as


u i +1 − y i
Si ( x ) = y i + ( x − xi )
x i +1 − x i
Now to check whether it follows the three conditions for a linear spline,
first note that Si ( x ) is clearly linear for some i. Defining S( x ) as

S( x ) = Si ( x ) for x ∈ [ xi , xi+1 ]

then S( x ) is piece-wise linear function which is continuous in the whole


interval while satisfying the interpolating condition, i.e. S( xi ) = yi .

CHAPTER 8. INTERPOLATION
Scientific Computing 58

Therefore such functions exists!

However, more useful method of Spline Interpolation can be achieved by


fitting higher order polynomials in between the points, which is what we
consider now.

8.9.1 Cubic Spline Interpolation


Definition : (Cubic Spline) A function S( x ) is a cubic spline if

1. S( x ) is a polynomial of degree ≤ 3 on each [ xi , xi+1 ].

2. S0 , S00 ∈ C ([ x0 , xn ])

3. S( xi ) = yi for all i = 0, 1, . . . , n

4. First and Second derivative has to be continuous on each interval boundary.

Now suppose we are given n + 1 points ( x0 , y0 ), . . . , ( xn , yn ) as usual.


Let Si be the cubic polynomial on [ xi , xi+1 ] representing S( x ). Then (note
the closed intervals!),


 S0 ( x ) x ∈ [ x0 , x1 ]

S ( x ) x ∈ [ x1 , x2 ]

1
S( x ) = . ..

 .. .


S ( x )
n −1 x ∈ [ x n −1 , x n ]

additionally with

Si−1 ( xi ) = yi = Si ( xi ) for i = 1, . . . , n − 1

and combined with the assumed continuity of S0 and S00 , we also get the
following conditions,

Si0−1 ( xi ) = Si0 ( xi )
Si00−1 ( xi ) = Si00 ( xi )

for i = 1, . . . , n − 1.

CHAPTER 8. INTERPOLATION
59 Scientific Computing

Can we find such a function?


One interesting question at this point can be to ask if we can even form
such a function S( x ) with the conditions given so-far.

First, it’s easy to see that we need 4n conditions to make S( x ) (the coef-
ficients of third degree polynomial on each interval). However, a quick
observation tells us that we have total 2n (Boundary values of each sub-
interval) +(n − 1) (Boundary values for continuity of Si0 ) +(n − 1) (Bound-
ary values for continuity of Si00 ).

So in total, we have 4n − 2 total conditions, which is 2 short than the


required 4n conditions!! Thus we still need 2 more conditions to make
this endeavour possible. We will see these two conditions as we will try to
derive the cubic spline in the next section.

8.9.2 Derivation of Cubic Spline


Let us proceed to derive equation for Si ( x ) on [ xi , xi+1 ] for 0 ≤ i ≤ n − 1.
For this, let us define,

mi = S00 ( xi ) for all 0 ≤ i ≤ n

Clearly, mi also satisfies (the continuity of S00 ),

lim S00 ( x ) = mi = lim S00 ( x ) for all 1 ≤ i ≤ n − 1


x → xi− x → xi+

Also since Si is an atmost cubic polynomial on [ xi , xi+1 ], it directly implies


that Si00 is atmost linear and satisfies,

Si00 ( xi ) = mi and Si00 ( xi+1 ) = mi+1 for all 1 ≤ i ≤ n − 1

Thus, Si00 , which is linear, is given by (Lagrange’s Interpolation Eq 8.1,8.4


on the interval [ xi , xi+1 ]),
x i +1 − x x − xi
Si00 ( x ) = mi + m i +1
x i +1 − x i x i +1 − x i
mi m i +1 (8.42)
= (x − x) + ( x − xi )
h i i +1 hi

where hi = xi+1 − xi . Note the reversed order of subtraction in two terms.

CHAPTER 8. INTERPOLATION
Scientific Computing 60

Eq. 8.42 has given the Si00 for each interval [ xi , xi+1 ]. Since Si00 is linear,
to get S( x ), we can simply integrate Eq. 8.42 twice, the results of which
are,
mi m
Si ( x ) = ( x i +1 − x )3 + i +1 ( x − x i )3 + C ( x − x i ) + D ( x i +1 − x )
6hi 6hi
(8.43)

where C & D are constants of integration.

The conditions Si ( xi ) = yi and Si ( xi+1 ) = yi+1 (Interpolating Conditions)


can be used to solve for C and D, the final results are thus,

mi m
Si ( x ) = ( x i +1 − x )3 + i +1 ( x − x i )3 (8.44)
6h 6h
 i  i  
y i +1 m i +1 h i yi mi hi
+ − ( x − xi ) + − ( x i +1 − x )
hi 6 hi 6

Now, we will use the final condition, the Continuity of S0 . First of all,
the Si0 is,
   
m m y i +1 m i +1 h i yi mi hi
Si0 ( x ) = − i ( x i +1 − x )2 + i +1 ( x − x i )2 + − − −
2hi 2hi hi 6 hi 6
(8.45)

Now, since,

Si0−1 ( xi ) = Si0 ( xi ) for all i = 1, 2, . . . , n − 1

Therefore,

m i h i h i m i +1 y i y i +1
Si0 ( xi ) = − − − +
3 6 hi hi
(8.46)
h m h m y y
Si0−1 ( xi ) = i−1 i−1 + i−1 i − i−1 + i
6 3 h i −1 h i −1

Equating them, we get,

6 6
h i −1 m i −1 + 2 ( h i + h i −1 ) m i + h i m i +1 = ( y i +1 − y i ) − ( y − y i −1 )
hi h i −1 i
(8.47)

CHAPTER 8. INTERPOLATION
61 Scientific Computing

The Eq. 8.47 leads to n − 1 linear equations with n + 1 unknown in m0 , m1 , . . . , mn .


If we select m0 and mn arbitrarily, we can solve it for n − 1 variables
m 1 , . . . , m n −1 .

Doing the above calculation for m0 = S000 ( x0 ) = mn = Sn00 ( xn ) = 0 leads us


to the definition of Natural Cubic Spline.

Natural Cubic Spline in Matrix Form


With m0 = mn = 0, the resulting linear system can be represented as the
following matrix equation,
    
u1 h1 m1 v1
 h1 u2 h2   m2   v2 
    
 h 2 u 3 h 3
  m3   v3 
  ..  =  ..  with m0 = mn = 0
    

 ... ... ...  .   . 
    
 h n −3 u n −2 h n −2   m n −2   v n −2 
h n −2 u n −1 m n −1 v n −1
(8.48)
where,
h i = x i +1 − x i
u i = 2 ( h i + h i −1 )
6 (8.49)
bi = ( y i + 1 − y i )
hi
v i = bi − bi − 1
for 1 ≤ i ≤ n − 1. Hence, we obtain a tridiagonal and diagonally domi-
nant system, which can be solved by Gaussian Elimination for m1 , . . . , mn−1 .

? Now after finding m1 , m2 , . . . , mn , we can simply put those values in


Eq. 8.44 to get the Natural Cubic Spline Interpolating Function.

8.10 Minimizing Property of Cubic Splines


We saw the constraints under which Cubic Splines are defined in as dis-
cussed in Section 8.9.1. Now with this first remember that the curvature of
a curve y = f ( x ) is given by,
00 h i− 3
f ( x ) 1 + ( f ( x ))2 2

CHAPTER 8. INTERPOLATION
Scientific Computing 62

However, if we drop the nonlinear ( f ( x ))2 term, we would still get a


good enough approximation to the curvature as

00
f ( x ) ≈ curvature

And as we saw from previous section, in natural cubic spline interpolation


we are finding the curve with minimal (approximate) curvature over an
interval, i.e.
Z b 2
f 00 ( x ) dx
a

is being minimized, as visible by the process from Eq. 8.42 to 8.43.

Now, we formalize the above discussion in the following important theo-


rem in Functional Analysis:

Theorem 8.11 : (Minimal Curvature of Natural Cubic Spline) Let f ∈ C2 ([ a, b])


and let a = x0 < x1 < · · · < xn−1 < xn = b. If S is the natural cubic spline
interpolating f at xi , i.e. S( xi ) = f ( xi ) for i = 0, 1, . . . , n, then

Z b 2 Z b 2
00
S (x) dx ≤ f 00 ( x ) dx
a a

Proof : Take h( x ) = f ( x ) − S( x ). Clearly, h( xi ) = 0 for all i = 0, 1, . . . , n.


Now, note the following

Z b 2 Z b 2 Z b 2 Z b
00 00 00
f ( x ) dx = S ( x ) dx + h ( x ) dx + 2 S00 ( x )h00 ( x )dx
a
|a {z } |a {z } | a
{z }
≥0 ≥0 ?

The last term can be seen to be the deciding factor, in the sense that if it is
greater than zero than we are done, however if it is less than zero, that can
become problematic.

However, as we will show now, this third term is indeed equal to zero.

CHAPTER 8. INTERPOLATION
63 Scientific Computing

By using Integration by Parts, we get,


Z b n Z xi

a
00 00
S ( x )h ( x )dx = ∑ S00 h00 dx
i =1 x i −1
 
n Z xi
= ∑ |(S00 h0 )(xi ) −{z(S00 h0 )(xi−1}) − S000 h0 dx 
 
i =1 x i −1
=0, Continuity constraints
n Z xi
=−∑ S000 h0 dx
i =1 xi−1 const.
|{z}
n
= − ∑ ci (h( xi ) − h( xi−1 )) = 0
i =1
(8.50)

QED.

CHAPTER 8. INTERPOLATION
Scientific Computing 64

CHAPTER 8. INTERPOLATION
Chapter 9

Numerical Differentiation

We know that from past experience that differentiating a function is easier


than integrating the function. However, to approximate the derivative is a
much harder task then integrating the same function numerically!

Let us pose the question of numerical differentiate first in a concrete man-


ner.

Definition : (Numerical Differentiation & Integration Problem) Suppose we are


giventhe values of a function f ( x ) at a few points, say x0 , x1 , . . . , xn , can that
information be used to estimate
Z b
0
f (c) (a derivative) or f ( x )dx (an integral)
a

The answer to this problem is yes, we can using the interpolating poly-
nomial which we just discussed!

Thus, in numerical differentiation and integration, we approximate the


number
L( f ( x )) ≈ L( p( x ))
where, L is a linear operator and L( f ) denotes one of these operations
(derivatice of integral),
Z b
0
L( f ) = f ( x ) or L( f ) = f ( x )dx
a

and the p( x ) is the polynomial approximating to f ( x ).

65
Scientific Computing 66

9.1 Differentiation via Polynomial Interpolation


We now discuss the process of differentiation through polynomial inter-
polation.

Let f ( x ) ∈ C k+2 [c, d]. If x0 , x1 , . . . , xk are distinct points in [c, d], we can
write using the Newton’s Interpolating polynomial the f ( x ) as,

f ( x ) = pk ( x ) + f [ x0 , x1 , . . . , xk , x ]ψk ( x ) (9.1)

where pk ( x ) is a polynomial of degree ≤ k which satisfies the interpola-


tion conditions
pk ( xi ) = f ( xi ) i = 0, 1, . . . , k
with ψk being,
k
ψk ( x ) = ∏( x − x j )
j =0

(see Eq. 8.17).

Now, since we can write the derivative of the divided difference as the
following (refer Sec. 8.5.1, 1st point),
d
f [ x0 , x1 , . . . , xk , x ] = f [ x0 , x1 , . . . , xk , x, x ]
dx
With the help of above, we can differentiate Eq. 9.1 to get the following,

f 0 ( x ) = p0k ( x ) + f [ x0 , x1 , . . . , xk , x, x ]ψk ( x ) + f [ x0 , x1 , . . . , xk , x ]ψk0 ( x ) (9.2)

Now, let us define the derivative as the operator D to allow us to write


D ( f ) = f 0 ( a) for any a ∈ [c, d].

Now, if D ( f ) ≈ D ( pk ), then we can write the error E( f ) as,

E( f ) = D ( f ) − D ( pk )
= f [ x0 , x1 , . . . , xk , a, a]ψk ( a) + f [ x0 , x1 , . . . , xk , a]ψk0 ( a)
(9.3)
f (k+2) (ξ )ψk ( a) f ( k +1) ( η ) ψ 0 ( a )
= + (Theorem 8.9)
( k + 2) ! ( k + 1) !

where ξ, η ∈ [c, d].

CHAPTER 9. NUMERICAL DIFFERENTIATION


67 Scientific Computing

9.1.1 Simplification of Error Eq. 9.3


To simplify the error expression 9.3, we analyze it under the following
cases.

• CASE I : When a = xi for some i.

In such a case, we see that ψk ( a) would be zero (Eq. 8.17) as it con-


tains ( x − xi ) as a factor. Thus,

ψk ( a) = 0

Coming to ψ0 ( x ), we can easily see that,

ψk0 ( a) = ( a − x0 )( a − x1 ) . . . ( a − xi−1 )( a − xi+1 ) . . . ( a − xk )

Hence, if we choose a = xi , then we would get the error E( f ) simply


as the following

k
f ( k +1) ( η )
E( f ) =
( k + 1) ! ∏ ( xi − x j ) for η ∈ [c, d] (9.4)
j=0,j6=i

• CASE II : When a is such that ψk0 ( a) = 0.

We first discuss how this case can arise, i.e. for which a is ψk0 ( a) = 0.

If it so happens that k is odd, then we can choose a to be the mid-


point of the whole interval of interpolating points, i.e.

k−1
xk− j − a = a − x j , j = 0, . . . ,
2
Then, we have that,

( x − x j )( x − xk− j ) = ( x − a + a − x j )( x − a + a − xk− j )
k−1
= ( x − a)2 − ( a − x j )2 , j = 0, . . . ,
2
Hence, we get the ψk ( x ) as,
k −1
2 h i
ψk ( x ) = ∏ ( x − a )2 − ( a − x j )2
j =0

CHAPTER 9. NUMERICAL DIFFERENTIATION


Scientific Computing 68

Now since,
d h i
( x − a )2 − ( a − x j )2 = 2( x − a)| x=a = 0 ∀ j

dx x=a

Thus, it follows easily the required condition which we were trying


to prove for a particular choice of a,
ψk0 ( a) = 0
And it’s not difficult to see that the error term thus becomes,
k −1
f ( k +2) ( ξ ) 2 h i
( k + 2) ! ∏
2
E( f ) = −( a − x j ) for some ξ ∈ (c, d) (9.5)
j =0

Also note that in this case the derivative is one orde higher than that
in Eq. 9.4.
We now demonstrate few examples which portray the usage of above
cases in determining the derivatives at the given points.

Exampe 1 : For k = 1,
p1 ( x ) = f ( x0 ) + f [ x0 , x1 ]( x − x0 )
Thus,
D ( p1 ) = f [ x0 , x1 ]
regardless of a. If we set a = x0 , we thus arrive at CASE I.

Even more, if we set h = x1 − x0 then we obtain the following forward


difference formula
f ( a + h) − f ( a)
f 0 ( a) ≈ f [ a, a + h] =
h
and then the error is simply given by Eq. 9.4 as,
1
E( f ) = − h f 00 (η )
2
However, if we choose a symmetrically around x1 and x0 , i.e. a = 21 ( x1 −
x0 ), we get the CASE II. With x0 = a − h and x1 = a + h and h = 12 ( x1 −
x0 ), we obtain the central-difference formula,
f ( a + h) − f ( a − h)
f 0 ( a) ≈ f [ a − h, a + h] =
2h

CHAPTER 9. NUMERICAL DIFFERENTIATION


69 Scientific Computing

and the associated error through the Eq. 9.5 is,

h2 000
E( f ) = − f (η )
6

Example 2 : For k = 2 (three interpolation points), we would have,

pk ( x ) = f ( x0 ) + f [ x0 , x1 ]( x − x0 ) + f [ x0 , x1 , x2 ]( x − x0 )( x − x1 )

whose derivative would be,

p0k ( x ) = f [ x0 , x1 ] + f [ x0 , x1 , x2 ](2x − x0 − x1 )

Again, at x0 = a (CASE I), we would get the derivative f 0 ( a) as (Eq. 9.4


and D ( f ) = D ( pk ) + E( f )),

1
f 0 ( a) = f [ a, x1 ] + f [ a, x1 , x2 ]( a − x1 ) + ( a − x1 )( a − x2 ) f 000 (η )
|6 {z }
E( f )

In a more representable way, we can write x1 = a + h and x2 = a + 2h to


obtain (after opening all the finite differences),

−3 f ( a) + 4 f ( a + h) − f ( a + 2h)
f 0 ( a) ≈
2h
and the error as (Eq. 9.4),

h2 000
E( f ) = f (ξ ) , for some ξ ∈ ( a, a, +2h)
3
On the other hand, if we choose x1 = a − h and x2 = a + h (This is NOT
the CASE II, we just assume a different distribution of points), then,

f ( a + h) − f ( a − h)
f 0 ( a) ≈
2h
and the error becomes,

h2 000
E( f ) = − f (ξ ) with |ξ − a| < |h|
6

CHAPTER 9. NUMERICAL DIFFERENTIATION


Scientific Computing 70

9.1.2 Discretization
Observe in above examples that the formulas for the derivative of f were
always of the form,

D ( f ) = D ( pk ) + Chr f (r+1) (ξ ) (9.6)

with D ( f ) = f 0 ( a) and h is the spacing of the points used for interpolation.

Definition : (Discretization) The process of replacing D ( f ) by D ( pk ) is known


as discretization and the error term Chr f (r+1) (ξ ) is called the discretization
error.

Derivative on a computer

Theorem 9.12 : For a computer with fixed word length and for a given function
f , there is an optimum value of h below which the approximation of the derivative
with the derivative of pk will become worse. The optimum value of h is that value
for which the sum of the magnitudes of the round-off error and the discretization
error is minimized.

More concretely, consider the formula as discussed in example 2 above,

f ( a + h) − f ( a − h) h2 000
f 0 ( a) = − f (ξ )
2h 6
In a computer, during calculation, to model the roundoff, we use,

f ( a + h) + R+ instead of f ( a + h)
(9.7)
f ( a − h) + R− instead of f ( a − h)

Therefore,

0 f ( a + h) + R+ − f ( a − h) − R−
f comp =
2h (9.8)
f ( a + h) − f ( a − h) R+ − R−
= +
2h 2h
Hence,
R+ − R− h2 000
f 0 ( a) = f comp
0
− − f (ξ ) (9.9)
2h
| {z } 6
| {z }
Round-Off Error Discretization Error

CHAPTER 9. NUMERICAL DIFFERENTIATION


71 Scientific Computing

? Hence if we want to find optimum h, just simply find the value of h


which minimizes the |Round-Off Error| + |Discretization Error|.

Now, if f 000 ( x ) is bounded then the discretization error goes to zero as


h → 0, but the round-off grows if we assume that R+ − R− does not de-
crease.

CHAPTER 9. NUMERICAL DIFFERENTIATION


Scientific Computing 72

9.2 Approximation of Derivatives via Taylor’s The-


orem
In this section we will focus on approximating the derivatives for a given
function by the use of the Taylor’s theorem.

0 h2 00
f ( x + h) = f ( x ) + h f ( x ) + f (ξ )
2
where ξ ∈ ( x, x + h) and f 00 ∈ C2 [( x, x + h)]. We can rewrite the above
equation as the following,

f ( x + h) − f ( x ) h 00
f 0 (x) = − f (ξ )
h 2
Now note that the first term in the above equation is just the forward-
difference equation (Example 1)! Thus if we neglect the higher order
term, thus we get an approximation of f 0 as,

f ( x + h) − f ( x )
f 0 (x) ≈ (9.10)
h
? The neglected higher order term − 2h f 00 (ξ ) is called the Truncation Er-
ror (T.E.).

We can use the Taylor’s theorem on f ( x − h) as the following,

h2 00
f ( x − h) = f ( x ) − h f 0 ( x ) + f (ξ )
2
Thus, we get the following formula for approximating f ( x ),

f ( x ) − f ( x − h)
f 0 (x) ≈ (9.11)
h
which is called backward-difference formula.

Similarly, we can approximate to higher-order derivatives through the


Taylor’s Theorem as follows,

h2 00 h3 000
f ( x + h) = f ( x ) + h f 0 ( x ) + f (x) + f (ξ 1 )
2 6 (9.12)
h2 h3 000
f ( x − h) = f ( x ) − h f 0 ( x ) + f 00 ( x ) − f (ξ 2 )
2 6

CHAPTER 9. NUMERICAL DIFFERENTIATION


73 Scientific Computing

where ξ 1 ∈ ( x, x + h) and ξ 2 ∈ ( x − h, x ). If we subtract the above two


equations, we get,

f ( x + h) − f ( x − h) h2 000
f 0 (x) = − [ f (ξ 1 ) + f 000 (ξ 2 )] (9.13)
2h 12
Assuming f 000 ∈ C ([ x − h, x + h]), there exists some point ξ ∈ [ x − h, x + h]
such that,
1
f 000 (ξ ) = [ f 000 (ξ 1 ) + f 000 (ξ 2 )]
2
000
With the above f (ξ ), we can write Eq. 9.13 as,

f ( x + h) − f ( x − h) h2 000
f 0 (x) = − f (ξ ) (9.14)
2h 6
Thus, if we neglect the higher-order term, then,

f ( x + h) − f ( x − h)
f 0 (x) ≈ (9.15)
2h
which is the central-difference formula as in Example 1.

Note that in this case, the Truncation Error is O(h2 )

It should be clear now that we can extend the above calculation to even
more higher order derivatives. For example, if we extend the taylor’s the-
orem to fourth order derivatives,

h2 00 h3 000 h 4 (4)
f ( x + h) = f ( x ) + h f 0 ( x ) + f (x) + f (x) + f (ξ 1 )
2 6 24 (9.16)
h2 h3 000 h 4 (4)
f ( x − h) = f ( x ) − h f 0 ( x ) + f 00 ( x ) − f (x) + f (ξ 2 )
2 6 24
Again, adding the above two equations leads us to,

f ( x + h ) − 2 f ( x ) + f ( x − h ) h 2 (4)
f 00 ( x ) ≈ − f (ξ ) (9.17)
h2 24
for some ξ ∈ ( x − h, x + h). Then again, the approximate formula of f 00 ( x )
is,
f ( x + h) − 2 f ( x ) + f ( x − h)
f 00 ( x ) ≈ (9.18)
h2
and the Truncation Error is O(h2 ).

CHAPTER 9. NUMERICAL DIFFERENTIATION


Scientific Computing 74

CHAPTER 9. NUMERICAL DIFFERENTIATION


Chapter 10

Numerical Integration

Seeing the difficulty of approximating the derivatives of a function, we


now turn our attention to approximating the integral of a function. As we
will see, the task of finding the integral is in general, easier than that of it’s
counterpart.

In particular, we wish to find the value of,


Z b
f ( x )dx.
a

This can be alternatively stated as the task of finding a function F ( x ) such that
F 0 ( x ) = f ( x ). Then, we would have,
Z b
f ( x )dx = F (b) − F ( a)
a

Note that there are a lots of functions whose anti-derivative are very diffi-
cult to compute, for example the following,
Z 2 Z 1 Z π
− x2 x
e dx , sin( xe )dx , cos(3 cos θ )dθ
0 0 0

are not amenable to the techniques learned in elementary calculus.

A very basic question that may arise in the reader’s mind is that if we
are given values of a function f ( x ) at a few points, say x0 , x1 , . . . , xk , then
can that information be used to estimate
Z b
f ( x )dx an integral ?
a

75
Scientific Computing 76

Surprisingly, the answer is yes! It comes from the same idea that we used
in numerical differentiation, of that of approximating the function f by
pk , i.e.
Z b
I ( f ) ≈ I ( pk ) = pk ( x )dx (10.1)
a
where pk ( x ) is the polynomial of degree ≤ k with

pk ( xi ) = f ( xi ) , i = 0, . . . , k (10.2)

The error in the approximation is then given by,

E( f ) = I ( f ) − I ( pk )

This approximation is usually written as a weighted sum as follows,

I ( p k ) = A0 f ( x0 ) + A1 f ( x1 ) + · · · + A k f ( x k ) (10.3)

where Ai are the weights and f ( xi )’s are the functional values.

By Newton’s Divided Differences, we can write the interpolation poly-


nomial using Theorem 8.8 as follows,

f ( x ) = pk ( x ) + f [ x0 , . . . , xk , x ]ψk ( x )
| {z }
Error Term

where we know that,

pk ( x ) = f ( x0 ) + f [ x0 , x1 ]( x − x0 ) + f [ x0 , x1 , x2 ]( x − x0 )( x − x1 ) + . . .
+ f [ x0 , x1 , . . . , xk ]( x − x0 )( x − x1 ) . . . ( x − xk−1 )
k
ψk ( x ) = ∏( x − x j )
j =0

10.1 Many rules of choosing the interpolating points


We now discuss the various ways one can choose the interpolating points
and thus, the various ways we could thus find the integral.

10.1.1 Rectangle Rule


Let k = 0. Then,
f ( x ) ≈ p0 ( x ) = f ( x0 )

CHAPTER 10. NUMERICAL INTEGRATION


77 Scientific Computing

Hence, the approximate integral would be,


Z b
I ( pk ) = f ( x0 )dx = (b − a) f ( x0 )
a
If x0 = a, then this approximation becomes
I ( f ) ≈ R = (b − a) f ( a) (10.4)
which is called the Rectangle Rule.
f(x)

x=a x=b

Figure 10.1: Rectangle Rule

10.1.2 Mid-point Rule


a+b
If x0 = 2 ,
then the approximation would be,
 
a+b
I ( f ) ≈ M = (b − a) f (10.5)
2
is known as the mid-point rule.

10.1.3 Trapezoidal Rule


Let k = 1. Then
f ( x ) ≈ f ( x0 ) + f [ x0 , x1 ]( x − x0 )
Choosing x0 = a and x1 = b to have,
Z b
I ( p1 ) = ( f ( a) + f [ a, b]( x − a)) dx
a
or,
1
I( f ) ≈ T =(b − a)[ f ( a) + f (b)] (10.6)
2
which yields the trapezoidal rule.

CHAPTER 10. NUMERICAL INTEGRATION


Scientific Computing 78

f(x)

x=a x=(a+b)/2 x=b

Figure 10.2: Mid-Point Rule

P_1
f

a b

Figure 10.3: Trapezoidal Rule

10.1.4 Simpson’s Rule

Let k = 2. Then

f ( x ) ≈ p2 ( x )

a+b
If we choose x0 = a, x1 = 2 and x2 = b, then the interpolating polyno-
mial p2 ( x ) is in the form,

 
a+b
p2 ( x ) = f ( a) + f [ a, b]( x − a) + f a, b, ( x − a)( x − b)
2

CHAPTER 10. NUMERICAL INTEGRATION


79 Scientific Computing

P_2

a (a+b)/2 b

Figure 10.4: Simpson’s Rule

Then, the approximate integral would be,

( b − a )2
 Z b
a+b
I ( f ) ≈ I ( p2 ) = f ( a)(b − a) + f [ a, b] + f a, b, ( x − a)( x − b)dx
2 2 a
( b − a )2 a + b ( b − a )3
 
= f ( a)(b − a) + f [ a, b] + f a, b,
2 2 6
    
a+b
 f (b) − f ( a) f ( b ) − f 2 + f ( a ) 
= (b − a) f ( a) + −2
 2 6 

b−a
   
a+b
= f ( a) + 4 f + f (b)
6 2
(10.7)

Thus, the quadrature formula becomes,

b−a
   
a+b
I( f ) ≈ S = f ( a) + 4 f + f (b) (10.8)
6 2

which is called the Simpson’s Rule.

10.1.5 Corrected Trapezoidal Rule


Suppose we have k = 3. Then, as usual,

f ( x ) ≈ p3 ( x )

Choosing x0 = x1 = a and x2 = x3 = b, we notice that,

p3 ( x ) = f ( a) + f [ a, a]( x − a) + f [ a, a, b]( x − a)2 + f [ a, a, b, b]( x − a)2 ( x − b)

CHAPTER 10. NUMERICAL INTEGRATION


Scientific Computing 80

Now, integrating p3 ( x ) leads to the following approximation,


( b − a )2 0
Z b
b−a
I ( f ) ≈ I ( p3 ) = p3 ( x )dx = [ f ( a) + f (b)] + [ f ( a) − f 0 (b)]
a 2 12
(10.9)
which is known as corrected trapezoidal rule.
f
p_3

a b

Figure 10.5: Corrected Trapezoidal Rule

10.2 Error Analysis


So far, we’ve seen the various methods to approximate the integral of a
function f by approximating it via Newton’s Interpolating method. A
very obvious question that arises in mind after seeing all the methods is
the amount of error we are incurring in approximating the integral via
Newton’s interpolating polynomial. Note that if we are able to quantify
the error, then it would be much easier to judge which rule is most suit-
able for a given function f . Hence we now do exactly that, i.e. quantify
the error.

By Newton’s divided difference, we can write,


f ( x ) = pk ( x ) + f [ x0 , . . . , xk , x ]ψk ( x )
where ψk ( x ) = ∏kj=0 ( x − x j ). The error E( f ) is given by,
Z b
E( f ) = I ( f ) − I ( pk ) = f [ x0 , . . . , xk , x ]ψk ( x )dx
a
? If ψk ( x ) is only of one sign in interval [ a, b], then by Mean Value The-
orem
Z b Z b
f [ x0 , . . . , xk , x ]ψk ( x )dx = f [ x0 , . . . , xk , ξ ] ψk ( x )dx
a a

CHAPTER 10. NUMERICAL INTEGRATION


81 Scientific Computing

for some ξ ∈ ( a, b). If f ( x ) ∈ C k+1 ( a, b), then it follows that the error by
Theorem 8.9 is,
Z b
1
E( f ) = f ( k +1) ( η ) ψk ( x )dx for some η ∈ ( a, b) (10.10)
( k + 1) ! a

? Even if ψk ( x ) is not of one sign, certain simplifications in the error


E( f ) are possible. One particular desirable instance of this kind occurs
when, Z b
ψk ( x )dx = 0 (10.11)
a
For this case, we can use the identity,
f [ x0 , . . . , xk , x ] = f [ x0 , . . . , xk , xk+1 ] + f [ x0 , . . . , xk+1 , x ]( x − xk+1 ) (10.12)
which is true for arbitrary xk+1 . Then the error E( f ) becomes
Z b Z b
E( f ) = f [ x0 , . . . , xk+1 ]ψk ( x )dx + f [ x0 , . . . , xk+1 , x ]( x − xk+1 )dx
a a
Z b
= f [ x0 , . . . , xk+1 , x ]ψk+1 ( x )dx
a
(10.13)
where ψk+1 ( x )dx = ( x − xk+1 )ψk ( x ).

Now choose xk+1 in such a way that ψk+1 ( x ) = ( x − xk+1 )ψk ( x ) is of


one sign on ( a, b). Thus, if f ( x ) ∈ C k+2 ( a, b) then,
Z b
1
E( f ) = f ( k +2) ( η ) ψk+1 ( x )dx for some η ∈ ( a, b) (10.14)
( k + 2) ! a

10.2.1 Error in Rectangle Rule


In this case, we only have one point x0 = a, hence,
ψ0 ( x ) = ( x − a)
Thus, the error becomes,
Z b
ER = E ( f ) = f [ x0 , x ]( x − a)
a
? Now since ψ0 ( x ) is of one sign in ( a, b), hence we would use Eq. 10.10 to
get,
f 0 (η )(b − a)2
Z b
0
ER = f ( η ) ( x − a)dx = (10.15)
a 2

CHAPTER 10. NUMERICAL INTEGRATION


Scientific Computing 82

10.2.2 Error in Mid-Point Rule


In this case, we still have only one point, however, that point is the mid-
point of the interval ( a, b), thus x0 = a+2 b .

Note that in this case,


a+b
ψ0 ( x ) = ( x −
)
2
which is of NOT the same sign for x ∈ ( a, b). But note that,
Z b Z b 
a+b
ψ0 ( x )dx = x− dx = 0
a a 2
Thus we can now simply use the second method discussed above.

a+b
For that, if we introduce another point x1 = 2 , then
a+b 2
ψ1 ( x ) = ( x − x1 )ψ0 ( x ) = ( x − )
2
is of one sign. Thus, by Eq. 10.14, we get,

f 00 (η )(b − a)3
EM = for some η ∈ ( a, b) (10.16)
24

10.2.3 Error in Trapezoidal Rule


In this case, we have two points x0 = a and x1 = b. Therefore,
ψ1 ( x ) = ( x − a)( x − b)
As ψ1 ( x ) is of one sign on ( a, b), thus, we can simply use the Eq. 10.10 so
that the error in Trapezoidal Rule ET becomes,

f 00 (η ) f 00 (η )(b − a)3
Z b
ET = ( x − a)( x − b)dx = for some η ∈ ( a, b)
2 a 12
(10.17)

10.2.4 Error in Simpson’s Rule


In this case, we have 3 points as x0 = a, x1 = a+2 b and x2 = b. Thus, the
ψ2 ( x ) is,  
a+b
ψ2 ( x ) = ( x − a)( x − b) x −
2

CHAPTER 10. NUMERICAL INTEGRATION


83 Scientific Computing

Now note that in ( a, b), the sign of ψ2 ( x ) is NOT same. But still, note that,
Z b Z b  
a+b
ψ2 ( x )dx = ( x − a)( x − b) x − dx = 0
a a 2
Hence we can use the second method in this case! For that all, we need
to find is another point x3 such that ψ3 ( x ) should be of same sign in ( a, b).

For this, first see that


 
a+b
ψ4 ( x ) = ( x − a)( x − b)( x − x3 ) x −
2
and note that it can be of same sign on ( a, b) only when x3 = a+2 b . Thus,
the error for Simpson’s Rule can now can be written with the help of Eq.
10.14 as,
f (4) ( η ) b a+b 2
Z  
ES = ( x − a)( x − b) x − dx
24 a 2
f (4) ( η ) − 4 b − a 5
 
= × (10.18)
24 15 2
f (4) ( η ) b − a 5
 
=− , η ∈ ( a, b) .
90 2

10.2.5 Error in Corrected Trapezoidal Rule


We have three points here, x0 = x1 = a and x2 = x3 = b. Now note that,
ψ3 ( x ) = ( x − a)2 ( x − b)2
is of one sign on (a,b) and hence we can simply use Eq. 10.10 to get the
error ECT as,
f (4) ( η )
Z b
ECT = ( x − a)2 ( x − b)2 dx
4! a
(10.19)
f (4) (η )(b − a)5
= η ∈ ( a, b)
720

10.3 Composite Methods


Let’s take a look at Figure 10.1. The boxed one represents the area actual
Rb
approximation and the whole grey region is the actual value of a f ( x )dx.

CHAPTER 10. NUMERICAL INTEGRATION


Scientific Computing 84

We can clearly see intuitively that this would contain heavy amount of er-
ror. This was also confirmed by error analysis and Eq. 10.15. It grows
quadratically with the size of interval ( a, b).

One way to overcome this might be to use different length rectangles in


each subinterval after dividing the original interval. This would bring us
somewhat closer to the Darboux’s definition of Riemann integral. Thus,
our aim now is to find a scheme to fit the length of rectangle which we
should make dependent on the subinterval of ( a, b). This is called com-
posite rule where we use the previously discussed rules in the context of
each subinterval of ( a, b) instead of using it on whole of ( a, b) at once.

10.3.1 Composite Rectangle Rule


Divide [ a, b] into N subintervals to get,

a = x0 < x1 < x2 < · · · < x N = b


b− a
where xi = a + ih , i = 0, . . . , N with uniform step-size h = N .

Set,
f i = f ( xi ) = f ( a + ih) , i = 0, . . . , N
and,
h
f i − 1 = f ( x i − ).
2 2
Now, simply apply the Rectangular Rule on each subinterval to get,

f 0 (ηi )( xi − xi−1 )2
Z xi
f ( x )dx = ( xi − xi−1 ) f ( xi−1 ) +
x i −1 | 2
{z }
Error Term (Eq. 10.15)

f 0 (η i ) h2
= h f ( x i −1 ) +
2
Summing from i = 1 to i = N, we obtain,

N N
f 0 ( ηi ) h 2
Z b
I( f ) = f ( x )dx = h ∑ f i−1 + ∑ R
= R N + EN (10.20)
a i =1 i =1
2

where ηi ∈ ( xi−1 , xi ) and R N is called the Composite Rectangle Rule.

CHAPTER 10. NUMERICAL INTEGRATION


85 Scientific Computing

Note that if f 0 ( x ) is continuous, then we can write,


N
f 0 ( ηi ) h 2 N 2
h f 0 (η ) Nh2
∑ N
= f 0 (η ) ∑
2
=
2
i =1 i =1
with Nh = b − a, it becomes,
R f 0 (η )(b − a)h
EN = for some η ∈ ( a, b) (10.21)
2

10.3.2 Composite Mid-Point Rule


Continuing as in the previous subsection for the rectangle rule, we can do
the same now for the Mid-Point rule,
Z b N Z xi
I( f )
a
f ( x )dx = ∑ f ( x )dx
i =1 x i −1
N
≈ h ∑ f ( xi − 1 ) (10.22)
2
i =1
N
= h ∑ f i− 1
2
i =1

where the error can be similarly found to be,

M f 00 (ξ )(b − a)h2
EN = (10.23)
24

10.3.3 Composite Trapezoid Rule


Using Eq. 10.6,
Z b N Z xi
I( f ) =
a
f ( x )dx = ∑ f ( x )dx
i = 1 x i −1
N
h
2 i∑
≈ [ f ( xi−1 ) + f ( xi )] (10.24)
=1
" #
N −1
h
TN = f0 + 2 ∑ fi + f N
2 i =1

T follows from Eq. 10.17,


and the error EN

T f 00 (η )(b − a)h2
EN =− (10.25)
12

CHAPTER 10. NUMERICAL INTEGRATION


Scientific Computing 86

10.3.4 Composite Simpson’s Rule


As usual, letting a = xi−1 , b = xi and xi − xi−1 = h, apply Simpson’s Rule
over a single subinterval ( xi−1 , xi ) in conjunction with result in Eq. 10.7 to
obtain,
 5
Z xi
hh i f (ηi ) 2h
( 4 )
f ( x )dx = f + 4 f i− 1 + f i − , x i − 1 < ηi < x i
x i −1 6 i −1 2 90

Now simply summing over all subintervals i = 1, . . . , N to obtain,


 5
h
N Z xi
h N h i N f (4 ) ( ηi ) 2
I( f ) = ∑ f ( x )dx = ∑ f i−1 + 4 f i− 1 + f i − ∑
6 i =1 2 90
i =1 x i −1 i =1
= S N + ESN
(10.26)

The composite Simpson approximation S N can be simplified to have,


" #
N −1 N
h
SN =
6
f0 + f N + 2 ∑ f i + 4 ∑ f i− 1
2
(10.27)
i =1 i =1

with the error term ESN being,


 4
h
f (4) (ξ )(b − a) 2
ESN = a<ξ<b (10.28)
180

10.3.5 Composite Corrected Trapezoidal Rule


Following from Eq. 10.9,
N Z xi Z x1 Z xN
I( f ) = ∑ f ( x )dx = f ( x )dx + · · · + f ( x )dx
i = 1 x i −1 x0 x N −1

h h2 (10.29)
≈ [ f ( x0 ) + f ( x1 )] + [ f 0 ( x0 ) − f 0 ( x1 )]
2 12
h h2 0
+ · · · + [ f ( x N −1 ) + f ( x N )] + [ f ( x N −1 ) − f 0 ( x N )]
2 12
Now note that all the interior derivatives form a telescopic series, thus can-
celling each other except the first and the last terms. Thus, the Composite

CHAPTER 10. NUMERICAL INTEGRATION


87 Scientific Computing

Corrected Trapezoidal Rule is,


!
N −1
h h2 0
I ( f ) ≈ CTN =
2
f0 + f N + 2 ∑ fi +
12
[ f ( a) − f 0 (b)] (10.30)
i =1

and the error term ECT


N can be seen from Eq. 10.19 to be,

f (4) (η )(b − a)(h)4


ECT
N = ,a < η < b (10.31)
720

10.4 Gauss Quadrature Rule


Quadrature is a historic word which means the area under a curve, thus, an
integral. In fact, we have seen three quadrature rules already, where any
quadrature rule has the form,

I ( f ) ≈ A0 f ( x0 ) + A1 f ( x1 ) + · · · + A k f ( x k ) (10.32)

with nodes x0 , . . . , xk and weights A0 , . . . , Ak .

Note that this encompasses all the following rules,

I ( f ) ≈ (b − a) f ( x ) (Rectangle Rule)
(b − a)
I( f ) ≈ [ f ( a) + f (b)] (Trapezoidal Rule)
2
(b − a)
   
a+b
I( f ) ≈ f ( a) + 4 f + f (b) (Simpson’s Rule)
6 2

? Now note that there is no apparent freedom in choosing the nodes


x0 , x1 , . . . , xk . The difficulty with the Composite Rules is that the nodes
xi must be evenly spread.

Thus a natural question to ask is whether it is possible to make a rule


for polynomial of degree ≤ 2k + 1 by choosing the nodes appropriately?

To discuss the Gaussian Rules in the more general context, we write the
integral as
Z b Z b
f ( x )dx = w( x ) g( x )dx
a a

CHAPTER 10. NUMERICAL INTEGRATION


Scientific Computing 88

where the weight function w( x ) is assumed to be non-negative and inte-


grable on [ a, b] and,
f (x)
g( x ) =
w( x )
Consider approximating the weighted integral,
Z b
I ( g) = g( x )w( x )dx
a
≈ A0 g ( x0 ) + A1 g ( x1 ) + · · · + A k g ( x k )
k
= ∑ A j g(x j ) = Ik ( g)
j =0

We can clearly see in the above equations that the nodes x j and weights A j
are to be chosen so that Ik ( g) equals I ( g) exactly for polynomials g( x ) of as
higher degree as possible. This is indeed the basic idea behind the Gaussian
Rule.

R1
10.4.1 Special case when w( x ) = 1 and −1
g( x )dx ≈ ∑kj=0 A j g( x j )
In this case, we define the Error as,
Z 1 k
Ek ( g) = g( x )dx − ∑ A j g( x j ) (10.33)
−1 j =0

Now the task is to determine the weights A j and nodes x j to make the
error 0, i.e.
Ek ( g) = 0 (10.34)
for as high a degree polynomial g( x ) as possible.

Note that,

Ek ( a0 + a1 x + · · · + an x m ) = a0 Ek (1) + a1 Ek ( x ) + · · · + am Ek ( x m ) (10.35)

Also, note that,


Ek ( g) = 0 for every polynomial of degree ≤ m
(10.36)
⇐⇒ Ek ( xi ) = 0, i = 0, 1, 2, . . . , m.

Hence, to show that Ek ( g) = 0 is equivalent to showing that each Ek ( xi ) =


0 for all i = 0, 1, . . . , m. We now use exactly this equivalence.

CHAPTER 10. NUMERICAL INTEGRATION


89 Scientific Computing

For k = 0

We have,
Z 1
g( x )dx ≈ A0 g( x0 )
−1

Due to the conditions, we require Ek (1) = 0 and Ek ( x ) = 0.


Z 1
Ek (1) = 0 =⇒ dx − A0 =⇒ A0 = 2
−1
Z 1 (10.37)
Ek ( x ) = 0 =⇒ xdx − A0 x0 =⇒ x0 = 0
−1

Therefore, we would be lead to the following formula,

Z 1
g( x )dx ≈ 2g(0)
−1

which is the Mid-Point Rule!

For k = 1

We have,
Z 1
g( x )dx ≈ A0 g( x0 ) + A1 g( x1 )
−1

Note there are four unknown parameters to be determined.

Thus we require,
Z 1
Ek (1) = 0 =⇒ dx − A0 − A1 = 0 =⇒ A0 + A1 = 2
−1
Z 1
Ek ( x ) = 0 =⇒ xdx − ( A0 x0 + A1 x1 ) = 0 =⇒ A0 x0 + A1 x1 = 0
−1
Z 1
2
Ek ( x2 ) = 0 =⇒ x2 dx − ( A0 x02 + A1 x12 ) = 0 =⇒ A0 x02 + A1 x12 =
−1 3
Z 1
Ek ( x3 ) = 0 =⇒ x3 dx − ( A0 x03 + A1 x13 ) = 0 =⇒ A0 x03 + A1 x13 = 0
−1
(10.38)

CHAPTER 10. NUMERICAL INTEGRATION


Scientific Computing 90

On solving, we get,
A0 = 1
A1 = 1
1
x0 = √
3
1
x1 = − √
3
This leads to the formula,
Z 1    
1 1
g( x )dx ≈ g √ + g −√
−1 3 3

which has a degree of precision 3.

For a general k

There are 2k + 2 parameters, weights {wi }ik=0 and nodes { xi }ik=0 , to be de-
termined.

The equations to be solved are,

Ek ( xi ) = 0 , i = 0, 1, . . . , 2k + 1 (10.39)
This leads to the following set of equations:
(
k
0 i = 1, 3, . . . , 2k + 1.
∑ A j xij = 2
i = 0, 2, . . . , 2k.
(10.40)
j =0 i +1

However, note that the equations in Eq. 10.40 are non-linear equations and
their solvability is not at all obvious. For that, we may have the following
alternative

10.4.2 An Alternate Approach through Newton’s Interpo-


lation
First, choose x0 , . . . , xk in ( a, b) and write the Newton’s Interpolating Poly-
nomial (Theorem 8,8),
g( x ) = pk ( x ) + g[ x0 , x1 , . . . , xk , x ]ψk ( x )

CHAPTER 10. NUMERICAL INTEGRATION


91 Scientific Computing

where pk ( x ) is the polynomial of degree ≤ k which interpolates g( x ) at


x0 , . . . , xk with,
ψk ( x ) = ( x − x0 ) . . . ( x − xk )
This now leads to, after integrating both sides,
Z b
I ( g) = I ( pk ) + g[ x0 , . . . , xk , x ]ψk ( x )w( x )dx (10.41)
a
| {z }
Error Term

Now, if we write pk ( x ) in Lagrange form (Eq. 8.3) then,

p k ( x ) = g ( x0 ) L0 ( x ) + g ( x1 ) L1 ( x ) + · · · + g ( x k ) L k ( x )

with,
k (x − xj )
Li ( x ) = ∏ ( x i − x j )
, i = 0, . . . , k
j=0,i 6= j

Thus, expanding I ( pk ) in Eq. 10.41 now yields,


Z b
I ( pk ) = pk ( x )w( x )dx
a
Z b Z b
= g ( x0 ) L0 ( x )w( x )dx + · · · + g( xk ) Lk ( x )w( x )dx
a a

Hence we can write I ( pk ) simply as,

I ( p k ) = A0 g ( x0 ) + A1 g ( x1 ) + · · · + A k g ( x k ) (10.42)

where coefficients Ai are simply,


Z b
Ai = Li ( x )w( x )dx , i = 0, . . . , k (10.43)
a

Now, for the error term, using the property of orthogonal polynomials,
for many w( x ), we can find a polynomial Pk+1 ( x ) such that,
Z b
Pk+1 ( x )q( x )w( x )dx = 0 (10.44)
a

for all polynomial q( x ) of degree ≤ k. Moreover, since Pk+1 ( x ) is a poly-


nomial, thus,

Pk+1 ( x ) = αk+1 ( x − ξ 0 )( x − ξ 1 ) . . . ( x − ξ k )

CHAPTER 10. NUMERICAL INTEGRATION


Scientific Computing 92

where ξ 0 , . . . , ξ k are the k + 1 distinct points in the interval ( a, b) at which


Pk+1 vanishes.

Now, simply set,


x j = ξ j , j = 0, . . . , k (10.45)
to get
I ( f ) = I ( pk )
as the error term becomes zero. But the difficulty being finding the right
Pk+1 ’s.

? Hence, if we choose the points x0 , . . . , xk as the zeros of the polyno-


mial Pk+1 ( x ) of degree k + 1, which is orthogonal to the weight function
w( x ) over ( a, b) to any polynomial of degree ≤ k, and if the coefficients Ai
for i = 0, . . . , k are chosen in accordance with Eq. 10.43, then the resulting
Gaussian Quadrature Formula will then be EXACT for all polynomials
of degree ≤ 2k + 1.

But we see that determining Pk+1 ( x ) is not at all obvious. One thing we
can do, however, is to choose the orthogonal polynomials Pk+1 to be Leg-
endre Polynomials! But the Legendre polynomials are only defined over
Rb
(−1, 1). Thus, one needs to transform original integral a f ( x )dx over the
R1
limits −1 and 1 to write −1 g(τ )dτ. This can be done using the following
change of variable,
(b − a)t + (b + a)
x=
2
Now, we can use the argument above to, for any k, construct the Orthogo-
nal Legendre Polynomials, find it’s roots ξ i , subsequently exactly calculate
the integral by Eq. 10.42, 10.43 and xi = ξ i .

Refer to Example in Lecture 20 for more rigidity.

CHAPTER 10. NUMERICAL INTEGRATION


Chapter 11

Numerical Solutions to IVPs for


ODEs : One-Step Method

We first consider the first-order ordinary differential equations as we can


use the same idea to extend these ideas to higher order ODEs as they can
be written as a system of first order ODEs.

Consider a first-order IVP of the form


y0 = f ( x, y) , y( x0 ) = y0 (11.1)
where the function f may be linear or non-linear.

Clearly, before jumping into the numerical techniques, we must first make
sure concretely that the question we are trying to solve indeed has a solu-
tion and that the solution is unique. To that extent, for IVP in Eq. 11.1, we
have the following theorem,

Theorem 11.13 : (Unique Solution of Eq. 11.1) If f ( x, y) is continuous


in a rectangle
R = {( x, y) : | x − x0 | ≤ a , |y − y0 | ≤ b}
satisfies a Lipschitz condition in the second variable
| f ( x, y1 ) − f ( x, y2 )| ≤ L|y1 − y2 | ∀( x, y1 ), ( x, y2 ) ∈ R2
Then the IVP in Eq. 11.1 has a unique solution in the interval | x − x0 | ≤ α
where,  
b
α = min a, and M = max| f ( x, y)|
M R

93
Scientific Computing 94

11.1 Taylor-Series Method


Note that we can expand the y( x ) into it’s Taylor Series to get,

( x − x0 )2 00
y ( x ) = y ( x0 ) + ( x − x0 ) y 0 ( x0 ) + y ( x0 ) + . . .
2!
h2 00
= y0 + hy0 ( x0 ) + y ( x0 ) + . . .
2!
where x − x0 = h. If f is sufficiently differentiable with respect to x and
y, we can compute,

y0 = f ( x, y)
y00 = f 0 = f x + f y y0 = f x + f y f
y000 = f 00 = f xx + f xy f + f yx f + f yy f 2 + f y f x + f y2 f
and so on . . .

Now let yn be approximations to the true solutions y( xn ) at the points


xn = x0 + nh , n = 0, 1, 2, . . . . That is,

yn ≈ y( xn )

We thus arrive at the Taylor’s Algorithm of Order k.

11.1.1 Taylor’s Algorithm of Order k


Algorithm : To find an approximate solution of the IVP

y0 = f ( x, y) , y( x0 ) = y0

over an interval [ a, b].


b− a
Step 1 : Choose a step size h = N . Set,

xn = x0 + nh , n = 0, 1, . . . , N

Step 2 : Generate approximations yn to y( xn ) from the recursion

yn+1 = yn + hTk ( xn , yn ) , n = 0, 1, . . . , N − 1

where Tk is,

h 0 h k −1 ( k −1)
Tk ( x, y) = f ( x, y) + f ( x, y) + . . . f ( x, y) , k = 1, 2, . . .
2! k!

CHAPTER 11. NUMERICAL SOLUTIONS TO IVPS FOR ODES :


ONE-STEP METHOD
95 Scientific Computing

Here, f ( j) denotes the jth derivative of the function f ( x, y( x )) with


respect to x.

So we are basically truncating the Taylor series to kth order and take
the h common out from them as y0 = f .

Note that we calculate y at x = xn+1 by using only the informa-


tion about y and it’s derivatives at the previous step x = xn . Such a
method is thus called One-Step/Single-Step Method.

Error in Taylor’s Algorithm


Taylor’s Theorem with remainder term shows the local error of Taylor’s
Algorithm of order k can be written as,

h k +1 ( k ) h k +1 ( k +1)
E= f (ξ, y(ξ )) = y (ξ ) , xn < ξ < xn + h (11.2)
( k + 1) ! ( k + 1) !

The Taylor algorithm is said to be of order k if the local error E is O(h(k+1) ).

11.2 Euler’s Method


Setting k = 1 (Taylor’s Algorithm of Order 1), we obtain,

y n +1 = y n + h f ( x n , y n ) (11.3)

which is known as Euler’s Method. Note that the xn is still calculated as


per the Taylor’s Algorithm. The Local Error is simply

h2 00
E= y (ξ ) (11.4)
2

CHAPTER 11. NUMERICAL SOLUTIONS TO IVPS FOR ODES :


ONE-STEP METHOD
Scientific Computing 96

Figure 11.1: Geometric Interpretation of Euler’s Method.

Error in Euler’s Method


Theorem 11.14 : (Error Estimate) Let yn be the approximate solution of

y0 = f ( x, y) , y( x0 ) = y0

as generated by Euler’s Method. If y00 ∈ C ([ x0 , b]) and

f y ( x, y) < L , y00 ( x ) < M , x ∈ [ x0 , b]


for fixed positive constants L and M, then, the error en = y( xn ) − yn of Euler’s


method at a point xn = x0 + nh is bounded as follows,

hM h ( xn − x0 ) L i
| en | ≤ e −1
2L
This theorem shows that the error is O(h) and en → 0 as h → 0.

Refer to Lecture 21 for a small example.

11.3 Runge-Kutta Method


We previously saw that in Taylor’s Algorithm of order k and that in Eu-
ler’s Method, one needs higher order derivatives of a function. But we
definitely don’t have that information with us. Moreover, the approxima-
tions done by such methods only produce results with low error when h
is low enough. Thus, we try to look at the methods which only require
function calculations instead of requiring to calculate an explicit form of
other functions.

CHAPTER 11. NUMERICAL SOLUTIONS TO IVPS FOR ODES :


ONE-STEP METHOD
97 Scientific Computing

To that extent, the Runge-Kutta Method plays a major step. In this method,
we seek a formula of the form,

yn+1 = yn + ak1 + bk2


(11.5)
k1 = h f ( xn , yn ) , k2 = h f ( xn + αh, yn + βk1 )

where the constants a, b, α, β are to be determined so that Eq. 11.5 will


agree with the Taylor Algorithm of as high an order as possible.

Expanding y( xn+1 ) in a Taylor’s Series yields us (keep the original prob-


lem, Eq. 11.1, in mind),

h2 00 h3
y( xn+1 ) = y( xn + h) = y( xn ) + hy0 ( xn ) + y ( xn ) + y000 ( xn ) + . . .
2 6
h2
= y( xn ) + h f ( xn , yn ) + ( f x + f y f )n
2
h 3
+ ( f xx + 2 f xy f + f yy f 2 + f y f x + f y2 f )n + O(h4 )
6
(11.6)

On the other hand, expanding f ( xn + αh, yn + βk1 ) as in Eq. 11.5 by using


Taylor’s Expansion for functions of two variables, we have,

k2 α2 h2
= f ( xn + αh, yn + βk1 ) = f ( xn , yn ) + αh f x + βk1 f y + f xx
h 2 (11.7)
β2 k21
+ (αhβk1 ) f xy + f yy + O(h3 )
2
where all derivatives are evaluated at ( xn , yn ). Substituting the expression
for k2 above in Eq. 11.5 and using k1 = h f ( xn , yn ), we get upon rearrange-
ment in powers of h that,

yn+1 = yn + ( a + b)h f + bh2 (α f x + β f f y )


 2
β2 2 (11.8)

3 α
+ bh f xx + αβ f f xy + f f yy + O(h4 )
2 2

Now, simply comparing the corresponding powers of H and h2 from Eq.


11.6 and Eq. 11.8, we must have,

a+b = 1
1
bα = bβ =
2

CHAPTER 11. NUMERICAL SOLUTIONS TO IVPS FOR ODES :


ONE-STEP METHOD
Scientific Computing 98

Note that there are many solutions to the above system, the simplest per-
haps being,

1
a=b=
2
α=β=1

and we use this in the following algorithm.

Runge-Kutta Method of Order 2

Algorithm : For the equation,

y0 = f ( x, y) , y( x0 ) = y0

generate approximations yn to the exact solution y( x0 + nh), for fixed h,


using the recursion formula,

1
y n +1 = y n + ( k 1 + k 2 )
2
k1 = h f ( xn , yn ) (11.9)
k2 = h f ( xn + h, yn + k1 )

Also, the local error is of the form (refer Eq. 11.6 and Eq. 11.8)

h3
y ( x n +1 ) − y n +1 = ( f xx + 2 f xy f + f yy f 2 + f y f x + f y2 f ) + O(h4 )
12 (11.10)
= O ( h3 )

Note that the this method thus takes average slope between two points
as the quantity to add to current estimate at the previous point h distance
away.

Runge-Kutta Method of Order 4

Algorithm : For the equation,

y0 = f ( x, y) , y( x0 ) = y0

CHAPTER 11. NUMERICAL SOLUTIONS TO IVPS FOR ODES :


ONE-STEP METHOD
99 Scientific Computing

generate approximations yn to the exact solution y( x0 + nh), for fixed h


and n = 0, 1, . . . using the following recursion formula,

1
yn+1 = yn + (k1 + 2k2 + 2k3 + k4 )
6
k1 = h f ( xn , yn )
h k
k2 = h f ( xn + , yn + 1 ) (11.11)
2 2
h k2
k3 = h f ( xn + , yn + )
2 2
k4 = h f ( xn + h, yn + k3 )

Also, the Local Discretization Error would be of order O(h5 ) (Eq. 11.6 &
Eq. 11.8).

11.4 Systems of Differential Equations


Now we would use the previous methods for solving first order IVPs to
solve an N th order equation of the form,

y( N ) ( x ) = f ( x, y( x ), y0 ( x ), . . . , y( N −1) ( x )) (11.12)

can be written as a system of N first order equations through substitution.


With y1 = y, set,

y10 = y2
y20 = y3
y30 = y4
.. (11.13)
.
y0N −1 = y N
y0N = f ( x, y1 , y2 , . . . , y N )

More generally, a system of N first-order equations will have the form,

y10 = f 1 ( x, y1 , y2 , . . . , y N )
y20 = f 2 ( x, y1 , y2 , . . . , y N )
.. (11.14)
.
y0N = f N ( x, y1 , y2 , . . . , y N )

CHAPTER 11. NUMERICAL SOLUTIONS TO IVPS FOR ODES :


ONE-STEP METHOD
Scientific Computing 100

Fourth-order Runge-Kutta Method for the system of two equations


For simplicity, we now illustrate Fourth-order Runge-Kutta Method for
the system of two equations of the form

y0 = f ( x, y, z)
(11.15)
z0 = g( x, y, z)

with the initial conditions y( x0 ) = y0 and z( x0 ) = z0 .

Algorithm :

1. Set xn = x0 + nh where n = 0, 1, . . . .

2. Generate approximations yn and zn to the exact solutions y( xn ) and


z( xn ), using the recursion formula,

1
yn+1 = yn + (k1 + 2k2 + 2k3 + k4 )
6 (11.16)
1
zn+1 = zn + (l1 + 2l2 + 2l3 + l4 )
6
where,

k1 = h f ( xn , yn , zn )
l1 = hg( xn , yn , zn )
 
h k1 l1
k2 = h f xn + , yn + , zn +
2 2 2
 
h k1 l1
l2 = hg xn + , yn + , zn +
2 2 2
  (11.17)
h k2 l2
k3 = h f xn + , yn + , zn +
2 2 2
 
h k2 l2
l3 = hg xn + , yn + , zn +
2 2 2
k4 = h f ( xn + h, yn + k3 , zn + l3 )
l4 = hg ( xn + h, yn + k3 , zn + l3 )

CHAPTER 11. NUMERICAL SOLUTIONS TO IVPS FOR ODES :


ONE-STEP METHOD
Chapter 12

Numerical Solutions to IVPs for


ODEs : Multi-Step Methods

The One-Step methods discussed in previous chapter (Taylor’s Method,


Euler Method, Runge-Kutta Methods) use the information on the solution
of the previous step to compute the solution at the next step. We now dis-
cuss Mutli-Step Methods, where we make use of the information about the
solution at more than one point.

Consier the IVP of the form

y0 = f ( x, y) , y( x0 ) = y0 (12.1)

Now, let us assume that we have already obtained approximations to y0


and y at a number of equally spaced points, say x0 , x1 , . . . , xn . Integrating
the differential equation 12.1 from xn to xn+1 , we get,

Z x n +1 Z x n +1
0
y dx = f ( x, y( x ))dx
xn xn
Z x n +1 (12.2)
=⇒ y n +1 = y n + f ( x, y( x ))dx
xn

as we don’t have any information about the RHS integral, thus we now
simply approximate f ( x, y( x )) by a polynomial pm ( x ) which interpo-
lates f ( x, y( x )) at the m + 1 points xn , xn−1 , xn−2 , . . . , xn−m seen previ-
ously. Set,
f ( xk , y( xk )) = f k

101
Scientific Computing 102

12.0.1 Adams-Bashford Method


Using Newton’s backward formula of degree m for this purpose, we form
pm ( x ) as the following,
m 
−s k x − xn

pm ( x ) = ∑ ∆ f n−k where s = (12.3)
k =0
k h

where ∆ is the forward difference operator and ∆ f i = f i+1 − f i and


∆ 2 f i = ∆ ( ∆ f i ) = ∆ ( f i +1 − f i ) = f i +2 − 2 f i +1 + f i .

Inserting this equation into the integral in Eq. 12.2 and noting that hds =
dx and also appropriately changing the limits, we get,
Z 1 m  
−s k
y n +1 = y n + h ∑
0 k =0 k
∆ f n−k

= yn + h [γ0 f n + γ1 ∆ f n−1 + · · · + γm ∆m ]
(12.4)
where,
Z 1 
k −s
γk = (−1) ds
0 k
The Eq. 12.4 is called the Adams-Bashford Method.

For example, consider m = 3. Thus, from Eq. 12.4, we have,


 
1 5 2 3 3
y n +1 = y n + h f n + ∆ f n −1 + ∆ f n −2 + ∆ f n −3
2 12 8
Now, expanding the forward-difference formulas yields us,
∆ f n −1 = f n − f n −1
∆ 2 f n −2 = f n − 2 f n −1 + f n −2
∆ 3 f n −3 = f n − 3 f n −1 + 3 f n −2 − f n −3
Substituting them, we get,
h
y n +1 = y n + (55 f n − 59 f n−1 + 37 f n−2 − 9 f n−3 )
24
Note that the local discretization error would be,
251
E AB = h5 y(5) (ξ ) = O ( h5 )
720
Remarks:

CHAPTER 12. NUMERICAL SOLUTIONS TO IVPS FOR ODES :


MULTI-STEP METHODS
103 Scientific Computing

• One major disadvantage of Multi-Step formulas is that they are not


self-starting. These starting values must be obtained by some inde-
pendent method like the Single-Step methods discussed in the chap-
ter earlier.

• Another disadvantage of the Adams-Bashford method is that, al-


though the local discretization error is O(h5 ), the coefficient in the
error term is somewhat larger than for formulas of the Runge-
Kutta type of the same order.

• On the other hand, the Multi-Step formula require only one deriva-
tive evaluation per step, compared with four evaluations per step
with Runge-Kutta methods and is therefore considered faster and
requires less computational load.

12.1 Predictor-Corrector Methods


We now see another type of method for solving ODEs as a member of
Multi-Step methods. we Continue from Eq. 12.2, which we write here
again for brevity,
Z x n +1 Z x n +1
0
y dx = f ( x, y( x ))dx
xn xn
Z x n +1
=⇒ y n +1 = y n + f ( x, y( x ))dx
xn

? Now, approximating the integral by the trapezoidal rule, we obtain,


h
y n +1 = y n + [ f ( xn , yn ) + f ( xn+1 , yn+1 )] , n = 0, 1, 2, . . . (12.5)
2
h 000 3
Note that the error of this formula is simply E = − 12 y (Chapter 10, Eq.
10.17). Thus, the formula Eq. 12.5 is known as Improved Euler Method.

Note that the Eq. 12.5 is an implicit equation for yn+1 .

? If f ( x, y) is a non-linear function, then it is difficult to solve Eq. 12.5


for yn+1 exactly. However, one can attempt to obtain yn+1 by means of
iteration. Thus, keeping xn fixed, we obtain a first approximation to yn+1
by means of Euler’s Formula,
(0)
y n +1 = y n + h f ( x n , y n )

CHAPTER 12. NUMERICAL SOLUTIONS TO IVPS FOR ODES :


MULTI-STEP METHODS
Scientific Computing 104

(0)
Then, compute f ( xn+1 , yn+1 ) and obtain the following approximation,

(1) hh (0)
i
y n +1 = y n + f ( x n , y n ) + f ( x n +1 , y n +1 )
2
(1) (2)
Continue the iteration to calculate f ( xn+1 , yn+1 ) and obtain yn+1 as,

(2) hh (1)
i
y n +1 = y n + f ( x n , y n ) + f ( x n +1 , y n +1 )
2
In general, the iteration is given by,

(k) hh ( k −1)
i
y n +1 = y n + f ( xn , yn ) + f ( xn+1 , yn+1 ) , k = 1, 2, . . .
2
This leads us to the following algorithm.

12.1.1 Second-Order Predictor-Corrector Method


Algorithm : For the differential equation

y0 = f ( x, y) , y( x0 ) = y0

with h given and xn = x0 + nh, for each fixed n = 0, 1, . . . . Now,


(0)
1. Compute yn+1 using,

(0)
y n +1 = y n + h f ( x n , y n )

(k)
2. Compute yn+1 where k = 1, 2, . . . , using,

(k) hh ( k −1)
i
y n +1 = yn + f ( x n , y n ) + f ( x n +1 , y n +2 )
2
iterating on k untill
(k) ( k −1)
y n +1 − y n +1

(k)
<e
y n +1

for a prescribed tolerance.

Remarks:

CHAPTER 12. NUMERICAL SOLUTIONS TO IVPS FOR ODES :


MULTI-STEP METHODS
105 Scientific Computing

• It is customary to call an explicit formula such as Euler’s Formula an


Open Type formula, while an implicit formula such as 12.5 is said to
be of Closed Type.
• When they are used as a pair of formulas, the open-type formula is
called a predictor, while the closed-type formula is called a corrector.
A natural question to ask now would be that what are the conditions on
which the inner iteration on k will converge?

To that extent we have the following theorem.


∂f
Theorem 12.15 : Let f ( x, y) , ∂y ∈ C ( R). Then, the inner iteration defined
by,
(k) hh ( k −1)
i
y n +1 = y n + f ( xn , yn ) + f ( xn+1 , yn+1 ) , k = 1, 2, . . .
2
will converge, provided h is chosen small enough so that, for x = xn and for
(0)
all y with |y − yn+1 | < |yn+1 − yn+1 |,

∂f
h < 2
∂y

(k)
Proof : Observe that with xn fixed and setting yn+1 = Y (k) , we can write
the iteration in Eq. 12.5 in the form,
 
(k) ( k −1)
Y =F Y

h
where F (Y ) = 2 f ( xn+1 , Y ) + C. Here C depends on n not on Y.

Now, consider the above equation as the fixed point iteration with iter-
ation function F (Y ). Now, since we know that this would converge when,
0
F (Y ) < 1 ∀ Y with |Y − yn+1 | < |Y (0) − yn+1 |

where yn+1 is the fixed point of F (Y ).

Thus, iteration would converge if,




0
h ∂f 2
| F (Y )| ≤
< 1 =⇒ h < ∂ f
2 ∂y
∂y

QED.

CHAPTER 12. NUMERICAL SOLUTIONS TO IVPS FOR ODES :


MULTI-STEP METHODS
Scientific Computing 106

12.1.2 The Adams-Moulton Method


Continuing from the following recurrence relation,
Z x n +1
y n +1 = y n + f ( x, y( x ))dx
xn

for the IVP in Eq. 12.1. We now approximate f ( x, y( x )) by a polynomial


which interpolates at xn+1 , xn , . . . , xn−m for an integer m > 0. Then, use of
Newton’s backward interpolation formula which interpolates f at these
m + 2 points (instead of m + 1) in terms of s = x−hxn yields,
m +1
k 1−s
 
pm+1 (s) = ∑ (−1) ∆ k f n +1− k
k =0
k
These differences are based on the m + 2 values f n+1 , f n , . . . , f n−m . Replac-
ing f by pm+1 in Eq. 12.2, we get the following,
Z 1 m +1
k 1−s
 
y n +1 = y n + h ∑ (−1) k ∆k f n+1−k ds
0 k =0
h i
0 0 0 m +1
= yn + h γ0 f n+1 + γ1 ∆ f n + · · · + γm+1 ∆ f n−m
(12.6)
where,
Z 1 m +1 
1−s

0
γk = (−1) k
∑ k ds , k = 0, 1, . . . , m + 1
0 k =0

This formula is known as Adams-Moulton Multi-Step Formula.

For Example, consider m = 2 and the values of coefficients are γ00 =


1, γ10 = − 21 , γ20 = − 12
1
and γ30 = − 24
1
, we obtain the formula,
 
1 1 2 1 3
y n +1 = y n + h f n +1 − ∆ f n − ∆ f n −1 − ∆ f n −2
2 12 24
Putting in the values of the forward difference operators, we simply ob-
tain,
h
yn+1 = yn + (9 f n+1 + 19 f n − 5 f n−1 + f n−2 ) (12.7)
24
and the error in this example would be,
19 5 (iv)
E AM = − h y (ξ )
720
This result in this example is used in demonstrating the following algo-
rithm

CHAPTER 12. NUMERICAL SOLUTIONS TO IVPS FOR ODES :


MULTI-STEP METHODS
107 Scientific Computing

The Adams-Moulton Predictor-Corrector Method


Algorithm : For the IVP,

y0 = f ( x, y) , y( x0 ) = y0

and with fixed h, xn = x0 + nh and given (y0 , f 0 ), (y1 , f 1 ), (y2 , f 2 ), (y3 , f 3 ),


where f i = f ( xi , yi ). Note that we have m = 3
(0)
1. Compute yn+1 using the Adams-Bashforth Formula as in the exam-
ple in it’s section,

(0) h
y n +1 = y n + (55 f n − 59 f n−1 + 37 f n−2 − 9 f n−3 ) , n = 3, 4, . . .
24

(0) (0)
2. Compute f n+1 = f ( xn+1 , yn+1 ).

3. Improve the value of yn+1 using the Adams-Moulton Muti-Step


Formula (Eq. 12.7),

(k) h  ( k −1)

y n +1 = yn + 9 f ( xn+1 , yn+1 ) + 19 f n − 5 f n−1 + f n−2 k = 1, 2, . . .
24

4. Iterate on k until,

(k) ( k −1)
y n +1 − y n +1

(k)
< e , for prescribed tolerance e
y n +1

12.2 Stability of Multi-Step Methods 1


Consider the IVP as discussed earlier,

y0 = f ( x, y) , y( x0 ) = y0

Integrating from xn−1 to xn+1 yields,


Z x n +1 Z x n +1
0
y dx = f ( x, y)dx
x n −1 x n −1

1 This section contains some details which are rigorously explained in the following
chapter.

CHAPTER 12. NUMERICAL SOLUTIONS TO IVPS FOR ODES :


MULTI-STEP METHODS
Scientific Computing 108

Now, using the mid-point rule for the integral on RHS leads to the fol-
lowing multi-step method,
yn+1 = yn−1 + 2h f n (12.8)
Since we want to focus on the stability of this multistep method, thus, for
the instance, let us consider the following problem as an example,
y0 = −2y + 1 , y(0) = 1 (12.9)
The exact solution of this can be found to be simply,
1 −2x 1
y( x ) =
e + (12.10)
2 2
Applying the multi-step method with f n = f ( xn , yn ) = −2y + 1 (Eq. 12.8),
we get,
yn+1 + 4hyn − yn−1 = 2h , y0 = 1
X Following the method to solve a Linear Difference Equation in the next
chapter, we find the characteristics polynomial is (for general solution),
β2 + 4hβ − 1 = 0
which gives us,
p p
β 1 = −2h + 1 + 4h2 β 2 = −2h − 1 + 4h2

Now, expanding 1 + 4h2 using Taylor Series gets us,
β 1 ≈ 1 − 2h + O(h2 ) and β 2 = −1 − 2h + O(h2 )
Note the particular solution is simply ynPS = 21 , thus the general solution is
simply (refer Chapter 13 for more details),
1
yn = C1 (1 − 2h + O(h2 ))n + C2 (−1 − 2h + O(h2 ))n + (12.11)
2
xn
Note that n = h as x0 = 0. Thus for fixed xn , we have this important
observation,
1
lim (1 + 2h)n = lim (1 + 2h) 2h 2xn = e2xn
h→∞ h→∞
n −2xn
Similarly, lim (1 − 2h) = e
h→∞
Hence, in the limit h → 0, the solution of Eq. 12.9 as written in eq. 12.11
becomes,  
−2xn 1
yn = C1 e + + C2 (−1)n e2xn (12.12)
2
Remarks:-

CHAPTER 12. NUMERICAL SOLUTIONS TO IVPS FOR ODES :


MULTI-STEP METHODS
109 Scientific Computing

• Note that the first term tends to the true solution (Eq. 12.11) of
the differential equation. The second term is extraneous and arises
only because we have replaced a first-order difference equation by
a second-order difference equation!

• The error term induced from extraneous solution will eventually


dominate the true solution and lead to completely incorrect results!!

Now, for a general case, suppose that a multi-step method leads to a dif-
ference equation of order k whose characteristics equation is,

β k + a k −1 β k −1 + · · · + a 0 = 0 (12.13)

If Eq. 12.13 has k distinct zeros, say β 1 , β 2 , . . . , β k . The GS of the corre-


sponding homogeneous difference equation is then,

yn = c1 βn1 + c2 βn2 + · · · + ck βkn ∀ n

? Now, one of these solutions, say βn1 , will tend to the exact solution of
the differential equation as h → 0. All the other solutions ( βn2 , . . . , βnk )
are thus extraneous. We hence arrive at the following definition.

Definition : A multi-step method is said to be strongly stable if the extraneous


roots satisfy the condition

| β i | < 1 , i = 2, 3, . . . , k

It’s trivial to see that if | β i | > 1 for any i = 2, 3, . . . , k, then the errors will
grow exponentially.

Note : First example in Lecture 25 shows that Adams-Bashforth method


is strongly-stable. We demonstrate below the stability of Milne’s Method.

12.2.1 Example : Stability of Milne’s Method


Consider the IVP,
y0 = λy , y(0) = 1
The Milne’s method is given by,

h
y n +1 = y n −1 + ( f n +1 + 4 f n + f n −1 )
3

CHAPTER 12. NUMERICAL SOLUTIONS TO IVPS FOR ODES :


MULTI-STEP METHODS
Scientific Computing 110

Since f ( x, y) = λy, it follows that,



y n +1 − y n −1 −(yn+1 + 4yn + yn−1 ) = 0
3
It’s characteristics equation is thus given by,
p( β) + hλq( β) = 0 where,
p ( β ) = β2 − 1 (12.14)
1
q( β) = − ( β2 + 4β + 1)
3
Now, as h → 0, we would have the following,
p ( β ) = β2 − 1 = 0
which has two roots, β 1 = 1 , β 2 = −1. By definition, hence, Milne’s
method is not strongly stable!

Moreover, for small h, the roots of the stability polynomial Eq. 12.14 is,
β 1 = 1 + λh + O(h2 )
 
λh
β2 = − 1 − + O ( h2 )
3
The general solution is thus,
 n
2 n n λh
yn = c1 (1 + λh + O(h )) + c2 (−1) 1− + O ( h2 ) (12.15)
3
xn
Set n = h and let h → 0, the solution thus approaches,
λxn
yn = c1 eλxn + c2 (−1)n e− 3
| {z } | {z }
yd,n ( x ) ye,n ( x )

? Remarks :
• If λ > 0, the desired solution yd,n ( x ) is exponentially increasing
and the extraneous solution ye,n ( x ) is exponentially decreasing. In
that case, the Milne’s method would be stable, NOT strongly stable
though.
• On the other hand, if λ < 0, then Milne’s method would be unstable
as the extraneous solution ye,n ( x ) would be increasing exponentially.
• Methods of this type whose stability depends on the the sign of λ for
the test equation y0 = λy are said to be weakly stable.

CHAPTER 12. NUMERICAL SOLUTIONS TO IVPS FOR ODES :


MULTI-STEP METHODS
Chapter 13

Solutions of Linear Difference


Equations

We now turn our attention to finding solutions of the linear difference


equations (LDE). An LDE of order N is of the form,

y n + N + a N − 1 y n + N − 1 + a N − 2 y n + N − 2 + · · · + a 0 y n = bn (13.1)

where a N −1 , a N −2 , . . . , a0 are constants.

? If bn = 0, then Eq. 13.1 is called a Homogeneous LDE.

13.1 Solutions to homogeneous LDE


We seek solutions of the form yn = βn for all n. Thus, substituting, we
get,
y n + N = β n + N , y n + N −1 = β n + N −1 , . . .
into Eq. 13.1 with bn = 0 (homogeneous), to get,

β n + N + a N −1 β n + N −1 + · · · + a 0 β n = 0

Thus,
p ( β ) = β N + a N −1 β N −1 + · · · + a 0 = 0 (13.2)
which is known as characteristics equation.

Now with regards to the characteristics equation in Eq. 13.2, we can have
following cases,

111
Scientific Computing 112

CASE I : Assume that Eq. 13.2 has N distinct zeros β 1 , β 2 , . . . , β N .

Thus, we have that


βn1 , βn2 , . . . , βnN

are all solutions to Eq. 13.1.

Thus, by linearity, we can write the general solution (GS) as,

yn = c1 βn1 + c2 βn2 + · · · + c N βnN ∀n (13.3)

where c1 , c2 , . . . , c N are arbitrary constants.

Remark : If the first N − 1 values of yn are given, the resulting initial-


value difference equation can be solved explicitly for all succeeding
values of n. That is to say that if we are given yi for i = 0, . . . , N − 1,
then we can solve for the constants ci that arise in the general solu-
tion.

CASE II : If the characteristic equation (Eq. 13.2) has a pair of conjugate-complex


roots, the solution can still be expressed in real form.

Thus, if β 1 = α + iβ and β 2 = α − iβ, then we write,

β 1 = reiθ
(13.4)
β 2 = re−iθ
 
where r = α2 + β2 and θ = tan−1 α . Thus, the general solution
p β

(GS) corresponding to this pair is simply,

yn = c1 βn1 + c2 βn2 = c1 r n einθ + c2 r n e−inθ


= r n [c1 (cos nθ + i sin nθ ) + c2 (cos nθ − i sin nθ )]
= r n (C1 cos nθ + C2 sin nθ )
(13.5)

CASE III : If β 1 is a double root of the characteristic equation Eq. 13.2, then a second
solution of the homogeneous LDE is nβn1 .

CHAPTER 13. SOLUTIONS OF LINEAR DIFFERENCE EQUATIONS


113 Scientific Computing

Thus, if we substitute yn = nβn1 in the homogeneous LDE, we get,

(n + N ) βn1 + N + a N −1 (n + N − 1) βn1 + N −1 + · · · + a0 nβn1


= βn1 [n( β 1N + a N −1 β 1N −1 + · · · + a0 ) + β 1 ( Nβ 1N −1 + a N −1 ( N − 1) β 1N −2
+ · · · + a1 )]
= βn1 np( β 1 ) + β01 ( β 1 ) = 0
 

13.2 Solution to Non-homogeneous LDE with con-


stant coefficients
The General Solution of the equation

y n + N + a N − 1 y n + N − 1 + · · · + a 0 y n = bn (13.6)

can be written in the form,

yn = ynGS + ynPS

where ynGS is the General Solution of the Homogeneous LDE (i.e. for
bn = 0) and ynPS is the particular solution of the Eq. 13.6.

Note that in the special case that bn = b is a constant, one can find partic-
ular solution by simply substituting ynPS = A (a constant). This constant
would be simply,
b
A=
1 + a N −1 + · · · + a 0
provided, of-course, 1 + a N −1 + · · · + a0 6= 0.

CHAPTER 13. SOLUTIONS OF LINEAR DIFFERENCE EQUATIONS


Scientific Computing 114

CHAPTER 13. SOLUTIONS OF LINEAR DIFFERENCE EQUATIONS


Chapter 14

Finite Difference Approximations


to Derivatives

Consider the two-dimensional second-order PDE:


∂2 U ∂2 U ∂2 U ∂U ∂U
a 2
+ b + c 2
+d +e + fU + g = 0 (14.1)
∂x ∂x∂y ∂y ∂x ∂y
where a, b, c, d, e, f , g may be functions of the independent variables x and
y and the dependent variable U = U ( x, y).

We can classify the PDE 14.1 on the basis of the coefficients as follows,
• Elliptic : when b2 − 4ac < 0.
• Parabolic : when b2 − 4ac = 0.
• Hyperbolic : when b2 − 4ac > 0.
The above classification occur many times in real world as the following
examples show.

Elliptic Equations : These problems are generally associated with equi-


librium or steady-state problems. For example,
• Laplace’s Equation,
∂2 U ∂2 U
+ 2 =0
∂x2 ∂y
• Poisson’s Equation,
∂2 U ∂2 U
+ 2 = f ( x, y)
∂x2 ∂y

115
Scientific Computing 116

Parabolic Equations : The heat equation,

∂U ∂2 U
=κ 2
∂t ∂x

Hyperbolic Equations : One-Dimensional Wave Equation,

∂2 U 2
2∂ U
= c
∂t2 ∂x2

14.1 Finite Difference Approximations to Deriva-


tives
Now to approximate the derivatives using finite differences, we use the
composite rules.

14.1.1 Functions of one-variable


Let U : [ a, b] → R be sufficiently differentiable function. Let

a = x o < x1 < x2 < · · · < x n = b

x n − x0
be a partition of [ a, b] such that xn = x0 + nh, where h = n is the dis-
cretization parameter.

Set xi = x0 + ih , i = 0, 1, . . . , n and Ui = U ( xi ).

Now, by Taylor’s Theorem,

0 h2 00 h3 000
U ( x + h) = U ( x ) + hU ( x ) + U ( x ) + U ( x ) + . . . (14.2)
2 6

h2 00 h3
U ( x − h) = U ( x ) − hU 0 ( x ) + U ( x ) − U 000 ( x ) + . . . (14.3)
2 6

CHAPTER 14. FINITE DIFFERENCE APPROXIMATIONS TO


DERIVATIVES
117 Scientific Computing

Now,

dU U ( xi + h ) − U ( xi )
= + O(h) (From 14.2)
dx x= xi
h
U − Ui
≈ i +1 (Forward difference formula)
h
U ( xi ) − U ( xi − h )
= + O(h) (From 14.3)
h (14.4)
Ui − Ui−1
≈ (Backward difference formula)
h
U ( xi + h ) − U ( xi − h )
= + O(h2 ) (From Eq. 14.2 - 14.3)
2h
U − Ui−1
≈ i +1 (Central difference formula)
2h

And for the second-derivative,

d2 U

U ( xi + h) − 2U ( xi ) + U ( xi − h)
2
= 2
+ O(h2 ) (From Eq. 14.2 + 14.3)
dx x= xi
h
U − 2Ui + Ui−1
≈ i +1
h2
(14.5)

14.1.2 Functions of two-variables


Let U : [0, a] × [0, b] → R be a differentiable function of x and t. Intro-
duce the mesh parameters h and k in the directions of x and t respectively.
Denote,

xi = ih , i = 0, 1, 2, . . . , N with x0 = 0 , x N = a
(14.6)
t j = jk , i = 0, 1, 2, . . . , J with t0 = 0 , t J = b

Before, the partial derivatives, let’s first define the following,

Ui,j = U ( xi , t j ) = U (ih, jk)


Ui+1,j = U ( xi + h, t j ) = U ((i + 1)h, jk) (14.7)
Ui,j+1 = U ( xi , t j + k ) = U (ih, ( j + 1)k )

CHAPTER 14. FINITE DIFFERENCE APPROXIMATIONS TO


DERIVATIVES
Scientific Computing 118

With the above, we can find the partial derivative as,

Ui+1,j − Ui,j

∂U
= + O(h)
∂x ( xi ,t j ) h
Ui,j − Ui−1,j
= + O(h)
h
Ui+1,j − Ui−1,j
= + O ( h2 )
2h
Ui,j+1 − Ui,j

∂U
= + O(k)
∂t ( xi ,t j ) k
(14.8)
Ui,j − Ui,j−1
= + O(k)
k
Ui,j+1 − Ui,j−1
= + O ( k2 )
2k
∂2 U Ui+1,j − 2Ui,j + Ui−1,j

= + O ( h2 )
∂x2 ( xi ,t j ) h 2

∂2 U Ui,j+1 − 2Ui,j + Ui,j−1



2
= + O ( k2 )
∂t ( xi ,t j )
k2

We now use the above technique for solving some application based prob-
lems in the next few sections.

14.2 The Heat Equation


Consider one-dimensional heat equation of the form

∂U ∂2 U
= x ∈ (0, 1) , t > 0
∂t ∂x2
(14.9)
U (0, t) = U (1, t) = 0 , t > 0 (Boundary Condition)
U ( x, 0) = f ( x ) , 0 ≤ x ≤ 1 (Initial Condition)

Set xi = ih , i = 0, 1, 2, . . . and t j = jk , j = 0, 1, 2, . . . .

Let Uij be the true value of the solution at the grid point ( xi , t j ).

Let uij be the finite difference approximation to the true solution at ( xi , t j ).


Thus,
uij ≈ Uij = U ( xi , t j )

CHAPTER 14. FINITE DIFFERENCE APPROXIMATIONS TO


DERIVATIVES
119 Scientific Computing

Figure 14.1: Computational Stencils for various schemes for Heat Equa-
tion.

with the basic notations in hand, we now explain various schemes by


which one can approximate the partial derivative with the help of finite
differences.

14.2.1 Schmidt’s Explicit Scheme

Technique : Use the forward-time and central-space (FTCS) schemes to


∂2 U
approximate ∂U
∂t = ∂x2 at the grid point ( xi , t j ).

Hence, we would get the partial derivatives as (from Eq. 14.8),

ui,j+1 − ui,j
 
∂U

∂t ( xi ,t j ) k
(14.10)
∂2 U ui+1,j − 2ui,j + ui−1,j
 

∂x2 ( xi ,t j ) h2

CHAPTER 14. FINITE DIFFERENCE APPROXIMATIONS TO


DERIVATIVES
Scientific Computing 120

With the above approximations to the derivatives, the heat equation 14.9
would thus yield to the following,
ui,j+1 − ui,j ui+1,j − 2ui,j + ui−1,j
=
k h2
which on simplification gives,

ui,j+1 = rui−1,j + (1 − 2r )ui,j + rui+1,j


where, (14.11)
k
r= 2
h
Note that in this equation, we want values of u at different values of t as
the values of u at different values of x for a fixed t can be found by recur-
sively using Eq. 14.11, the Boundary conditions and Initial conditions.

Remarks:
• It is a two level explicit system as the solution at the jth level is only
computed by values at the j − 1th level.
 
• This scheme is conditionally stable when 0 < r ≤ 21 (will be proved
soon).
• The local truncation error is O(h2 ) + O(k ) as seen from Eq. 14.9.

14.2.2 Euler’s Implicit Scheme


Technique : Use the backward-time and central-space (BTCS) schemes
at the point ( xi , t j ).

The approximations thus are,


ui,j − ui,j−1
 
∂U

∂t ( xi ,t j ) k
 2  (14.12)
∂ U ui+1,j − 2ui,j + ui−1,j

∂x2 ( xi ,t j ) h2

Thus the heat equation is,


ui,j − ui,j−1 ui+1,j − 2ui,j + ui−1,j
=
k h2

CHAPTER 14. FINITE DIFFERENCE APPROXIMATIONS TO


DERIVATIVES
121 Scientific Computing

and on simplification, it yields,

ui,j−1 = −rui−1,j + (1 + 2r )ui,j − rui+1,j


where, (14.13)
k
r= 2
h
Remarks:

• It is a two-level implicit scheme.

• At each time level, we are required to solve a linear system.

• This scheme is unconditionally stable, that is, it’s stable for all val-
ues of r.

• The local truncation error is O(h2 ) + O(k ).

14.2.3 Crank-Nicolson Scheme


Technique : Use the central difference formula for both time and space at
the mid point of on time scale.

ui,j+1 − ui,j
 
∂U
  ≈ (From Eq. 9.15)
∂t xi ,t k
j+ 21

∂2 U 1 ui−1,j+1 − 2ui,j+1 + ui+1,j+1 ui−1,j − 2ui,j + ui+1,j


   
≈ +
∂x2 h2 h2
 
xi ,t 2
j+ 21

(14.14)
Thus the Heat equation gives us,

ui,j+1 − ui,j 1 ui−1,j+1 − 2ui,j+1 + ui+1,j+1 ui−1,j − 2ui,j + ui+1,j


 
= +
k 2 h2 h2

Simplifying this finally gives us,

− rui−1,j+1 + (2 + 2r )ui,j+1 − rui+1,j+1 = rui−1,j + (2 − 2r )ui,j + rui+1,j


(14.15)
where r = hk2 .

Remarks:

CHAPTER 14. FINITE DIFFERENCE APPROXIMATIONS TO


DERIVATIVES
Scientific Computing 122

• As visible, this is a two-level implicit scheme as the value at level


j + 1 and level j are interlinked in the different levels of i. In-short,
the j + 1 level is in multiple places with different levels of i.
• At each time level, we are required to solve a linear system.
• This scheme is also unconditionally stable.
• The local truncation error is O(h2 ) + O(k2 ) (From Eq. 9.15).

14.2.4 Richardson’s Scheme


Technique : Use only the central-time and central-space (CTCS) approxi-
mation.

The CTCS approximations are (follows from Eq. 9.15),


ui,j+1 − ui,j−1
 
∂U

∂t ( xi ,t j ) 2k
 2  (14.16)
∂ U ui−1,j − 2ui,j + ui+1,j

∂x2 ( xi ,t j ) h2
the heat equation thus gives us,
ui,j+1 − ui,j−1 ui−1,j − 2ui,j + ui+1,j
= (14.17)
2k h2
Remarks:
• It is a three level explicit scheme .
• This scheme is unstable, thus not used practically.
• Local truncation error is O(h2 ) + O(k2 ).

14.2.5 DuFort-Frankel Explicit Scheme


Technique : Modification of Richardson’s scheme as follows,
ui,j−1 + ui,j+1
ui,j = (14.18)
2
Thus, substituting in the Heat equation and further simplification yields,
1 − 2r 2r
ui,j+1 = ui,j−1 + (u + ui+1,j ) (14.19)
1 + 2r 1 + 2r i−1,j
Remarks:

CHAPTER 14. FINITE DIFFERENCE APPROXIMATIONS TO


DERIVATIVES
123 Scientific Computing

• It is a three level explicit scheme.

• This scheme is unconditionally stable.

• The local truncation error is O(h2 ) + O(k2 ).

14.2.6 Weighted Average Approximation


A more general finite-difference approximation to the heat equation is
given by
ui,j+1 − ui,j 1  
= 2 θ (ui−1,j+1 − 2ui,j+1 + ui+1,j+1 ) + (1 − θ )(ui−1,j − 2ui,j + ui+1,j )
k h
(14.20)

where θ is a parameter such that 0 ≤ θ ≤ 1.

Now observe that it generalises the previous methods,

θ=0 =⇒ Scheme’s Explicit Scheme


θ=1 =⇒ Euler’s Implicit Scheme (14.21)
1
θ= =⇒ Crank-Nicolson Scheme
2
Remarks:
1
• This scheme is unconditionally stable for 2 ≤ θ ≤ 1.

• Also, this scheme is conditionally stable for 0 ≤ θ < 12 . The condi-


tion for stability is,
k 1
r= 2 ≤
h 2(1 − 2θ )
Now, define the central-difference operators δx and δt as:

δx φi,j = φi+ 1 ,j − φi− 1 ,j


2 2
(14.22)
δt φi,j = φi,j+ 1 − φi,j− 1
2 2

Thus, we can write the explicit scheme for heat equation as,

δt ui,j+ 1 = ui,j+1 − ui,j


2

δx (δx ui,j ) = δx (ui+ 1 ,j − ui− 1 ,j ) (14.23)


2 2

= ui+1,j − 2ui,j + ui−1,j

CHAPTER 14. FINITE DIFFERENCE APPROXIMATIONS TO


DERIVATIVES
Scientific Computing 124

and finally,
1 1
δt ui,j+ 1 = 2 δx2 ui,j (14.24)
k 2 h
Note that using the definitions in Eq. 14.23, you can write the Euler’s
Implicit scheme as,
1 1
δt ui,j− 1 = 2 δx2 ui,j (14.25)
k 2 h
the Crank-Nicolson scheme,
1 1 h i
δt ui,j+ 1 = 2 δx2 ui,j+1 + δx2 ui,j (14.26)
k 2 2h
and finally, the Weighted Average scheme,

1 1 h i
δt ui,j+ 1 = 2 θδx2 ui,j+1 + (1 − θ )δx2 ui,j (14.27)
k 2 h

14.3 Consistency & Stability of Finite Difference


Equations
To discuss the stability of the schemes discussed earlier, we now formulate
the definitions needed for calculating that.

Let
L (U ) = 0 (14.28)
represent the partial differential equation in the independent variables x
and t with exact solution U. Let,

Fi,j (u) = 0 (14.29)

represent the finite difference equation approximation for the PDE at (i, j)th
mesh point with exact solution u.

The local truncation error Ti,j (U ) at the point (ih, jk) is defined by

Ti,j (U ) = Fi,j (U ) − L(Ui,j ) = Fi,j (U )

as L(Ui,j ) = 0. Thus, Ti,j gives an indication of the error resulting from the
replacement of L(Ui,j ) by Fi,j (U ). We hence arrive at the following defini-
tion,

CHAPTER 14. FINITE DIFFERENCE APPROXIMATIONS TO


DERIVATIVES
125 Scientific Computing

Definition : If Ti,j (U ) → 0 as h → 0 and k → 0, then the difference equa-


tion in Eq. 14.29 is said to be consistent or compartible with the PDE Eq.
14.28.

Example. To illustrate the use of this definition, let us, for example, con-
sider the local truncation error Ti,j of the two level explicit scheme approx-
imating Ut = Uxx at the point (ih, jk).

The finite difference equation in this case will be (Eq. 14.11),


ui,j+1 − ui,j ui−1,j − 2ui,j + ui+1,j
Fi,j (u) = − =0
k h2
thus the Truncation error Ti,j ,
Ui,j+1 − Ui,j Ui−1,j − 2Ui,j + Ui+1,j
Ti,j (U ) = Fi,j (U ) = − (14.30)
k h2
By Taylor’s Expansion,
Ui+1,j = U ((i + 1)h, j) = U ( xi + h, t j )
h2 ∂2 U h3 ∂3 U
     
∂U
= Ui,j + h + + +...
∂x i,j 2 ∂x2 i,j 3! ∂x3 i,j
Ui−1,j = U ( xi − h, t j )
h2 ∂2 U h3 ∂3 U
     
∂U (14.31)
= Ui,j − h + − +...
∂x i,j 2 ∂x2 i,j 3! ∂x3 i,j
Ui,j+1 = U ( xi , t j + k )
k 2 ∂2 U k 3 ∂3 U
     
∂U
= Ui,j + k + + +...
∂t i,j 2 ∂t2 i,j 3! ∂t3 i,j

Substituting these approximations in the Finite Difference Eq. 14.30, we


get,

∂U ∂2 U
 2 
1 2 ∂4 U 1 2 ∂3 U 1 4 ∂6 U
       
1 ∂ U
Ti,j = − 2 + k − h + k − h +...
∂t ∂x i,j 2 ∂t2 i,j 12 ∂x4 i,j 6 ∂t3 i,j 360 ∂x6 i,j
 
∂2 U
Note that since ∂U∂t − ∂x2
= 0, the major contribution to the local trun-
i,j
cation error happen only through the following term,
 2 
1 2 ∂4 U
 
1 ∂ U
k − h
2 ∂t2 i,j 12 ∂x4 i,j

CHAPTER 14. FINITE DIFFERENCE APPROXIMATIONS TO


DERIVATIVES
Scientific Computing 126

Therefore, Ti,j = O(k ) + O(h2 ). Also note that,

Ti,j → 0 as h → 0 and k → 0

Thus, the explicit scheme approximating the heat equation in Eq. 14.11 is
consistent with the heat equation.

14.4 Stability

Definition : Stability is related to the round-off error. We say that the scheme
is stable if the round-off error in the numerical process is bounded.

Let R = {( x, t)|0 ≤ x ≤ 1 , 0 ≤ t ≤ T } be a rectangle. Consider the PDE,

L(U ) = 0 in R

with prescribed initial and boundary conditions.

Let h and k be the mesh parameters such that,

xi = ih , i = 0, 1, . . . , N with Nh = 1
t j = jk , j = 0, 1, . . . , N with Jk = T

Assume that h is related to k as follows: As h → 0, then k → 0 (or k = O(h)


or k = O(h2 )).

Consider the general finite difference approximation of the form:

bi−1 ui−1,j+1 + bi ui,j+1 + bi+1 ui+1,j+1 = ci−1 ui−1,j + ci ui,j + ci+1 ui+1,j
(14.32)
where bi ’s and ci ’s are constants.

Now, suppose that the boundary values u0,j and u N,j for j > 0 are known.

CHAPTER 14. FINITE DIFFERENCE APPROXIMATIONS TO


DERIVATIVES
127 Scientific Computing

Then for remaining i = 1, . . . , N − 1, we can write,


  
b1 b2 u1,j+1
 b1 b2 b3   u2,j+1 
  
. . . . ..  .. 
 . . .   . 
  
 b N −3 b N −2 b N −1  u N −2,j+1 
b N −2 b N −1 u N −1,j+1
    
c1 c2 u1,j c0 u0,j − b0 u0,j+1
 c1 c2 c3   u2,j   0 
    
. . . . . .. . .
= .   ..  +  ..
    
. 
    
 c N −3 c N −2 c N −1  u N −2,j   0 
c N −2 c N −1 u N −1,j c N u N,j − b N u N,j+1
(14.33)
In matrix notation,
Bu j+1 = Cu j + d j
=⇒ u j+1 = B−1 Cu j + B−1 d j (14.34)
=⇒ u j+1 = Au j + f j

where A = B−1 C and f j = B−1 d j .

We can apply the Eq. 14.34 recursively to obtain


u j = Au j−1 + f j−1
= A(Au j−2 + f j−2 ) + f j−1 = A2 u j−2 + Af j−2 + f j−1
(14.35)
= ...
= A j u0 + A j−1 f0 + A j−2 f1 + · · · + f j−1
? where u0 is the vector of initial values and f0 , f1 , . . . , f j−1 are the vec-
tors of known boundary values.

Since we want to find the stability of the finite difference method, so we


check the error in the resultant vector after perturbing the initial value
from u0 to u0∗ . Thus, the exact solution at the jth time level will be,

u∗j = A j u0∗ + A j−1 f0 + A j−2 f1 + · · · + f j−1 (14.36)

Now, define the perturbation error by


e∗ = u∗ − u

CHAPTER 14. FINITE DIFFERENCE APPROXIMATIONS TO


DERIVATIVES
Scientific Computing 128

then it follows from Eq. 14.35 and 14.36 that,

e j = u∗j − u j = A(u0∗ − u0 ) = A j e0

where e0 is the amount by which the initial value u0 is perturbed by.

Note that,
ke j k = kA j e0 k ≤ kA j kke0 k (14.37)
Now if there exists a positive number M, independent of j, h and k such
that kA j k ≤ M, then it’s easy to see that,

k e j k ≤ M k e0 k

Now to use this, first note that,

kA j k = kA j−1 Ak ≤ kA j−1 kkAk ≤ · · · ≤ kAk j

Thus, the bound M on kA j k would imply that,

k e j k ≤ k A k j k e0 k

The Lax & Richtmeyer definition of stability thus requires that

kAk ≤ 1 (14.38)

This is the necessary and sufficient condition for the difference equations
to be stable when the solution of the PDE does not increase as t increases.

14.5 Stability Analysis by Matrix Method


Now that we have converted our problem to equivalent matrix formula-
tion, we can now use a lot of techniques for checking convergence and
stability available from Matrix Theory!

In particular, we would explore stability of finite difference equations by


two methods, namely Matrix method and von Neumann’s1 method.

Before that, we present brief review of matrix theory.


1 Of-course!

CHAPTER 14. FINITE DIFFERENCE APPROXIMATIONS TO


DERIVATIVES
129 Scientific Computing

14.5.1 Basic Elements of Matrix Theory


• Let A be an n × n matrix. Define,
n
kAk1 = max ∑ |aij |
1≤ j ≤ n i =1
n
kAk∞ = max ∑ |aij |
1≤ i ≤ n j =1
(14.39)

kAxk
kAk = max = max kAxk
x 6 =0 kxk k x k=1

• Let v1 , v2 , . . . , vn be the eigenvectors corresponding to the eigenval-


ues λ1 , λ2 , . . . , λn of A. Then,

Avi = λ i vi
=⇒ kAvi k = kλi vi k = |λi |kvi k
=⇒ |λi |kvi k = kAvi k ≤ kAkkvi k
=⇒ |λi | ≤ kAk , i = 1, . . . , N (14.40)
=⇒ max|λi | ≤ kAk
i
or, ρ(A) ≤ kAk

where ρ(A) is called the spectral radius and is the largest eigenvalue
of matrix A.

• The eigenvalues of the following n × n matrix


 
a b
c a b 
 
. . . . . . 
 . . . 
 
 c a b
a b

are given by,

√ 


λs = a + 2 bc cos , s = 1, . . . , n (14.41)
n+1

where a, b, c ∈ R.

CHAPTER 14. FINITE DIFFERENCE APPROXIMATIONS TO


DERIVATIVES
Scientific Computing 130

Lax-Richtmeyer Stability condition


As in Eq. 14.38, the Lax-Richtemeyer Condition that kAk ≤ 1 implies that,

kAk ≤ 1 =⇒ ρ (A) ≤ 1 (14.42)

Note that the converse is not true, that is,


ρ (A) ≤ 1 6
=⇒ kAk ≤ 1
However, if A is real and symmetric, then
q q q
T
kAk = ρ(A A) = ρ(A2 ) = ρ2 (A) = ρ(A) (14.43)

Stability of the Schmidt’s Explicit Scheme


ui,j+1 = rui−1,j + (1 − 2r )ui,j + rui+1,j , i = 1, . . . , N − 1
As usual, assuming that the boundary values u0,j and u N,j are known for
j = 1, 2, . . . , thus the equivalent matrix formulation becomes,
      
u1,j+1 (1 − 2r ) r u1,j ru0,j
 u2,j+1  
   r (1 − 2r ) r   u2,j   0 
   
 .. 
=
 .. .. ..   ..   .. 
+
. . . .
 .   . 
       
  
u N −2,j+1   r (1 − 2r ) r  u N −2,j   0 
u N −1,j+1 r (1 − 2r ) u N −1,j ru N,j
| {z }
A

Clearly, the amplification matrix is A.

Now, note that


kAk∞ = 2|r | + |1 − 2r |
Now,
CASE I : 1 − 2r ≥ 0 =⇒ 0 ≤ r ≤ 12 .

Note that,
kAk∞ = r + 1 − 2r + r = 1
CASE II : 1 − 2r < 0 =⇒ r > 12 .

Therefore, |1 − 2r | = 2r − 1, and
kAk∞ = r + 2r − 1 + r = 4r − 1 > 1

CHAPTER 14. FINITE DIFFERENCE APPROXIMATIONS TO


DERIVATIVES
131 Scientific Computing

Thus, the scheme is stable only for 0 < r ≤ 21 . Note that since A is real
and symmetric,
kAk = ρ(A) = max|µs |
s

where µs is the sth eigenvalue of A.

We can do the same calculation in a more eigenvalue oriented one, i.e., de-
riving a general form of eigenvalue and using Lax-Richtemeyer condition
of stability in Eq. 14.42.

For this, first note that the matrix A can be rewritten as,
A = I N −1 + rT N −1
where,
 
1

 1 

I N −1 =
 .. 
. 
 
 1 
1
  (14.44)
−2 1
 1 −2 1 
 
T N −1 =
 . . 
. 
 
 1 −2 1 
1 −2
Now, a particular eigenvalue of A is just the sum of the corresponding
eigenvalues of I N −1 and T N −1 . Thus, we first need to find the eigenvalues
λs of T N −1 as the eigenvalues of I N −1 are trivially all 1.
 sπ 
λs = −2 + 2 cos (Eq. 14.41)
 sπ N
= −4 sin2
2N
for s = 1, . . . , N − 1. Therefore, the eigenvalues of A are,
2 sπ
 
µs = 1 − 4r sin (14.45)
2N
Now, for the stability, ρ(|µs |) ≤ 1,
 sπ 
ρ(|µs |) = max 1 − 4r sin2 ≤1 (14.46)

s 2N

CHAPTER 14. FINITE DIFFERENCE APPROXIMATIONS TO


DERIVATIVES
Scientific Computing 132

which leads to,


 sπ 
2
−1 ≤ 1 − 4r sin ≤1
2N
1
=⇒ r ≤ 2 sπ

2 sin 2N

which implies that (for s = N − 1),

1
r≤   (14.47)
2 ( N −1) π
2 sin 2N

 
( N −1) π
Hence, for h → 0, then N → ∞, which then implies that sin 2
2N →
1. Which implies that,
1
r≤ (14.48)
2
is the required condition for stability (conditionally).

14.6 Stability Analysis by von Neumann Method


& Lax Equivalence Theorem
We previously saw the basic definition of stability by Lax-Richtmeyer con-
dition. Now, we shift our focus on extending this criterion for checking
the stability of any given finite difference approximation of a certain IVP
through a method called von Neumann stability method.

Consider the IVP,

Ut = Uxx , 0 ≤ x ≤ L , 0 < t ≤ T
(14.49)
U ( x, 0) = f ( x ) , 0 ≤ x ≤ L

The basic idea now followed to find an approximate solution to this is


two-fold:

? Express initial data by finite Fourier series along the initial mesh-
point at t = 0.

? Study the growth of a function that reduced to this series at t = 0 by


variable separation method.

CHAPTER 14. FINITE DIFFERENCE APPROXIMATIONS TO


DERIVATIVES
133 Scientific Computing

Hence, the Fourier series in complex exponential form can be represented


as,
iπnx
U ( x, 0) = f ( x ) = ∑ An e L
Now, let us introduce the commonly used notations for this method before
moving into it’s peculiarities,

Define,
x p = ph , p = 0, 1, 2, . . . , N with Nh = L
tq = qk , q = 0, 1, 2, . . . , J with Jk = T (14.50)
u( x p , tq ) = u p,q = u( ph, qk )
With the above, first note that the Fourier Series terms at particular values
of x p are
iπnx p iπnph πn
An e L = An e Nh = An eiβ n ph where β n =
Nh
Now, at q = 0, i.e. t = t0 = 0,
N
u p,0 = u( ph, 0) = ∑ An eiβn ph
n =0
Using the given u p,0 at p = 0, 1, 2, . . . , N, the constants An can be uniquely
determined! But since this problem is a linear one, thus it is enough to
investigate the propagation of only one initial value, such as eiβph as sep-
arate solutions are additive. The coefficient An is a constant and can be
neglected for the growth analysis. Thus, we study,
u p,q = eiβph · eαqk = eiβph · ξ q (14.51)

where ξ = eαk and α is a constant. Note that this turns to eiβph at k = 0


which corresponds to the t = 0 criterion.

Now, by Lax-Richtemeyer definition of stability, we have,



u p,q ≤ C ∀q ≤ J
as h → 0, k → 0 and for all values of β needed to satisfy the initial condi-
tions. This inequality directly translate to,

u p,q ≤ C

iβph p
e · ξ ≤ C (Eq. 14.51)
(14.52)
iβph p
e |ξ | ≤ C
|ξ p | ≤ C

CHAPTER 14. FINITE DIFFERENCE APPROXIMATIONS TO


DERIVATIVES
Scientific Computing 134

i.e. |ξ p | should remain bounded, which is only possible if

ξ≤1 (14.53)

which is the necessary and sufficient condition for stability, or also called
the von Neumann stability condition.

Remarks:

• Consistency is related to the truncation error. We say a finite dif-


ference scheme is consistent with given PDE if the truncation error
Ti,j → 0 as h → 0 and k → 0.

• Whereas Stability is related to the round-off error. We say that a


finite difference scheme is stable if the exact solution of the finite
difference equation does not grow with time.

We finally note the major theme of the whole discussion. Since from the
beginning, we wanted to find an approximation as close as possible to the
true solution of an PDE, we hence discuss the convergence of the finite dif-
ference approximation to the true solution, starting from the following
definition.

Definition : Let Ui,j be the exact solution of the PDE at the mesh point (ih, jk)
and let ui,j be it’s finite difference approximation at the same point. Then, we say
that ui,j converges to Ui,j if

ui,j − Ui,j → 0 as h → 0 and k → 0

In the final note, we arrive at the following theorem.

Theorem 14.16 : (Lax-Equivalence Theorem) Given a well-posed, linear ini-


tial value problem and a consistent linear finite difference equation approximat-
ing it. Then, stability is the necessary & sufficient condition for conver-
gence. That is, for a consistent finite difference scheme,

Consistency + Stability =⇒ Convergence

CHAPTER 14. FINITE DIFFERENCE APPROXIMATIONS TO


DERIVATIVES

You might also like