0% found this document useful (0 votes)
18 views23 pages

Numerical Analysis

This document discusses numerical analysis and methods for finding roots of equations. It introduces concepts of errors in numerical computation including absolute and relative errors. It also describes the bisection method for finding roots of equations and provides an example of applying the method.

Uploaded by

tafadzwa munemo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views23 pages

Numerical Analysis

This document discusses numerical analysis and methods for finding roots of equations. It introduces concepts of errors in numerical computation including absolute and relative errors. It also describes the bisection method for finding roots of equations and provides an example of applying the method.

Uploaded by

tafadzwa munemo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

Chapter 1

Numerical Analysis

1.1 Introduction

1.2 Errors in Numerical Computation

1.2.1 Absolute and Relative Errors

Definition 1.2.1 A number a∗ is said to be an approximate number to the exact num-


ber a, if it differs slightly from a. The approximate number, a∗ is called a minor
approximation if it is less than a, and a major approximation if it is greater than a.

For example, 2.6 is a minor approximation of 7 and 2.7 is a mjor approximation.
If a∗ is an approximate value of a, we write a∗ ≈ a.

Definition 1.2.2 The difference between the exact number a and the approximate
number a∗ is called the error, sometimes denoted by ∆a, that is, ∆a = a − a∗ , where
∆a < 0 for a < a∗ , ∆a > 0 for a > a∗ .

If a∗ is an approximation to a, the absolute error is given by ∆ = |a − a∗ |.

Definition 1.2.3 If a∗ is an approximation to a and ∆ the absolute error, then

∆ = |a − a∗ | ≤ ∆a

where ∆a is called the limiting absolute error of the approximation.

Clearly,
a∗ − ∆a ≤ a ≤ a∗ + ∆a
where (a∗ − ∆a ) is the minor approximation and
(a∗ + ∆a ) is the major approximation of a

Exercise 1.2.1 Determine the limiting absolute error of the approximation number
a = 2.7 to the number e.

Solution 1.2.1
∆ = |e − 2.7| ≤ ∆a

2.7 − ∆a ≤ e ≤ ∆a + 2.7
Since e > 2.7 and e < 2.72, |e − 2.7| < 2.72 − 2.7 = 0.02 ⇒ ∆a = 0.02.

vchikwasha Harare Institute of Technology


2 Numerical Analysis


Definition 1.2.4 If a∗ is an approximation to a, then δ = , is called the relative
|a|
error of the approximate number a∗ .

Definition 1.2.5 The limiting relative error δa of the approximation a∗ to a is any



number not less than the relative error of that number. For example, δ ≤ δa or < δa
|a|
or ∆ ≤ |a|δa .

Thus, the limiting absolute error of a number a∗ can be written as

∆a = |a|δa ≈ |a∗ |δa


So, a∗ − ∆a ≤ a ≤ a∗ + ∆a can be written as
a∗ − a∗ δa ≤ a ≤ a∗ + a∗ δa
⇒ a∗ (1 − δa ) ≤ a ≤ a∗ (1 + δa )
or a = a∗ (1 ± δa ).

Exercise 1.2.2 The weight of 1dm3 of water at 0o C is given as p = 999.847gf ±


0.001gf (gf = gram f orce). Determine the error of the result of weighing the water.

Solution 1.2.2 The limiting absolute error ∆p = 0.001gf and p ≤ 999.847 + 0.001 =
999.848gf .

⇒ the limiting relative error is,

0.001
δp = · 100 %
999.848

= 10−4 %

1.2.2 Basic Sources of Error

The source of error can be broken down into five groups:

1. Error of method - in formulating conditions that govern real life phenomena


using mathematical statements, one has to give allowance for errors.

2. Residual error - functions involved in mathematical formulae are sometimes


2
expressed in the form of infinite sequences or series, e.g. ex = 1 + x + x2! + . . ..
In practical situations we consider only a limited number of terms of a sequence
stopping at some term which is then taken to be the required solution. This kind
of termination gives rise to error.

3. Initial error - Some errors arise due to the use of approximate numerical pa-
rameters whose values are determined either experimentally or through infinite
processes. When performing computations with machines these errors are carried
into the final data.

vchikwasha Harare Institute of Technology


Numerical Analysis 3

4. Round-off error - if the decimal system of numeration or some other positional


system is used, there may be an infinite number of digits to the right of the
decimal point.

5. Operational error - calculations carried out using approximate numbers involve


errors from the initial data to the final result.

1.3 Solution of Non-linear Equations


Consider the equation

f (x) = 0 (1.1)

where f (x) is defined and continuous on some finite or infinite interval a < x < b.
If f (ξ) = 0, then ξ ∈ [a, b] is called a root of the equation.

Procedure for estimating the roots of (1.1)

1. Isolate the roots. This is a procedure to identify the smallest possible interval
[α, β] containing one and only one root of (1.1).

2. improve the values of the approximate roots, that is, refine the roots to the
required degree of accuracy

Process of isolation of roots

• identify an interval [α, β] with f (α)f (β) < 0. Thus, [α, β] contains at least one
root of the equation f (x) = 0.

• if f (ξ) = 0, then the root ξ will be unique if f 0 (x) exists and retains the same
sign throughout [a, b]. E.g. f 0 (x) > 0 (or f 0 (x) < 0) for α < ξ < β.

y
6
y = f (x)

f (β)

-
> x
α ξ β

f (α)

HIT223 - 2008 vchikwasha Harare Institute of Technology


4 Numerical Analysis

The signs of f (x) are determined at a number of intermediate points α1 , α2 , . . .. If at


point αk and αk+1 , f (αk )f (αk+1 ) < 0, then f (x) has a root in [αk , αk+1 ]
NB: An nth degree algebraic equation

a0 xn + a1 xn−1 + . . . + an = 0, (a0 6= 0) ai ∈ R, i = 1, 2 . . . , n

has at most n real roots. n + 1 sign changes on [α, β] assures us of the isolation.

Example 1.3.1 Isolate the roots of f (x) ≡ x3 − 6x + 2 = 0 on (−∞, ∞).

x −∞ -3 -1 0 1 3 +∞
f (x) - - + + - + +

f (x) has three roots in the interval (−3, −1), (0, 1), (1, 3).
0 0 2

We√can also make√ use of f (x) = 0, thus, f (x) = 3x − 6 = 0, x = ± 2. √ √ √ √
f ( 2) < 0, f (− 2) > 0, f (∞) > 0, f (−∞) < 0, thus f (x) has roots in (−∞, − 2), (− 2, 2), ( 2, ∞)

1.3.1 Graphical Method

f (x) = 0 can be replaced by φ(x) = ψ(x) where φ(x) and ψ(x) are simpler than f (x).
We consider the intersection of φ(x) and ψ(x).

Example 1.3.2 Solve 3x2 − ex = 0

Solution 1.3.1 Consider 3x2 = ex .


y = 3x2 y = ex
6

1p
-
ξ

ξ ≈ 0.9

1.3.2 Bisection Method

Consider f (x) = 0, where f is continuous on [a, b] and f (a)f (b) < 0, that is, f (a) and
f (b) have opposite signs.

vchikwasha Harare Institute of Technology


Numerical Analysis 5

Procedure

To find the root


 of f (x) = 0 in a+b
the interval [a, b], divide the interval into two subinter-
vals. If f a+b
2 = 0, then ξ = 2 is a root. If not, search for the root in the interval
a+b a+b
[a, 2 ] or [ 2 , b]. Let this new subinterval be [a1 , b1 ].
Bisect the new interval again, and make the same investigation of finding a root, and
so on.
This leads to either an exact root or an infinite sequence of nested intervals [a1 , b1 ], [a2 , b2 ],
. . . , [an , bn ] that contain ξ and is such that

f (an )f (bn ) < 0, n = 1, 2, . . .

and
b−a
bn − an =
2n
that is, if the interval [a, b] is subinterval into two, four, eight, etc, equal subintervals,
b−a b−a b−a
then the length of each subinterval is , 2 , 3 , etc.
2 2 2
Thus for 2n subintervals, the length of each is

b−a
= bn − an
2n

The end points a1 , a2 , . . . , an form a monotonic non-decreasing bounded sequence, and


b1 , b2 , . . . , bn form a monotonic non-increasing bounded sequence.
b−a
Thus, lim (bn − an ) = lim = 0. Hence, ξ = lim bn = lim an .
n→∞ n→∞ 2n n→∞ n→∞
As n → ∞, f (x) is continuous on [a, b], |f (ξ)|2 ≤ 0. This is possible only if f (ξ) = 0,
which means ξ is a root of f (x) = 0.

Example 1.3.3 Find the root of f (x) = x4 + 2x3 − x − 1 = 0 in the interval [0,1] using
the bisection method.

Solution 1.3.2 f (0) = −1 and f (1) = 1. ∴ f (x) has a root in [0,1].


ξ1 = 0+1
2 = 0.05 and f (0.5) = −1.1900, ∴ f (x) has a root in [0.5,1]. Continuing with
the iterations we obtain the following table

n an bn ξn f (ξn )
1 0.0000 1.0000 0.5000 -1.1900
2 0.05000 1.0000 0.7500 -0.5900
3 0.7500 1.0000 0.8750 0.0500
4 0.7500 0.8750 0.8125 -0.3040
5 0.81250 0.8750 0.8438 -0.1350
6 0.8438 0.8750 0.8594 -0.0430
7 0.8594 0.8750 0.8672 -0.0027
8 0.8672 0.8750 0.8711 -0.0267083

HIT223 - 2008 vchikwasha Harare Institute of Technology


6 Numerical Analysis

ξ7 = 0.8672 is a good approximation with error given by

Error = |ξ − ξ7 |
≤ |b7 − a7 |
= 0.8750 − 0.8594
= 0.0156
|b7 − a7 |
Absolute error = ≈ 0.0181 = 1.8 × 10−2 .
|a7 |

Exercise 1.3.1 Use the bisection method to find the smallest positive root of x3 − 2x +
1 = 0.

1.3.3 Newton-Raphson Method

Let f be a differentiable function, that is, the graph of f has a definite slope at each
point and hence a unique tangent.
At point (x0 , f (x0 )) on f , there is a tangent.
f (x)
r
6
(x0 , f (x0 ))

- x
a ξ x1 b = x0

y = `(x)

`(x) = f 0 (x0 )(x − x0 ) + f (x0 )(equation of tangent line). At b = x0 , f and ` agree.


Therefore , we take the zero of ` as an approximation to the zero of f .
The zero of `(x) is given by
f (x0 )
x1 = x0 − .
f 0 (x0 )
We repeat the process to produce a sequence of points:
f (x1 )
x2 = x1 −
f 0 (x0 )
f (x2 )
x3 = x2 − 0
f (x2 )
..
.

vchikwasha Harare Institute of Technology


Numerical Analysis 7

Until the sequence approaches a zero of f , ξ(say).

Interpreting Newton’s Method

Suppose x0 is the initial approximation to the root of f . Suppose a correction h is


added to x0 such that ξ = x0 + h gives a precise root, that is f (x0 + h) = 0.
Applying Taylor’s formula, we have

h2 00
f (x0 + h) = f (x0 ) + hf 0 (x0 ) + f (x0 ) + . . . = 0
2!
.
We can determine h by taking the first two terms.

f (x0 ) + hf 0 (x0 ) = 0
f (x0 )
⇒h = −
f 0 (x0 )
The new approximation to the root will be

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

the general formula for Newton’s method is given by

f (xn )
xn+1 = xn − , n = 0, 1, 2, . . . ,
f 0 (xn )

where x0 is the given first initial approximation.

Exercise 1.3.2 1. Use Newton’s method to find the negative root for x4 − 3x2 +
75x − 10000 = 0 within 10−3 within the interval [-15;-10].

2. Two of the zeros of x4 +2x3 −7x2 +3 are positive. Find them by Newton’s method,
correct to two significant figures.

1.4 Polynomial Interpolation


Interpolation is to connect discrete data points in a plausible way so that one can get
reasonable estimates of data points between the given points. The interpolation curve
goes through all data points. Numerically, we can say that interpolation is the tech-
nique of obtaining a value of a function for any intermediate value of the independent
variable if the values of the function corresponding to that variable are given in tabular
form. On the other hand, the technique of computing the value of the function outside
the range of given values is called extrapolation.

Example Given the table

HIT223 - 2008 vchikwasha Harare Institute of Technology


8 Numerical Analysis

x 0 4 8 12 16
f (x) 5 7 10 13 17
The technique of finding f (1), f (2), f (7), f (15) etc, is called interpolation, while finding
f (−1), f (17), etc is extrapolation.

For interpolation, the following assumptions are made:

• the given function should be either in increasing or decreasing order, without any
sudden jumps.

• the given function is a polynomial or can be represented as a polynomial with a


good degree of approximation.

Existence of interpolating polynomial

Suppose we have the following table of values


x x0 x1 ... xn
f (x) y0 y1 ... yn
and assume that the x0i s form a set of (n + 1) distinct points. The table represents
(n+1) points in the cartesian plane and we want to find a polynomial curve that passes
through all the points. A polynomial p for which

p(xi ) = yi , 0 ≤ i ≤ n

interpolate the table. The points xi are called the nodes.


Consider the simplest case when n = 0. The polynomial p of degree zero is

p(x) = y0 .

When n = 1, we have two points. A linear function can be fitted


 
y1 − y0
p(x) = y0 + (x − x0 ).
x1 − x0

Thus p(x0 ) = y0 and p(x1 ) = y1 are easily verified.

Example 1.4.1 Find the polynomial of least degree that interpolates the following ta-
ble.
x 2 5
y 6 18

Solution 1.4.1
 
18 − 6
p(x) = 6 + (x − 2)
5−2
= 76 + 4(x − 2)
= 4x − 2

vchikwasha Harare Institute of Technology


Numerical Analysis 9

To produce one more entry in the table we add another term p4. Assuming p(xi ) =
yi , 0 ≤ i ≤ k. We consider

p(x) + c(x − x0 )(x − x1 )(x − x2 ) . . . (x − xk )

where c is a constant to be determined.

Theorem 1.4.1 Given (n + 1) points x1 , x2 , . . . , x( n + 1), there is a unique polynomial


of degree m ≤ n that will interpolate through the (n + 1) points.
y
6

nth degree polynomial

y2 y3 y4 y5 y6 yn yn+1
y1
-
x
x1 x2 x3 x4 x5 x6 ... xn xn+1
2
P (x) = a0 + a1 x + a2 x + . . . + an xn

Difference tables are another way to write the nth order polynomial that passes through
(n + 1) points of the curve, (xi , f (xi )), i = 0, 1, 2, . . . , n.

1.4.1 Finite Differences

Let y = f (x) be a given function. Then,

∆y ≡ ∆f (x) = f (x + ∆x) − f (x)

where ∆x and ∆y are increments of x and y respectively, is called the first finite
difference of f .
Finite differences of higher order are denoted by

∆n y = ∆(∆n−1 y), n = 1, 2, 3 . . . .

Thus, ∆y = f (x + ∆x) − f (x)

∆2 y = ∆(∆y) = ∆[f (x + ∆x) − f (x)]


= ∆f (x + ∆x) − ∆f (x)
= f (x + ∆x + ∆x) − f (x + ∆x) − f (x + ∆x) + f (x)
= f (x + 2∆x) − 2f (x + ∆x) + f (x)

The three basic propeties of finite differences ∆ are:

HIT223 - 2008 vchikwasha Harare Institute of Technology


10 Numerical Analysis

1. ∆(u + v) = ∆u + ∆v.

2. ∆(cu) = c∆u. (where c is a constant)

3. ∆m (∆n y) = ∆m+n y.

for given functions u and v, and m and n being nonnegative integers.

Example 1.4.2 Construct the finite difference for the function P (x) = x2 , taking the
interval increment to be ∆x = 1.

Solution 1.4.2

∆P (x) = P (x + ∆x) − P (x)


= P (x + 1) − P (x)
= x2 + 2x
∆2 P (x) = P (x + 2) − 2P (x + 1) + P (x)
= x2 + 4x + 4 − 2x2 − 4x − 2 + x2
= 2

∆n P (x) = 0, for n > 2.

In general if Pn (x) = a0 xn + a1 xn−1 + . . . + an is an nth order polynomial, then

∆n Pn (x) = n!a0 hn
= constant, where h = ∆x

Differences Tables

Suppose y = f (x) is given at xi such that yi = f (xi ), where xi (i = 0, 1, 2, . . . , n) are


equidistant points. Setting

∆xi = xi+1 − xi = h = constant

The finite differences ∆y, ∆2 y, . . . are defined by

∆yi = yi+1 − yi (first finite difference).


2
∆ yi = yi+2 − 2yi+1 + yi
..
.

In general,

n(n−1)
∆n yi = yi+n − nyi+n−1 + 2 yi+n−2 − . . . + (−1)k n Ck y(i+n−k) + . . . + (−1)n yi

We can construct a forward finite differences table as follows:

vchikwasha Harare Institute of Technology


Numerical Analysis 11

x y ∆y ∆2 y ∆3 y ∆4 y
x0 y0
∆y0
x1 y1 ∆2 y0
∆y1 ∆ 3 y0
x2 y2 ∆2 y 1 ∆ 4 y0
∆y2 ∆3 y 1
..
x3 y3 ∆2 y 2 .
..
∆y3 .
.. ..
x4 y4 . .
.. .. .. .. .. ..
. . . . . .

1.4.2 Newton’s Forward Difference (for equally spaced points)

Let the function y = f (x) be given at the equally spaced points xi = x0 + ih (i =


0, 1, 2, . . . , n where h = xi+1 − xi .

Pn (x) = a0 + a1 (x − x0 ) + a2 (x − x0 )(x − x1 ) + . . .
+ an (x − x0 )(x − x1 ) . . . (x − xn−1 ) (1.2)

for appropriate constants a0 , a1 , . . . , an .


Since the x0i s are given, the problem is to determine coefficients ai .

Pn (x0 ) = y0 = a0
Pn (x1 ) = y1 = a0 + a(x1 − x0 ) = a0 + a1 h
y1 − y0 ∆y0
⇒ a1 = =
h h
Pn (x2 ) = y2 = a0 + a1 (x2 − x0 ) + a2 (x2 − x0 )(x2 − x1 )
⇒ y2 − y1 − 2(y1 − y0 ) = 2a2 h2
y2 − 2y1 + y0 ∆2 y0
∴ a2 = =
2h2 2h2
..
.
∆n y0
an =
n!hn
Substituting for ai (i = 0, 1, 2, . . . , n) in (1.2),
∆y0 ∆2 y0
Pn (x) = y0 + (x − x0 ) + (x − x0 )(x − x1 ) + . . . +
h 2!h2
n
∆ y0
+ (x − x0 )(x − x1 ) . . . (x − xn−1 ).
n!hn
Example 1.4.3 Construct Newton’s interpolation polynomial on [3.5;3.7] using the
spacing h = 0.05 for f (x) = ex given in the following table.

x 3.5 3.55 3.6 3.65 3.70


y 33.115 34.813 36.598 38.475 40.447

HIT223 - 2008 vchikwasha Harare Institute of Technology


12 Numerical Analysis

Solution 1.4.3 We first form a horizontal differences table:

x y ∆y ∆2 y ∆3 y ∆4 y
3.5 33.115 1.698 0.087 0.005 -0.002
3.55 34.813 1.785 0.092 0.003
3.6 36.598 1.887 0.95
3.65 38.475 1.972
3.7 40.447

1.698 0.087
P4 (x) = 33.115 + (x − 3.5) + (x − 3.5)(x − 3.55)
0.05 2 × 0.052
0.005
+ (x − 3.5)(x − 3.55)(x − 3.6)
6 × 0.053
0.002
− (x − 3.5)(x − 3.55)(x − 3.6)(x − 3.65).
24 × 0.054

Exercise 1.4.1 Construct an empirical formula for the function represented by the
following table.

x 0 1 2 3 4 5
y 5.2 8.0 10.4 12.4 14.0 15.2

1.4.3 Newton’s Divided Difference (for unequally spaced points)


y
6

y0 y1 y2 y3

- x
x0 x1 x2 x3 xn

As for Newton’s forward difference, the nth degree polynomial may be written as

y = a0 + a1 (x − x0 ) + a2 (x − x0 )(x − x1 ) + . . . + an (x − x0 )(x − x1 ) . . . (x − xn−1 )

vchikwasha Harare Institute of Technology


Numerical Analysis 13

Substituting for x at n + 1 points, we have

y0 = a0
y1 − y0 = a1 (x1 − x0 )
y1 − y0
⇒ a1 = , denoted y[x1 , x0 ]
x1 − x0
y2 − y0 − (x2 − x0 )(y1 − y0 )
a2 =
(x2 − x0 )(x2 − x1 )
y[x2 , x1 ] − y[x1 , x0 ]
= denoted y[x2 , x1 , x0 ]
x2 − x0
..
.
ak = y[xk , xk−1 , . . . , x0 ]
y[xk , xk−1 , . . . , x1 ] − y[xk−1 , xk−2 , . . . , x0 ]
=
xk − x0

The Newton’s divided difference polynomial can be written as

y(x) = y0 + (x − x0 )y[x1 , x0 ] + (x − x0 )(x − x1 )y[x2 , x1 , x0 ] + . . .


+ (x − x0 )(x − x1 ) . . . (x − xn−1 )y[xn , xn−1 , . . . , x0 ]

x y(x) First order Second order third order fourth order


divided diff. divided diff. divided diff. divided diff.
x0 y0
y[x1 , x0 ]
x1 y1 y[x2 , x1 , x0 ]
y[x2 , x1 ] y[x3 , x2 , x1 , x0 ]
x2 y2 y[x3 , x2 , x1 ] y[x4 , x3 , x2 , x1 , x0 ]
y[x3 , x2 ] y[x4 , x3 , x2 , x1 ]
x3 y3 y[x4 , x3 , x2 ]
y[x4 , x3 ]
x4 y4

1.4.4 Lagrange Interpolating Polynomial

Lagrange interpolating polynomial is for arbitrarily spaced points. Consider the con-
struction of a polynomial Ln (x) of degree not exceeding n having at specified points
x0 , x1 , . . . , xn the same value as the function y = f (x), that is,

Ln (xi ) = yi , (i = 0, 1, 2, . . . , n) where yi = f (xi )

HIT223 - 2008 vchikwasha Harare Institute of Technology


14 Numerical Analysis

y
6
y = f (x)


y = Ln (x)

- x
x0 x1 xn

First, construct a polynomial `i (x) such that



1, i = j
`i (x) = δij =
6 j
0, i =

δij is the Kronecker delta symbol.


The polynomial vanishes at n + 1 points: x0 , x1 , . . . , xi−1 , xi+1 , . . . , xn and thus has the
form

`i (x) = ci (x − x0 )(x − x1 )(x − x2 ) . . . (x − xi−1 )(x − xi+1 ) . . . (x − xn ) (1.3)

where ci is a constant coefficient. When x = xi , we have

`( xi ) = ci (xi − x0 )(xi − x1 ) . . . (xi − xi−1 )(xi − xi+1 ) . . . (xi − xn ) = 1


1
ci =
(xi − x0 )(xi − x1 ) . . . (xi − xi−1 )(xi − xi+1 ) . . . (xi − xn )
Substituting for ci in (1.3)
(x − x0 )(x − x1 )(x − x2 ) . . . (x − xi−1 )(x − xi+1 ) . . . (x − xn )
`i (x) =
(xi − x0 )(xi − x1 ) . . . (xi − xi−1 )(xi − xi+1 ) . . . (xi − xn )
(x − xj )
= Πnj=0
(xi − xj )

For the general case, we need to find a polynomial Ln (x) that satisfies the conditions

Ln (xi ) = yi
Xn
Ln (x) = `i (x)yi
i=0

The degree of Ln (x) is not greater than n, so we have


n
X
Ln (xj ) = `i (xj )yi
i=0
= `j (xj )yj
= yj (j = 0, 1, 2, . . . , n).

vchikwasha Harare Institute of Technology


Numerical Analysis 15

Thus,

n
X (x − x0 )(x − x1 )(x − x2 ) . . . (x − xi−1 )(x − xi+1 ) . . . (x − xn )
Ln (x) = f (xi )
(xi − x0 )(xi − x1 ) . . . (xi − xi−1 )(xi − xi+1 ) . . . (xi − xn )
i=0

i = 0, 1, 2, . . . , n

The nth Lagrange interpolating polynomial.

Example 1.4.4 Consider the table of values of y = f (x).

x 321.0 322.8 324.2 325.0


y 2.50651 2.50893 2.51081 2.51188

Estimate f (324.7).

Solution 1.4.4
3
X x − xj
L3 (x) = f (xi )`i (x) , with `i (x) = Π3j=0,j6=i
xi − xj
i=0

(x − 322.8)(x − 324.2)(x − 325.0)


`0 (x) =
(321.0 − 322.8)(321.0 − 324.2)(321.0 − 325.0)
(x − 321.0)(x − 324.2)(x − 325.0)
`1 (x) =
(322.8 − 321.0)(322.8 − 324.2)(322.8 − 325.0)
(x − 321.0)(x − 322.8)(x − 325.0)
`2 (x) =
(324.2 − 321.0)(324.2 − 322.8)(324.2 − 325.0)
(x − 321.0)(x − 322.8)(x − 324.2)
`3 (x) =
(325.0 − 321.0)(325.0 − 322.8)(325.0 − 324.2)

∴ L3 (x) = `0 (x)f (x0 ) + `1 (x)f (x1 ) + `2 (x)f (x2 ) + `3 (x)f (x3 )

⇒ f (324.7) ≈ 2.52397

Exercise 1.4.2 Given the Gaussian function


2 /5
g(x) = e−x

and the following table of values:

x -5 -4 -3 -2 -1 0
f (x) 0.0067379 0.0183156 0.0497871 0.1353353 0.3678794 1

Construct the Lagrange interpolating polynomial of degree 3 and find f (−2.5) and f (2.5)
and compare your value to the exact values.

HIT223 - 2008 vchikwasha Harare Institute of Technology


16 Numerical Analysis

1.4.5 Approximation by Spline Functions

A spline function is a function that consists of polynomial pieces joined together with
certain smoothness conditions.
A simple example is polygonal function (or spline of degree 1) whose pieces form linear
polynomials joined together for continuity.
pr
s0 prhh. h
.. sn−2
s1 r s2 r s3 s4 hr
h pq
r r

- x
t0 t1 t2 t3 t4 t5 ... tn−1

The points t0 , t1 , . . . , tn−1 are called knots.




 S0 (x) , x ∈ [t0 , t1 ]
 S1 (x) , x ∈ [t1 , t2 ]



S(x) = S 2 (x) , x ∈ [t2 , t3 ]
 .
.. ..
.




Sn−1 (x) , x ∈ [tn−2 , tn−1 ]

where Si (x) = ai x + bi . S(x) is piecewise linear.

Properties of S

1. The domain of S is an interval [a, b].

2. S is continuous on [a, b].

3. There is a partitioning of the interval a = t0 < t1 < . . . < tn−1 = b such that S
is a linear polynomial on each subinterval [ti , ti−1 ]

Example 1.4.5 Show that G(x) is not a spline function of first degree.

 x, x ∈ [−1, 0]
G(x) = 1 − x , x ∈ [0, 1]
2x − 2 , x ∈ [1, 2]

Solution 1.4.5

lim x = lim (1 − x) = 1
x→0+ x→0
lim x = lim x = 0
x→0− x→0
Thus lim G(x) 6= lim G(x)
x→0+ x→0−

Hence G(x) is discontinuous at x = 0.

vchikwasha Harare Institute of Technology


Numerical Analysis 17

Second Degree Splines

A function S(x) is spline of degree 2 if S is a piecewise quadratic polynomial such that


S and S 0 are continuous.

Example 1.4.6 Given that



 x, x≤0
G(x) = −x2 , 0 ≤ x ≤ 1
1 − 2x , x ≥ 1

Determine whether or not G(x) is a quadratic spline.

Solution 1.4.6

lim G(x) = lim x2 = 0


x→0− x→0−

lim G(x) = lim −x2 = 0


x→0+ x→0+

lim G(x) = lim (−x2 ) = −1


x→1− x→1−

lim G(x) = lim 1 − 2x2 = −1


x→1+ x→1+

lim G0 (x) = lim 2x = 0


x→0− x→0−

lim G0 (x) = lim −2x = 0


x→0+ x→0+

lim G0 (x) = lim −2x = −2


x→1− x→1−

lim G0 (x) = lim −2 = −2


x→1+ x→1+

Since G(x) and G0 (x) are continuous, G(x) is a quadratic spline.

The equation for the interpolating quadratic spline, Q(x) is given by




 Q0 (x) , t0 ≤ t ≤ t1
 Q1 (x) , t1 ≤ t ≤ t2

Q(x) = .. ..


 . .
Qn−1 (x) , tn−1 ≤ t ≤ tn

Zi+1 − Zi
Qi (x) = (x − ti )2 + Zi (x − ti ) + yi
2(ti+1 − ti )
where Zi = Q0 (ti )

HIT223 - 2008 vchikwasha Harare Institute of Technology


18 Numerical Analysis

Exercise 1.4.3 Determine whether the following are quadratic splines.

 0.1x2 ,

0≤x≤1
1. S(x) =
9.3x2 − 18.4x + 9.2 , 1 ≤ x ≤ 1.3


 x , −∞ < x < 1




2. S(x) = x2 , 1 ≤ x ≤ 2




4, 2 ≤ x ≤ ∞

1.5 Numerical Differentiation


Numerical differentiation is the process of calculating the value of the derivative of a
function y = f (x), at some assigned value of x from a given set of values (xi , yi ).
The derivation of formulae for numerical differentiation hinges on the Taylor series
expansion of f (x + h) and f (x − h), h > 0.
h2 00 h3
f (x + h) = f (x) + hf 0 (x) + f (x) + f 000 (x) + . . . (1.4)
2! 3!
and
h2 00 h3
f (x − h) = f (x) − hf 0 (x) + f (x) − f 000 (x) + . . . (1.5)
2! 3!

1.5.1 Two Point Forward Difference Formula

If we truncate (1.4) at the second derivative, we get


h2 00
f (x + h) = f (x) + hf 0 (x) + f (c1 )
2!
for some c1 ∈ [x, x + h].
f (x + h) − f (x)
⇒ f 0 (x) = + ET (h)
h
where ET (h) is the truncation error and is given by
h
ET (h) = − f 00 (c1 )
2

1.5.2 Two Point Backward Difference Formula

From (1.5)
f (x) − f (x − h)
f 0 (x) = + ET (h)
h
where
h
ET (h) = − f 00 (c2 )
2
for some c2 ∈ [x − h, x].

vchikwasha Harare Institute of Technology


Numerical Analysis 19

1.5.3 Three Point Central Difference Formula

Subtracting (1.5) from (1.4)

2h3 000
f (x + h) − f (x − h) = 2hf 0 (x) + f (x) + . . .
3!
f (x + h) − f (x − h)
⇒ f 0 (x) = + ET (h)
2h
h2 000
where ET (h) = f (c) for some c ∈ [x − h, x + h].
6

Example 1.5.1 Let f (x) be given by the table below

x 1.30 1.40 1.45 1.50 1.55 1.60 1.7


f (x) 4.77009 5.67728 6.18152 6.72253 7.30278 7.92485 9.30571

Find an approximation to f 0 (1.50) using the two-point forward difference formula with
h = 0.05.

Solution 1.5.1
f (x + h) − f (x)
f 0 (x) =
h
f (1.50 + 0.05) − f (1.50)
⇒ f 0 (1.50) ≈
0.05
f (1.55) − f (1.50)
=
0.05
7.30278 − 6.72253
=
0.05
= 11.6050

With error |e| = |11.2042 − 11.6050| = 0.4008

Exercise 1.5.1 Use the three point central difference formula with h = 0.1 to estimate
f 0 (1.50) using the table above.

1.5.4 Three Point Formula for First Order Derivative by the Lagrange
Polynomial

Consider an approximation to f (x) through x0 , x1 = x0 + h, x2 = x0 + 2h by the


Lagrange polynomial P2 (x).

(x − x1 )(x − x2 ) (x − x0 )(x − x2 ) (x − x0 )(x − x1 )


P2 (x) = f0 + f1 + f2
(x0 − x1 )(x0 − x2 ) (x1 − x0 )(x1 − x2 ) (x2 − x0 )(x2 − x1 )

where fk = f (xk ).
2x − x1 − x2 2x − x0 − x2 2x − x0 − x1
f 0 (x) = P 0 (x) = 2
f0 + 2
f1 + f2 .
2h h 2h2

HIT223 - 2008 vchikwasha Harare Institute of Technology


20 Numerical Analysis

Estimating at x0 , x1 , x2 we obtain three point formulae:


1
f 0 (x) ≈ (−3f0 + 4f1 − f2 ) − forward difference formula
2h
1
f 0 (x1 ) ≈ (−f0 + f2 ) − central difference formula
2h
1
f 0 (x2 ) ≈ (f0 − 4f1 + 3f2 ) − backward difference formula
2h

1.5.5 Second Order Derivatives

h2 00 h3 000 h2 (iv)
f (x + h) = f (x) + hf 0 (x) + f (x) + f (x) + f (x) + . . . (1.6)
2 3! 4!
h2 h3 000 h2 (iv)
f (x − h) = f (x) − hf 0 (x) + f 00 (x) − f (x) + f (x) + . . . (1.7)
2 3! 4!
Adding (1.6) and (1.7) eliminates terms with odd order derivatives
2h2 00 2h4 (iv)
f (x + h) + f (x − h) = 2f (x) + f (x) + f (x) + . . .
2 24
Solving for f 00 (x) yields
f (x + h) − 2f (x) + f (x − h)
f 00 (x) = + ET (f, h) − central difference formula
h2
h2 (iv)
where ET (f, h) = − f (c) where c ∈ [x − h, x + h].
12
Example 1.5.2 Given f (x) = xex , use the central difference formula to approximate
f 00 (0.5) with h = 0.1, 0.01, 0.001. Compare the calculated value with the true value.

Solution 1.5.2
f (x + h) − 2f (x) + f (x − h)
f 00 (x) =
h2
for h = 0.01
f (0.51) − 2f (0.5) + f (0.49)
f 00 (0.5) =
0.0001
≈ 4.121864950

The true value of f 00 (0.5) = 2.5e0.5 ≈ 4.121803177. ⇒ |e| ≈ 0.000061773.

1.6 Numerical Integration


The process of evaluating definite integrals from a set of tabulated values of the inte-
grand f (x) is called numerical integration.
The general form of numerical integration of a function f (x) over some interval [a, b]
is a weighted sum of the function values at a finite number (N + 1) of sample points
(nodes), referred to as quadrature:

vchikwasha Harare Institute of Technology


Numerical Analysis 21

1.6.1 The Trapezoidal Rule


Z b
Let I = f (x) dx
a
y
6

P
Q

y0 y1 y2 yi yi+1 yn−1 yn

M N
- x
a = x0 x1 x2 xi xi+1 xn−1 b = xn

To derive the Trapezoidal rule, divide the area represented by I into a number of thin
strips.
b−a
Let h = , be the interval length, n number of strips.
n
Provided h is small, area due to the ith strip is approximated by area of trapezium
M P QN .
Let xr = a + rh, fr = f (xr ) = yr
Total area under the curve is approximated the sum of areas of the n trapezia, i.e.

h h h
I ≈ (f0 + f1 ) + (f1 + f2 ) + . . . + (fn−1 + fn )
2 2 2
1 1
= h( (f0 + f1 + f2 + . . . + fn−1 + fn )
2 2
Xn
00
= h fr , where ”means first and last term are halved.
r=0

1.7 Numerical Solutions to Ordinary Differential Equa-


tions

1.7.1 Taylor Series Method

Consider the initial value problem (IVP)


y 0 = f (x, y), y(a) = y0 , over [a, b]
Subdivide [a, b] into n subintervals and select the mesh points
xk+1 = xk + h, k = 0, 1, 2, . . . , n − 1

HIT223 - 2008 vchikwasha Harare Institute of Technology


22 Numerical Analysis

b−a
where h = , x0 = a , xn = b.
n
Assuming y has (n + 1) continuous derivatives in [xk , xk+1 ], k = 0, 1, 2, . . . , n − 1, by
Taylor’s theorem
y(xk+1 ) = y(xk + h)
h2 00 hn (n) h(n+1) (n+1)
= y(xk ) + hy 0 (xk ) + y (xk ) + . . . + y (xk ) + y (ck )
2 n! (n + 1)!
for some ck ∈ [xk , xk+1 ].
For h very small

h2 00 hn (n)
y(xk + h) = y(xk ) + hy 0 (xk ) + 2! y (xk ) + ... + n! y (xk )
Taylor’s formula of order n.

Example 1.7.1 Use Taylor’s method of order 4 to solve


y 0 = y + ex on [0, 2] with y(0) = 1, and h = 1

Solution 1.7.1
y 0 = y + y + ex
y 00 = y 0 + ex
= y + 2ex
y 000 = y + 3ex
y (iv) = y + 4ex
The Taylor series order 4 is given by
h2 00 h3 000 h4 iv
yk+1 = yk + hyk0 + y + y k + yk
2! k 3! 4!
h 2 h3 h4
= yk + h(yk + exk ) + (yk + 2exk ) + (yk + 3exk ) + (yk + 4exk )
2   6  24
h2 h3 h4 h2 h3

= 1+h+ + + yk + h 1 + h + + exk
2 6 24 2 6
For h = 1
yk+1 = 2.70833yk + 2.66667exk
with y0 = y(0) = 1
y1 = 2.70833 + 2.66667 = 5.37500
y2 = 14.55727 + 7.24876 = 21.80603
The exact solution of y 0 = y + ex is
y = (1 + x)ex
∴ y1 = 2e2
= 5.43656
|e| = 0.06156

vchikwasha Harare Institute of Technology


Numerical Analysis 23

1.7.2 Euler’s Method

With n = 1, Taylor’s series gives

y(xk+1 ) = y(xk ) + hy 0 (xk )

We know that
y 0 (x) = f (x, y(x))
y 0 (xk ) ≈ f (xk , yk )
Thus,
yk+1 = yk + hf (xk , yk ) , k = 0, 1, 2, . . . , n − 1

2xy
Example 1.7.2 Solve y 0 = , y(1) = 2 in [1, 1.3] using Euler’s method with
1 + x2
h = 0.1.

2xy
Solution 1.7.2 f (x, y) = .
1 + x2
Mesh points: x0 = 1, x1 = x0 + h = 1.1, x2 = 1.2, x3 = 1.3

y0 = y(x0 )
= y(1) = 2

y1 = y0 + hf (x0 , y0 )
= 2 + 0.1f (1, 2)
2×1×2
= 2 + 0.1 ×
1 + 12
= 2.2

y2 = y1 + hf (x1 , y1 )
= 2 + 0.1f (1.1, 2.2)
= 2.419

y3 = y2 + f (x2 , y2 )
2 × 1.2 × 2.419
= 2.419 + 0.1 ×
1 + (1.2)2
= 2.65693

Exercise 1.7.1 Solve y 0 = y + ex on [0, 2] with y(0) = 1, h = 1 using Euler’s method.

1.7.3 Runge-Kutta’s Methods

HIT223 - 2008 vchikwasha Harare Institute of Technology

You might also like