Math 421 422-Part 1
Math 421 422-Part 1
Numerical Analysis
Numerical methods were developed to help us to solve
problems which we either can not solve at all analytically (
i.e/ by some kind of formula) or where the analytical
solution is so complicated that it is virtually unusable
Numerical analysis : is concerned with the theory of such
methods and the analysis of their convergence and
accuracy properties.
Examples of problems
ax bx cx dx ex f 0
5 4 3 2
But it was proved by A bell in 1823 that no such formula can exist
2) Solve
x
e Sin Tx.
Analytically an infinity of roots which approach the positive integers
as x
3) Solve the differential equation
dy
dx
x Sin y
4) Evaluate 1 dx
0
1 x 5
2 1.4142
When we accept an approximation to a real number we are
introducing rounding error.
Definition:
A number y is said to be an approximation to another number x
which is correct to K p.d if.
k
x y 1 10
2
Example:
How accurate an approximation to is 22 7 ?
Solution:
3.14159265....
22 3.14285714....
7
Hence 22 7 0.0012....
And since 1 1
2 3
0.005 10 0.0012 10 0.0005
2 2
We see that the approximation is correct to only 2 d.p.
to 2 d . p is 3.14.error is then 0.0015
3.15 gires an error 0.0084...(worse )
to 3d . p is 3.142error is then 0.0004
3.141 gives an error 0.00059(worse )
1 , 1 , 1 ,..., 1 to 6d . p
11 12 13 19
And then add up =0.618771
= 0.619 to 3 d.p.
2) work out each value 1 , 1 , 1 to 3 p.d and then add up =
11 12 19
0.620
Value correct to 6 d.p is 0.618771
Value after rounding each term correct to 3 d.p and them add up is
0.620
Hence error = 0.0012
Each of the 9th term in the sum is correct to 3 d.p ie/ its error
( rounding) lies between
1 3 3
10 and 1 10
2 2
So, the accumulated rounding error can not exceed
1
9 103 0.0045
2 1
In fact the accumulated rounding error is only about of this
4
caused by cancellation of positive and negative errors.
19
1
0.614
n 11 n
0.623
If we had added N such numbers the worst possible A.R.E would
N 10 3
be 2 from probability theory it is known that if rounding error
are independent then A.R.E is proportional to N
If we carry out a computation involving multiplications or divisions on
numbers which have been rounded to K d.p we can say very little about
the probable A.R.E.
Example:
From the product (3.90+1.22) (5.46+3.59)
(i) Directly :
(ii) As the sum of the four products rounding all numbers
to 2 d.p at each stage?
Solution:
Home work No 1.
Q: The fractions 19 ,117 , 721
6 37 228
10 3.16227766 to 8d . p
find the accuracy of these approximation?
Solution:
(i ) 10 3.16227766
19 3.16666666
6
10 19 0.00438900
6
1 10 3 0.00438900 1 10 2
2 2
Hence it is correct to 2d.p
(ii )117 3.16216216
37
10 117 0.00011550
37
1 10 4 0.00011550 1 10 3
2 2
Hence it is correct to 2d.p
2) Human errors:
In hand work or desk machine work human errors are all too
common
The most frequent types are:
a) Transposition of 2 digits e.g/writing 17236 instead of
17326.
b) Repetition of the wrong digit e.g/writing 39967 instead of
39667
c) Forgetting a negative sign infront of a number.
3) Empirical errors:
Measurement of data depends on the instrument.
Hence there is a limited accuracy.
One should not aim for impossible accuracy.
4) Truncation errors:
This occurs if we have to sum an infinite series. e.g/
1) S 1
n 1 n4
we must approximate.
This by stopping after say ( N-terms) thus taking
N
1
S n 1 n4
the sum of the series we have ignored
1
n N 1 n4 Is then the truncation error.
2) Another case if
I f ( x) dx
0
N
0
f ( x) dx In which
N
f ( x ) dx
S n 1
an and we stop after N terms.
N
i.e/ S an
n 1
a
every term of n
is likely to have its own rounding
error adding N such terms produces accumulated
Rounding error (ARE).
The part ignored
n N 1
an
f ( x) `
e.g / log e x the error would be
x
f f f
1 2 ... n
x1 x2 xn
Continuity:
A function f (x) from is discontinuous at a if
f ( x) f (a) as x a
f can be discontinuous in three Different, ways
f ( x h) f ( a )
lim ha
h
provided this limit exists.
Example:
Suppose x 3 1 , y 5 2 1 0.2 , 2 0.3
y x
Find bounds on the value of ?
y x
Solution:
(i ) y x 5 2 3 1
2 2 1
0.2 1 0.2
0.3 2 0.3
N
xn
Suppose we take n 1 n4
as our approximation then
x n ( 1 )n 1
N 1
1 N 2
n N 1 n 4
n N 1
2
n4
2
N 1 4
2
N 2 4
........
2
1
N 1
1 N 1
4
1 N 1
4
1
N 14
2 N 2 2 N 3
N 1
1
1 12 12
T .E 2
1 ....
N 14 2
2 3
2
1
N
1 1 1 1
N 1 2 2 2 2 3 2 4 ....
4
2
1
N
.
N 1
4
T .E 1 10 6
2
1
2
N
1
10 6
5 10 7
N 1 4
2
when N 9
1 2
N
2 10 7 5 10 7
N 14
9 terms required try 8.7
N log10 1 4 log10 ( N 1) log10 1 6 log10 10
2 2
N 0.3 4 log10 ( N 1) 6.3
Home work No. 2
1 , 1 ?
2 2
Q2: Estimate the number of terms of the series
n2
1
n 0
2
that we must take if we are to find its value correct to 3d.p?
Solution1:
1) suppose we take
N
x n as our approximation then T.E is.
n 1 n 2
n
n N 1
21 1 1 N 2
x
n N 1 n 2
n N 1 n 2
2
N 1 2
2
N 2 2
.....
1
2
N 1
N 1
2
N 1
2
1 1 2 1 2 ....
N 12 N 2 2 N 2
2
1
N 1
1
1
1
1
...
N 12 2 22 23
2
N
N 1 1
1
1
2 10 6
1
T .E 10 6
2
N 1
2
2 N 1 2
N = 14 is more accurate.
Solution2:
2) Suppose we take N terms
2
N 1
n 0
1 n2
1 2 2 2 2
N2 N2 N 12 N 2 2
T .E
n N
1 1 1 ...
1 1 1 1 ...
N2 2 N 1 4n4
2
2 2
1
N2
T .E 1 10 3
2
2
1
N2
1 10 3
2
N = 4 the terms required
(( Interpolation))
xi 1 xi h and h
is called the step size or the interval size) and we wish to find
the value of the function at some point yx i
for any i
Suppose x1 x2 x3 x4 if xi Such that xi y xi 1
we have the problem of interpolation, it y xn or y xn
the problem is that of extrapolation.
y xi
Z f ( xi )
x x
f xi 1 f xi
i 1 i
Z
Z f ( xi )
Pi Q Pi+1
x2 x1 xi 1
xi
Example:
Take f x x find 2.5
given 1, 2, 3
x x
2 1.4142
3 1.7321
Actually 2.5 1.5811
2.5 2
2.5 2
3 2
3 2
1.5732
Error 0.0079
A natural generalization is to use the known values of
a function at several points x1 , x2 , x , .............
to fix polynomials of degree (k-1) and use that to
interpolate values at other points.
There are three ways of finding a polynomial.
1)Direct method.
2)Lagrange's method.
3)Newton's method.
We put x xi i 1,...., K And equate xi tof xi
, this gives us K linear equations in K unknown
k 1
a0 a1 x1 a2 x ..... ak 1 x
2
1 1 f ( x1 )
k 1
a0 a1 x2 a2 x ... ak 1 x
2
2 2 f ( x2 )
In matrix form:
1 x1 x12 x1k 1 a0 f x1
1 x2 x 2
2
x2 a1 f x2
k 1
.
.
.
1 x x 2 K 1 a f x
k k xk k 1 k
on the L.H .S 0
It can be proved that the determination of the matrix
, So these equations have a solution.
This is reasonable way if K is small (2,3,4)
Example:
Find a polynomial which fits the following data.
x 0 1 5
f ( x ) 6 2 6
Solution:
since we have three points we can fit a polynomial containing
three coefficients, i.e/polynomial of degree two let it be.
f ( x) a x b x C
2
abc 2
25a 5b c 6
The solution is a 1 b 5 c 6
xi i 1,2,........, k
consider the polynomial
K K x xj
L( xi ) f ( xi )
j 1 xi x j
i 1
j i
L(x) consists of the sum of K polynomials each of which is of degree at
most (k-1) it follows that L(x
is it )self a polynomial of degree most ( k-
1)
K xr x j
f xr f ( xr )
j 1 xr x j
j r
So that L( xr ) f ( xr ). i.e
f ( x) 1 1 1
2 3
Solution:
x 2 x 3 1 x 1 x 3 1 x 1 x 2
L( x) 1 2 3
1 2 1 3 2 1 2 3 3 1 3 2
x 2 x 3 1 x 1 x 3 1 x 1 x 2
2 2 1 3 2
1 2
x 6 x 11
6
Depends upon the use of divided differences.
As an introduction to newtons method we need finite
differences we begin with forward differences take the
function f ( x) x 3
x 3, 5, 7, 9, 11, 13
x 3 5 7 9 11 13
f ( x ) 27 125 343 729 1331 2197
f 98 218 386 602 866
2 f 120 168 216 264
3 f 48 48 48
4 f 0 0
Given the values f xof
a function at a set of
equally spaced points xi i 1, 2, , n
Where x1 x2 x3 x4and xi 1 xi h
we define the first forward difference of
f ( x) at xi to be f ( xi 1 ) f ( xi )
and denote it by f i
x1 and x2 is defined to be
0
x x x x
x 1 3 6 7x 10 x
5th D.D 0
If a function f (x) takes values f ( xi ) at a set of points
f ( x) f ( x1 ) ( x x1 ) x1 x2 x x1 x x2
x1 x2 x3 ( x x1 ) x x2 x xn1
x1 x2 xn x x1 x x2 x xn
x x2 xn
Or: : f ( x) f ( x1 ) ( x x1 ) x1 x2 x x1 x x2 x1 x2 x3
( x x1 ) ( x x2 ) x xN 1 x1 x2 xN 1 xN
Example:
x
Fit a cubic to the data
0 1 3 6
f (x) -7 -8 14 197
f ( x) 7 8 14 197
1st D.D 1 11 61
2 n d D.D 4 10
3rd D.D 1
Taking x1 0, x2 1, x3 3, x4 6
Newton's formula then gives:
f ( x) 7 1( x) 4 x( x 1) x( x 1)( x 3)
f ( x) x 2 x 7
3
Q1: use the direct method and the Lagrange’s method to fit
polynomial to the
Data:
x 1 0 1 2
f ( x) 4 1 0 5
Q2: use newtons method to show that the data below is
x 1 0 1 3 4 6
f (x) ax bx cx d
3 2
1 b
Substituting for b and d in (3) and (4) we have .
2x 2 ac
10 8a 2c sub
6 6 a 1
c 1
The polynomial is f ( x) x 3 x 2 x 1
Now using Lagrange's method:
K K x xj
L( xi ) f ( xi )
i 1
j 1 xi x j
j i
x 0 x 1 x 2
L( x) 4
1 0 1 1 1 2
x 1 x 1 x 2 x 1 x 0 x 1
(1) 0 5
0 1 0 1 0 2 2 1 2 0 2 1
x x 1 x 2 x 1 x 1 x 2 x 1 x x 1
L( x) 4 5
1 2 3 1 1 2 3 2 1
x x 1x 2 1 x 1x 1x 2 5 x 1x x 1
4
6 2 6
L( x)
1
6
4 x 3 3x 2 2 x 3 x 3 2 x 2 x 2 5 x 3 x
1
6 x3 6 x 2 6 x 6
6
x3 x 2 x 1
2) x 1 0 1 3 4 6
2 nd D.D 0 16 32 52
3rd D.D 4 4 4
4th D.D 0 0
x1 1 , x2 0 , x3 1 , x4 3 , x5 4 , x6 6
Newtons formula then gives:
f ( x) 1 (2)( x 1) (0)( x 1)( x 0) 4 ( x 1)( x 0)( x 1)
4 x3 2 x 1
Relatively few integrals can be evaluated analytically.
We therefore have to evaluate most integrls numerically for
An integral of single variable.
b
Suppose that we wish to evaluate a
f ( x) dx
x
A B
and Q is the point b, f (b) then as a first rather crude approximation
f ( x) dx (b a) f (a) f (b)
b 1
a 2
*
n 1
f ( x) dx
b xi 1
(1) f ( x) dx And as in * we take
a xi
i 0
f ( x) dx xi 1 xi f ( xi ) f ( xi 1 )
xi 1 1
(2)
xi 2
The lengths of the sub-intevals need not all be the same
through, they usually are .
In the case where they are the same we have xi 1 xi h
So that. b a nh
And (1) and (2) combined then give us
b x0 nh
a
f ( x) dx
x0
f ( x)dx
f ( x0 ) 2 f ( x1 ) 2 f x2 2 f xn 1 f xn
h
2
f ( x0 ) f ( xn )
or h f x1 f x2 f xn 1
2
and this is the trapezium rule
Example:
Estimate the value of log e 2 by a trapezium rule
approximation
2 dx
1 x
Taking h 1 ?
3
Solution:
3 3
This method is fundamentally similar to the trapezium Rule,
As before we suppose that we wish to evaluate b
a
f ( x)dx
A C B
We have b a nhand so
b x0 nh
a
f ( x) dx
x0
f ( x) dx
n 1
xi xi 1
xi 1 xi f
i 0 2
Or, if the point x0 , x1 ,, xn
are equally spaced
x0 nh n 1
f ( x) dx h f x0 (k 1 h
x0
k 0
2
Example:
Use the midpoint Rule with h 1 to estimate loge 2?
3
Solution:
f ( x) dx 1 we shall require.
x
3 , f 31 , f 113
f 7
1
f 7 , 1 , 3
3 3 11
2 dx 1 6 2 6
log e 2
1 x 3 7 3 11
If we evaluate an integral by
I the Mid-point and the
Trapezium Rules and get values
I M , IT respectively then.
1
(i ) I I M ( I I T )
2
2I M IT
(ii )
3
gives a better approximation still to I
Truncation errors in the trapezium and midpoint Rules:
By truncation error we mean the error we get if we use
the formula once.
By global truncation error We mean the error we get when
we finally complete the integration
over a fixed interval.
The local truncation error in the T.R:
The T.R is
h2 h3
h
f (0) f (h) h f (0) f (0) f (oh)
2 2 4
The error in a single application of T.R is
h3 h3
f ( x)dx f (0) f (h) f 1
h h
0 2 6 4
f (oh)
h3
The T.E is f 1 0 1 h
12
The local truncation error inh the Mid-point Rule:
If we wish to evaluate
0
f ( x)dx The midpoint rule is
h h
0
f ( x)dx hf
2
And Taylor’s expansion lead to
h h2 h3
hf hf (0) f (0) f 2 0 2 h 1
2 2 8
By Taylor’s theorem:
x2
f ( x ) f (0) xf (0) f (0)
2!
h h
x2
0 f ( x)dx 0 f (0) xf (0) 2! f (0) dx
h2 h3
h f ( 0) f (0) f 1 0 h 2
2 6
h h3 h3
f 1 f 2
h
The error is: f ( x) dx hf
0
2 6 8
h3
f 2 0 2 h
24
Assuming that f (x) is constant over o, h
In both the trapezium Rule and the Mid-point Rule our
approximation to the area
under the curve is obtained by
replacing the arc of the curve between x=a and x=b by a straight
line. In the former case the line
Joined the points at the ends of the arc, in the latter case it
passes through the
mid point of the arc parallel to the x-axis A natural extension of
this idea is to replace
the arc by a curve of the second degree in which passes through
the two end points
and the Mid-point of the arc such a curve is a parabola and has an
equation of the form:
y Ax Bx C.
2
The algebra is simplified if we take a h and b hso that
1
a b 0
2
We then wish to choose A,B,C so that the parabola passes through
the points
h, f h, 0, f (0), h, f (h)
the equations defining A, B , C are there fore
Ah Bh C f ( h)
2
C f (0)
Ah 2 Bh C f ( h)
f ( h) f ( h) 2 f (0)
So that A
2h 2
f ( h) f ( h)
B
2h
C f (0)
The parabola so defined coincides with the curve y f (x)
at the three points
h
h
f ( x ) dx
h
h
Ax 2
Bx C dx
2
Ah 3 2ch
3
And substitution of the values of A, B C gives
1 1 3 1
1 1 3
4 2 4
0
4 2 4
(1) f ( 0) 1
( 2) f 1 4 1 11
16
(3) f 1 2 1 11
4
( 4) f 3 4
1
1 9
16
(5) f (1) 1
2
1 3
2
dx 1 1 1
1 x2
12 2
4
1 1
9 1 1
1 4
16 16
0.785392
M. point Rule
h
h
f ( x)dx 2h f (0) I M
f ( x)dx h f (h) f (h) I
h
T. Rule h
T
2 I M I T h f ( h) 4 f (0) f (h)
2I M IT
f (h) 4 f (0) f (h)
h
3 3
= Simpson's Rule.
Truncation Error in Simpson's Rule:
we take Simpson's rule in the form
Where 0 x
h h3 h5
h
f ( x)dx 2hf (0)
3
f (0)
60
f ( )
1 Sin x
Q2: Estimate the value of I
0 1 x
dx
(i)Using the Mid-point Rule to give Im.
(ii)Using the Trapezium Rule to give IT.
2I m IT
In each case taking h 1 Ic
4 Let
3
(iii) Using Simpson's Rule with h 1 and compare it with Ic.
4
b ba
a
f ( x ) dx (b n) f
2
0.6932 1.8138
1
3
0.8357 to 4 d . p
The error
0.8377 0.8357
0.0020 to 4d . p
1 sin x
2) I dx with h 1
0 1 x 4
(i) Using the Mid-point Rule
1 Sin 0 1 4 1 2 Sin 1 4 2 4 1 2
Sin
2 3 1
4
sin 3 4 1
4 2
i I M 4 2 4
4 1 1
2
0 1
4
1 12 4
1 24
12
1 3
1 3 4
1
24 4 2 4 4
3
1 Sin 8
Sin Sin 5 sin 7
8 8 8
4 1 1 1 3 1 5 1 7
8 8 8 8
1 0.3827 0.9239 0.9239 0.3827
8
4 9 11 13 15
2 0.0425 0.0840 0.0711 0.0255
0.4462 to 4d . p.
(ii) Using the Trapezium Rule.
2 I M IT 2 0.4462 0.4691
Ic 0.4338 to 4d . p.
3 3
I c is the most accurate value. Because in Ic
the error terms of I M and I T approximately cancelles out.
x 0 1 2 3 1
4 4 4
Sin x
0 0.5657 0.6667 0.4041 0
1 x
Applying Simpson's Rule
I s 1 40.5657 0.4041 20.6667 3.8792 1.3334
1
12 12
I s 0.4344
I c I s 0.0006 Error
The trapezium Rule and Simpson's Rule are the simplest formula of an
infinite class called the Newton cotes formula.
h
For the K-th order Newton cotes formula applied to
f ( x) dx
0
h
f h f 1 h
h
0 f ( x)dx
2
put f ( x) 1; h 1 1 h
h
it works
2
h2 h h2
f ( x) x; h h1 it works
2 2 2
2
f ( x) : x ;
h3 h
3 2
h 1 h 2
2
2
it works
These are the same if 1 2 3
2 2
2 2 2 1 0
3
1 1
3 1 1
2 2 12
h h 1 1 1 1
0
f ( x)dx f
2 2
h f
12 2
h
12
has a L.T.E order at least h4
Such a formula is called a gauss type integration formula .
Example:
1 dx
Find
0 1 x 2
?
T. Rule gives
1
2
2 4
1 1 3 3.00
1
4
3.20
2
M. point Rule gives 4 2
1 1 5
Gauss formula gives
1 1
1
4 2 1 1
2
1 1
2
1 1
2 12 2 12
1 1 1
24 1 4
1
3
12 3 12
8
1 48
3
3.1475
2 16 1 61
9 12
x2
Suppose we have an integral such e dx Since
e x 0 very rapidly we first choose N and approximate by
2
N
x2
e dx We choose N that T.E
N
N
2 e x2
dx Where is less than desired accuracy
N
then use some formula e.g M-point Rule to approximate
N
2 e x2
dx
0
e.g/ If we take N=10 and h= ½ we get
1 16
1 9 25 49
e x dx e e e e
2
16 16 16
2
1.772458to 6 d . p
Now 1.772458 3.141607
2
x2
in fact the e dx