0% found this document useful (0 votes)
32 views26 pages

Numerical Methods 1

This document discusses numerical analysis techniques for solving non-linear equations and polynomial interpolation. It introduces methods for estimating roots of non-linear equations graphically and through bisection and Newton-Raphson methods. It also covers polynomial interpolation using finite differences, Newton's divided differences, and Lagrange polynomials. The document provides examples and definitions for absolute and relative errors in numerical computations.

Uploaded by

jaydean mutenga
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)
32 views26 pages

Numerical Methods 1

This document discusses numerical analysis techniques for solving non-linear equations and polynomial interpolation. It introduces methods for estimating roots of non-linear equations graphically and through bisection and Newton-Raphson methods. It also covers polynomial interpolation using finite differences, Newton's divided differences, and Lagrange polynomials. The document provides examples and definitions for absolute and relative errors in numerical computations.

Uploaded by

jaydean mutenga
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/ 26

HARARE INSTITUTE OF TECHNOLOGY

March 13, 2015

SCHOOL OF INDUSTRIAL SCIENCES AND


TECHNOLOGY
CPSE, EE, IME

Engineering Maths 3: Numerical Analysis

Z. S. Makumbe, V. Chikwasha

Contents
1 Introduction 2
2 Errors in Numerical Computation 2
2.1 Absolute and Relative Errors . . . . . . . . . . . . . . . . . . . . 2
2.2 Basic Sources of Error . . . . . . . . . . . . . . . . . . . . . . . . 4

3 Solution of Non-linear Equations 5


3.0.1 Procedure for estimating the roots of (1) . . . . . . . . . . 5
3.0.2 Process of isolation of roots . . . . . . . . . . . . . . . . . 5
3.1 Graphical Method . . . . . . . . . . . . . . . . . . . . . . . . . . 6
3.2 Bisection Method . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
3.2.1 Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
3.3 Newton-Raphson Method . . . . . . . . . . . . . . . . . . . . . . 8
3.3.1 Interpreting Newton's Method . . . . . . . . . . . . . . . 9

4 Polynomial Interpolation 10
4.0.2 For interpolation, the following assumptions are made: . . 10
4.0.3 Existence of interpolating polynomial . . . . . . . . . . . 10
4.1 Finite Dierences . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
4.1.1 Dierences Tables . . . . . . . . . . . . . . . . . . . . . . 13
4.2 Newton's Forward Dierence (for equally spaced points) . . . . . 13
4.3 Newton's Divided Dierence (for unequally spaced points) . . . . 15

1
4.4 Lagrange Interpolating Polynomial . . . . . . . . . . . . . . . . . 16
4.5 Approximation by Spline Functions . . . . . . . . . . . . . . . . . 18
4.5.1 Properties of S . . . . . . . . . . . . . . . . . . . . . . . . 19
4.5.2 Second Degree Splines . . . . . . . . . . . . . . . . . . . . 20

5 Numerical Dierentiation 21
5.1 Two Point Forward Dierence Formula . . . . . . . . . . . . . . . 21
5.2 Two Point Backward Dierence Formula . . . . . . . . . . . . . . 21
5.3 Three Point Central Dierence Formula . . . . . . . . . . . . . . 22
5.4 Three Point Formula for First Order Derivative by the Lagrange
Polynomial . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
5.5 Second Order Derivatives . . . . . . . . . . . . . . . . . . . . . . 23

6 Numerical Integration 24
6.1 The Trapezoidal Rule . . . . . . . . . . . . . . . . . . . . . . . . 24

7 Numerical Solutions to Ordinary Dierential Equations 25


7.1 Taylor Series Method . . . . . . . . . . . . . . . . . . . . . . . . . 25

1 Introduction
2 Errors in Numerical Computation
2.1 Absolute and Relative Errors
Denition
A number a∗ is said to be an approximate number to the exact number a,
if it diers 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 approxi-
mation.
If a∗ is an approximate value of a, we write a∗ ≈ a.

Denition
The dierence 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∗ |.

2
Denition
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 approx-
imation of a

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

Solution:

∆ = |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.

Denition
If a∗ is an approximation to a, then


δ=
|a|

is called the relative error of the approximate number a∗ .

Denition
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|

3
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 ).
Example
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:
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 %

2.2 Basic Sources of Error


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

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


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

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


times expressed in the form of innite sequences or series, e.g. ex =
2
x
1+x+ 2! + . . ..
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
parameters whose values are determined either experimentally or through
innite processes. When performing computations with machines these
errors are carried into the nal data.

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


positional system is used, there may be an innite 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 nal result.

4
3 Solution of Non-linear Equations
Consider the equation

f (x) = 0 (1)

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

3.0.1 Procedure for estimating the roots of (1)


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

2. Improve the values of the approximate roots, that is, rene the roots to
the required degree of accuracy

3.0.2 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 (x) > 0 (or f 0 (x) < 0) for α < ξ < β .
0

y
6
y = f (x)

f (β)

-
> x
α ξ β

f (α)

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 n
th
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.

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

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

f (x) (−3, −1), (0, 1), (1, 3).


has three roots in the interval

0 0 2
We can also make use off (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, ∞)

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:
Solve 3x2 − ex = 0

Solution:
Consider 3x2 = ex . y = ex
y = 3x2
6

1 p
-
ξ

ξ ≈ 0.9

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.

6
3.2.1 Procedure
To nd the root of f (x)
 = 0 in the interval [a, b], divide the interval into two
subintervals. If f a+b2 = 0, then ξ =
a+b
2 is a root. If not, search for the root
in the interval [a, a+b a+b
2 ] or [ 2 , b]. Let this new subinterval be [a1 , b1 ].
Bisect the new interval again, and make the same investigation of nding a
root, and so on.
This leads to either an exact root or an innite 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 subin-
tervals, then the length of each subinterval is

b−a b−a b−a


, 2 , 3
2 2 2
, etc.
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 se-
quence, and b1 , b2 , . . . , bn form a monotonic non-increasing bounded sequence.
Thus, limn→∞ (bn − an ) = limn→∞ b−a 2n = 0. Hence,

ξ = lim bn = lim an
n→∞ n→∞

.
Asn → ∞, 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:
Find the root of f (x) = x4 + 2x3 − x − 1 = 0 in the interval [0,1] using the
bisection method.

Solution:
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]. Contin-
uing with the iterations we obtain the following table

7
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

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

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

Excercise:
Use the bisection method to nd the smallest positive root of x3 − 2x + 1 = 0.

3.3 Newton-Raphson Method


Let f be a dierentiable function, that is, the graph of f has a denite 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)

8
`(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 )
.
.
.

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

3.3.1 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 rst 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, . . . ,unexpected00 inmathunexpected00 inmath
f 0 (xn )

where x0 is the given rst initial approximation.

9
Excercise:
1. Use Newton's method to nd the negative root for x4 −3x2 +75x−10000 =
−3
0 within 10 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 signicant gures.

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 inter-
polation curve goes through all data points. Numerically, we can say that inter-
polation is the technique 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
x 0 4 8 12 16
f (x)5 7 10 13 17
The technique of nding f (1), f (2), f (7), f (15) etc, is called interpolation,
while nding f (−1), f (17), etc is extrapolation.

4.0.2 For interpolation, the following assumptions are made:


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

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


with a good degree of approximation.

4.0.3 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 nd 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 .

10
When n = 1, we have two points. A linear function can be tted
 
y1 − y0
p(x) = y0 + (x − x0 ).
x1 − x0
Thus p(x0 ) = y0 and p(x1 ) = y1 are easily veried.

Example:
Find the polynomial of least degree that interpolates the following table.
x 2 5
y 6 18

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

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
Given (n + 1) points x1 , x2 , . . . , x(n+1) , there is a unique polynomial of degree
m≤n that will interpolate through the
y (n + 1) points.

nth degree polynomial

y3 y4 y5 y6 yn yn+1
y1 y2

-
x
x1 x2 x3 x4 x5 x6 ... xn xn+1
2 n
P (x) = a0 + a1 x + a2 x + . . . + an x

11
Dierence 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.

4.1 Finite Dierences


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 rst nite
dierence of f .
Finite dierences 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 nite dierences ∆ are:

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:
Construct the nite dierence for the function P (x) = x2 , taking the interval
increment to be ∆x = 1.
Solutio

∆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.

12
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

4.1.1 Dierences 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 nite dierences ∆y, ∆2 y, . . . are dened by

∆yi = yi+1 − yi (rst nite dierence).


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

In general,

n(n − 1)
∆n yi = yi+n − nyi+n−1 + yi+n−2 − . . . + (−1)k n Ck y(i+n−k) + . . . + (−1)n yi unexpected00 inmathunex
2
We can construct a forward nite dierences table as follows:

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

4.2 Newton's Forward Dierence (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 ) (2)

13
for appropriate constants a0 , a1 , . . . , an .
Since the x0i s are given, the problem is to determine coecients 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 = 2
=
2h 2h2
.
.
.
∆n y 0
an =
n!hn
Substituting for ai (i = 0, 1, 2, . . . , n) in (2),

∆y0 ∆2 y 0
Pn (x) = y0 + (x − x0 ) + (x − x0 )(x − x1 ) + . . . +
h 2!h2
∆n y 0
+ (x − x0 )(x − x1 ) . . . (x − xn−1 ).
n!hn

Example:
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

SOLUTION:
We rst form a horizontal dierences 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

14
Excercise:
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

4.3 Newton's Divided Dierence (for unequally spaced


points)
y
6

y0 y1 y2 y3

- x
x0 x1 x2 x3 xn

As for Newton's forward dierence, the nth degree polynomial may be writ-
ten as

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

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

15
The Newton's divided dierence 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 di. divided di. divided di. divided di.
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

4.4 Lagrange Interpolating Polynomial


Lagrange interpolating polynomial is for arbitrarily spaced points. Consider the
construction of a polynomial Ln (x) of degree not exceeding n having at specied
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 )


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 =
0, i 6= j

δij is the Kronecker delta symbol.

16
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 ) (3)

where ci is a constant coecient. 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 (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 nd a polynomial Ln (x) that satises 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).
Thus,

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

i = 0, 1, 2, . . . , n
The nth Lagrange interpolating polynomial.

Excercise:
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).

17
Solution:

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

(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

Excercise:
Given the Gaussian function

2
g(x) = e−x /5

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 nd f (−2.5)


and f (2.5) and compare your value to the exact values.

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.

18
pr
s0 s2 s4 r h. . .
ph sn−2
s1 r r s3 h 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 ]
S (x) , x ∈ [t1 , t2 ]

1



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.

4.5.1 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 ]

Excercise:
Show that G(x) is not a spline function of rst degree.


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

Solution:
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.

19
4.5.2 Second Degree Splines
A function S(x) is spline of degree 2 if S is a piecewise quadratic polynomial
such that S and S0 are continuous.

Example:
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:
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 )

20
Excercise:
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≤∞

5 Numerical Dierentiation
Numerical dierentiation 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 dierentiation 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) + . . . (4)
2! 3!
and
h2 00 h3
f (x − h) = f (x) − hf 0 (x) + f (x) − f 000 (x) + . . . (5)
2! 3!

5.1 Two Point Forward Dierence Formula


If we truncate (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

5.2 Two Point Backward Dierence Formula


From (5)
f (x) − f (x − h)
f 0 (x) = + ET (h)
h

21
where
h
ET (h) = − f 00 (c2 )
2
for some c2 ∈ [x − h, x].

5.3 Three Point Central Dierence Formula


Subtracting (5) from (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
where
h2 000
ET (h) = f (c)
6
for some c ∈ [x − h, x + h]

Example:
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 dierence


formula with h = 0.05.

Solution:
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

Excercise:
Use the three point central dierence formula with h = 0.1 to estimate f 0 (1.50)
using the table above.

22
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) = f0 + f1 + f2 .
2h2 h2 2h2
Estimating at x0 , x1 , x2 we obtain three point formulae:

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

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) + . . . (6)
2 3! 4!
h2 h3 000 h2 (iv)
f (x − h) = f (x) − hf 0 (x) + f 00 (x) − f (x) + f (x) + . . . (7)
2 3! 4!
Adding (6) and (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 dierence formula
h2
where
h2 (iv)
ET (f, h) = − f (c)
12
where c ∈ [x − h, x + h].

Example:
Given f (x) = xex , use the central dierence formula to approximate f 00 (0.5)
with h = 0.1, 0.01, 0.001. Compare the calculated value with the true value.

23
Solution:
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.

6 Numerical Integration
The process of evaluating denite integrals from a set of tabulated values of the
integrand f (x) is called numerical integration.
The general form of numerical integration of a function f (x) over some in-
terval [a, b] is a weighted sum of the function values at a nite number (N + 1)
of sample points (nodes), referred to as quadrature

6.1 The Trapezoidal Rule


Let
 b
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 num-
ber of thin strips.
Let
b−a
h=
n

24
n number of strips.
, be the interval length,
h is small, area due to the ith
Provided 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 rst and last term are halved.
r=0

7 Numerical Solutions to Ordinary Dierential


Equations
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
where
b−a
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 ) + y (xk ) + . . . + y (xk )
2! n!
Example:
Use Taylor's method of order 4 to solve
y 0 = y + ex on [0, 2] with y(0) = 1, and h=1

25
Solution:

y0 = y + y + ex
y 00 = y 0 + ex
= y + 2ex
000
y = y + 3ex
y (iv) = y + 4ex

The Taylor series order 4 is given by

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

26

You might also like