Preface
This teaching material provides an introduction to the numerical methods that are typically
encountered (and used) in engineering, science and mathematics undergraduate courses. It gives
a brief introduction to the learner on basic concepts on error estimation, numerical solutions of
nonlinear equations, methods on system of equations, interpolation, numerical differentiation and
integration and numerical solution of ordinary differential equations.The first chapter is on basic
concepts in error estimation,second chapter about numerical methods to solve nonlinear
equations,such as bisection method,false position method,Newton-Raphson method etc. are
illusterted,in the third chapter numerical methods for system of equations(both direct and
iterative) methods are discussed. In the fourth chapter interpolation (in the case of equally spaced
data, Newton’s forward and back ward difference interpolation and where as in the case of
equally or unequally spaced data points, Newton’s divided difference interpolation method and
the lagrange’s method are presented). In the fifth chapter of this material numerical
differentiation using forward difference and backward difference interpolation formula and
numerical integration techniques, Trapezoidal rule, Simpson’s one-third and three-eight rules are
illustrated and in chapter six numerical solutions of ordinary differential equations are presented,
the methods presented in this chapter are Euler’s Method, Taylor series method of order N and
the Fourth order Runge-Kutta method, all the methods are illustrated with examples.
i
Table of Contents
Pages
CHAPTER ONE ........................................................................................................................................... 1
BASIC CONCEPTS ON ERROR ESTIMATION ................................................................................................... 1
1.1
. Introduction ..................................................................................................................................... 1
1.2. Error (1 hour) ......................................................................................................................................... 2
1.3. Sources of Error ................................................................................................................................... 2
1.4. Absolute, Relative and Percentage error (1 hour) .................................................................................. 3
1.5. Error propagation (3 hours).................................................................................................................... 4
CHAPTER TWO .......................................................................................................................................... 1
NUMERICAL SOLUTION OF NON-LINEAR EQUATIONS .................................................................. 1
2.1. Introduction ............................................................................................................................................ 1
2.2. Bisection Method (2hours) .................................................................................................................... 2
2.3. False position method (2 hours) ............................................................................................................. 9
2.4.
Fixed-point iteration (1 hour) .......................................................................................................... 14
2.5. Newton-Raphson method (2 hours) ..................................................................................................... 16
2.6. Secantmethod (1 hour) ......................................................................................................................... 20
CHAPTER THREE .................................................................................................................................... 24
SYSTEMS OF LINEAR EQUATIONS ..................................................................................................... 24
3.2.
Introduction ................................................................................................................................... 24
3.1.
Direct methods to solve a linear system of equations (8 hours)...................................................... 26
3. 2.1. Gaussian elimination (2 hours) ........................................................................................................ 26
3.2.2 Gauss- Jordan elimination (2 hours) .................................................................................................. 29
3.2.3 Solution of a tri-diagonal system (2 hours) ........................................................................................ 30
3.2.4.Thomas method .................................................................................................................................. 31
3.2.5 Lu Decomposition Method (2 hours) ................................................................................................. 32
3.2.6. Crout’s LU decomposition method ................................................................................................... 33
3.3. Iterative methods (4 hours) .................................................................................................................. 37
3.3.1 Jacobi iterative method (2 hours) ....................................................................................................... 39
3.3.2. Gauss-Seidel iterative method (2 hours) ........................................................................................... 43
3.3.3 Newton ‘s method to solve system of nonlinear equations (2 hours) ................................................ 47
CHAPTER 4 ............................................................................................................................................... 54
ii
FINITE DIFFERENCE OPERATORS AND INTERPOLATION ............................................................ 54
4.1. Introduction .......................................................................................................................................... 54
4.2. Finite Differences............................................................................................................................... 55
4.2.1. Forward Differences (1 hour) ......................................................................................................... 55
4.2.2. Backward Differences (1 hour) ......................................................................................................... 57
4.2.3. Central differences (1 hour) .............................................................................................................. 58
4.2.4. Shift Operater(E) (1 hour) ................................................................................................................. 61
4.3. Interpolation with equally spaced data (4 hours) ................................................................................. 63
4.3.1. Newton’s forward difference interpolationFormula (NFDIF) (2 hours) ........................................... 63
4.3.2.
Newton’s backward difference interpolation (2 hours) .............................................................. 66
4.4. Interpolation with unequal intervals (4 hours) ..................................................................................... 68
4.4.1. Newton’s divided difference (2 hours) ............................................................................................. 69
4.4.2.
Newton’s divided difference Interpolation formula (NDDIF) (2 hours) .................................... 70
4.4.2.
Lagrange’s interpolation formula (LIF) (2 hours) ...................................................................... 74
CHAPTER 5 ............................................................................................................................................... 78
NUMERICAL DIFFERNTIATION AND INTEGRATION ..................................................................... 78
5.1. Introduction .......................................................................................................................................... 78
5.2. Numerical differentiation (4 hours) ..................................................................................................... 79
5.3.
Numerical Integration (4 hours) ...................................................................................................... 82
5.3.1. Trapezoidal Rule (2 hours) ............................................................................................................... 84
5.3.2. Simpson’s one- third rule (1 hours) .................................................................................................. 85
5.3.3.
Simpson’s three-eight rule (1 hours) ........................................................................................... 86
CHAPTER SIX ........................................................................................................................................... 89
NUMERICAL SOLUTION OF ORDINARY DIFFERENTIAL EQUATIONS ....................................... 89
6.1. Introduction .......................................................................................................................................... 89
6.2. Euler’s Method(2hours) ....................................................................................................................... 90
6.3. Modified Euler’s Method (2 hours) ..................................................................................................... 94
6.4. Taylor series Method of order N (2 hours) .......................................................................................... 95
6.5. Runge-Kutta Method (2hours) ............................................................................................................. 98
Reference .................................................................................................................................................. 104
iii
NUMERICAL METHODS
CHAPTER ONE
BASIC CONCEPTS ON ERROR ESTIMATION
1.1. Introduction
What is Numerical Analysis?
Numerical methods are methods for solving problems on computers by numerical calculations,
often giving a table of numbers and/or graphical representations or figures. Numerical methods
tend to emphasize the implementation of algorithms. So, we can define Numerical analysis as an
area of mathematics and computer science that deals with crating data, organizing, analizing and
implementing an algorithm to solve mathematical problems. Inshort Numerical analysis is the
study of algorithms that use numerical approximation (as opposed to general symbolic
manipulations) for the problems of mathematical analysis (as distinguished from discrete
mathematics).
Why we learn Numerical Analysis?
The aim of numerical method is therefore to provide systematic methods for solving problems in
a numerical form. The process of solving problems generally involves starting from an initial
data, using high precision digital computers, following the steps in the algorithms and finally
obtaining the results. Most practical problems that have no analytic solutions can usually solved
by numerical methods.
Analytical solution versus numerical solution of a problem: the former is a closed form formula
for a solution and the later is numerical value (usually approximately) for a desired solution.
All numerical methods involve approximations due to either limits in the algorithm or physical
limits in the computer hardware. Errors associated with measurements or calculations can
characterize with reference to accuracy and precision.
Accuracy refers to how closely a computed or measured value agrees with the true value.
Prepared by Abe N
1
NUMERICAL METHODS
Precision refers how close; a measured or computed value agrees with each other after repeated
sampling.
Objective
At the end of this chapter students should be able to:
Define an error.
Identify some common sources of errors.
Determine the magnatiude of the error that occur during numerical computation.
Determine the effect of errors in the independent variables on the dependent variable.
Allowted time to complete this chapter is 5 hours
Activity 1
Given 𝜑(𝑥, 𝑦, 𝑧) = 3𝑥 2 𝑦 + 4𝑧 3 and 𝑥 = 2, 𝑦 = 3 and 𝑧 = 1 with errors
0.02,0.03 and 0.01 respectively, then determine the error in 𝜑.
1.2. Error (1 hour)
Often the numerical data and methods used are approximate ones. Hence, the error in a
computed result may caused by the errors in the data, or the errors in the method or both.
Definition1.1: There are a number of ways to describe error in measurements and calculations.
The simplest is the absolute error; this is the difference between the measured or calculated value
and the true value.
Error= true value –approximate value
1.3. Sources of Error
There are different sources of errors among them most common sources of errors in numerical
Method are:
Prepared by Abe N
2
NUMERICAL METHODS
A. Modeling Errors: Mathematical model is a process when mathematical equations, used
to represent a physical system. This modeling introduces errors and are called modeling
errors.
B. Blunders and Mistakes: Blunders occur at any stage of the mathematical modeling
process and consist to all other components of errors. Mistakes are due to the
programming errors.
C. Machine representation and Arithmetic errors: These errors are inevitable when using
floating-point arithmetic when using computers or calculations. Examples: rounding and
chopping errors.
D. Mathematical Approximation Errors: This error also known as a truncation error or
discretization error, which arises when an approximate formulation made to a problem
otherwise, not solved exactly.
1.4. Absolute, Relative and Percentage error (1 hour)
Absolute, Relative and Percentage errors are methods that help to determine the amount or
magnitude of the error that committed during numerical computation.
Definition1.2: Suppose that 𝒑 ∗ is an approximation to the true value p. Then
a. the absolute error(𝐸𝑎 ) is |𝑝 − 𝑝 ∗|.
b. the relative error (𝐸𝑟 ) is
|𝑝−𝑝∗|
|𝑝|
provided 𝑝 ≠ 0.
|𝑝−𝑝∗|
c. the percentage error(𝐸𝑝 ) is |𝑝| × 100%provided 𝑝 ≠ 0.
Example1.1: Determine the absolute and relative errors when approximating 𝑝 by 𝑝 ∗ when.
a.𝑝 = 0.3 × 101 and 𝑝 ∗= 3.1
b.𝑝 = 0.3 × 10−3 and 𝑝 ∗= 0.31 × 10−3
c.𝑝 = 0.3 × 104 and 𝑝 ∗= 0.31 × 104
Solution: a𝑝 = 0.3 × 101 and 𝑝 ∗= 3.1
𝐸𝑎 = |𝑝 − 𝑝 ∗| = |0.3 × 101 − 0.31 × 101 | = |3 − 3.1| = |−0.1| = 0.1.
Prepared by Abe N
3
NUMERICAL METHODS
𝐸𝑟 =
𝐸𝑎 0.1
1
=
=
= 0.0333
|𝑝|
3
30
𝐸𝑝 = 𝐸𝑟 × 100% =
1
10
× 100% =
% = 3.333%
30
3
b and c left as an exercise
5
1
Example1.2: Suppose that 𝑥 = 7 and 𝑦 = 3. Use five-digit chopping for calculating
𝑥 + 𝑦,𝑥 − 𝑦,𝑥 × 𝑦,and 𝑥 ÷ 𝑦.
5
1
Solution: Note that 𝑥 = 7 = 0.71428 and 𝑦 = 3 = 0.33333
𝑥 + 𝑦 = 0.71428 +0.33333 = 1.04761
𝑥 + 𝑦 = 1.0476 in five digits chopping
5
1
22
The true value 𝑥 + 𝑦 = 7 + 3 = 21,so
22
Absolute = |21 − 1.0476| = 0.19 × 10−4
Relative error=
0.19×10−4
22
21
= 0.0018
1.5. Error propagation (3 hours)
Objective
At the end of this subtopic students shoud be able:
Understand how errors in numbers can propagate through mathematical functions.
Determine the error in output because of the error in the input.
1.5.1. Functions of a single variable (1 hour)
Suppose that we have a function f (x) that is dependent on a single independent variable x.
Assumethat ∆𝑥 be the absolute error in x. We, therefore, would like to assess the effect of the
error in 𝑥 on the value of the function. That is, we would like to estimate the error in 𝑦 = 𝑓(𝑥).
Prepared by Abe N
4
NUMERICAL METHODS
y y f ( x x )
The error in y is given by
y f ( x x) f ( x)
(1.1)
From Taylor series, we have
f ( x x) f ( x) f '( x)x
f ''( x) 2 f '''( x ) 3
x
x . . .
2!
3!
Neglecting second and higher order derivatives we get
𝑓(𝑥 + ∆𝑥) = 𝑓(𝑥) + 𝑓 ′ (𝑥)∆𝑥
⟹ 𝑓(𝑥 + ∆𝑥) − 𝑓(𝑥) = 𝑓 ′ (𝑥)∆𝑥
⟹ ∆𝑦 = 𝑓 ′ (𝑥)∆𝑥
Hence, the absolute error in 𝑦 can be estimated by
∆𝑦 = |𝑓 ′ (𝑥)|∆𝑥
1.5.2. Functions of more than one variable (2 hours)
The foregoing approach can be generalized to functions that are dependent on more than one
independent variable. This is accomplished with a multivariable version of the Taylor series.
That is if 𝜑 = 𝑓(𝑥1 , 𝑥2 , … , 𝑥𝑛 )is a function of several variables and the error in each 𝑥𝑖 be xi ,
then
𝜕𝜑
𝜕𝜑
𝜕𝜑
𝜕𝜑
∆𝜑 = | | ∆𝑥1 + | | ∆𝑥2 + | | ∆𝑥3 + ⋯ + | | ∆𝑥𝑛
𝜕𝑥
𝜕𝑥
𝜕𝑥
𝜕𝑥
Example 1.3: If 𝑓(𝑥) = 7𝑥 3 + 13𝑥 2 + 10 and 𝑥 = 5 with an error 0.002, then determine the
absolute error ∆𝑦.
Solution:
∆𝑦 = |𝑓 ′ (𝑥)|∆𝑥
;𝑓 ′ (𝑥) = 21𝑥 2 + 26𝑥
Prepared by Abe N
5
NUMERICAL METHODS
𝑓 ′ (5) = 21(25) + 26(5) = 525 + 130 = 655
∆𝑦 = |655|(0.002) = 1.31
Example 1.4: Let𝜑(𝑥, 𝑦, 𝑧) = 12𝑥 2 𝑦𝑧 3 and 𝑥 = 2, 𝑦 = 3, and 𝑧 = 1 and if errors 0.002,
0.003, and0.001 are the errors made on 𝑥, 𝑦,and𝑧 respectively. What will be the error in 𝜑.
Solution: Given𝑥 = 2, 𝑦 = 3, 𝑧 = 1 ; ∆𝑥 = 0.002, ∆𝑦 = 0.003 and∆𝑧 = 0.001.
𝜕𝜑
𝜕
𝜕𝜑
=
(12𝑥 2 𝑦𝑧 3 ) = 24𝑥𝑦𝑧 3 ; |
= 24𝑥𝑦𝑧 3 |(2,3,1) = 144
𝜕𝑥 𝜕𝑥
𝜕𝑥 (𝑥,𝑦,𝑧)
𝜕𝜑
𝜕
𝜕𝜑
=
(12𝑥 2 𝑦𝑧 3 ) = 12𝑥 2 𝑧 3 ; |
= 12𝑥 2 𝑧 3 |(2,3,1) = 48
𝜕𝑦 𝜕𝑦
𝜕𝑦 (𝑥,𝑦,𝑧)
𝜕𝜑
𝜕
𝜕𝜑
=
(12𝑥 2 𝑦𝑧 3 ) = 48𝑥 2 𝑦𝑧 2 ; |
= 48𝑥 2 𝑦𝑧 2 |(2,3,1) = 432
𝜕𝑧 𝜕𝑧
𝜕𝑧 (𝑥,𝑦,𝑧)
𝜕𝜑
𝜕𝜑
𝜕𝜑
∆𝜑 = | | ∆𝑥 + | | ∆𝑦 + | | ∆𝑧 = 144(0.002) + 48(0.003) + 432(0.001)
𝜕𝑥
𝜕𝑥
𝜕𝑥
= 0.288 + 0.144 + 0.432 = 0.864
Therefore, the absolute error in𝜑 is 1. 008.The physical interpretation of the result is, if the
defect in each of the inputs is given as indicated above the defect in the out put is 1.008.
Summary
An error can be difined as the difference between the exact value and the approximate
value.
Absolute, percentage and relaive errors are used to determine the number of errors
occurred during computation.
Propagation error is the effect of the error in the input on the out put.
Prepared by Abe N
6
NUMERICAL METHODS
Review exercise 1
20
1. The three approximations of 6 are given as 3.3, 3 and 3.4.
a. Find the absolute, relative and percentage errors for each approximation
b. Which of these is the best approximation?
2. If 𝑓(𝑥) = 𝑥 4 + 3𝑥 2 + 2 and 𝑥 = 1 with error 0.002, then determine ∆𝑦.
3. Given 𝑢(𝑥, 𝑦) =
𝑦 4 𝑥+𝑥 2 𝑦
4𝑥
and 𝑥 = 2, 𝑦 = 1 with errors 0.02 and 0.03 respectively. Based on
the given determine ∆𝑢.
Prepared by Abe N
1
NUMERICAL METHODS
CHAPTER TWO
NUMERICAL SOLUTION OF NON-LINEAR EQUATIONS
2.1. Introduction
A numerical solution of an equation 𝑓(𝑥) = 0 is a value of 𝑥 that satisfies the equation
approximately. This means that when𝑥 is substituted in the equation, the value of 𝑓(𝑥) is close to
zero, but may not be exactly zero.
The methods used for solving equations numerically divided in to twogroups: Bracketing
methods and open methods. In bracketing methods, an interval that contains the solution is
identified. By definition, the end points of the interval are the upper bound and the lower bound
of the solution. Then by using a numerical scheme, the size of the interval is successively
reduced until the distance between the end points is lessthan the desired accuracy of the solution.
In an open method, an initial estimate (one point) for the solution is assumed. The value of this
initial guess for the solution should be closer to the actual solution. Then, by using a numerical
scheme, better (more accurate) values for the solution are calculated. Bracketing methods are
always converge to the true solution, where as open methods are usually more efficient but
sometimes might not yield the solution.
In this chapter four numerical method for finding a root of equation𝑓(𝑥) = 0 are presented. Two
bracketing methods; the bisection and false postion (regulafalsi) method and three open methods,
Newton-Raphson method, secantmethod and fixed-point iteration methodare illustrated in the
next section.
Objective
At the end of this chapter students should beable to:
Determine whether a root exists in a given interval or not.
Prepared by Abe N
1
NUMERICAL METHODS
Use different root finding methods to approximate a root.
Identify the convergency condition.
Allowted time to complete this chapter is 8 hours
Activity 2.1
1. Find a root of the equation 𝑓(𝑥) = 𝑥𝑒 𝑥 − 2 = 0 that lies in [0,1].
2. Find a root of the equation 𝑓(𝑥) = sin3𝑥 + 3𝑒 −2𝑥 sin𝑥 − 3𝑒 −𝑥 sin2𝑥 − 𝑒 −3𝑥 = 0
that lies in[3,4].
2.2. Bisection Method (2hours)
Objective
At the end of this subtopic students should beable:
Determine whether a root exists in a given interval or not.
Use bisection to find a root of an equation of the form 𝑓(𝑥) = 0.
Determine the maximum number of iterations required to get the desired accuracy.
The bisection method is a bracketing method for finding a numerical solution of an equation of
the form 𝑓(𝑥) = 0 when it is kown that with in a given interval [𝑎, 𝑏], 𝑓 is continuous and the
equation has a solution in this interval. Let 𝑓(𝑥) be a given function, continuous on an interval
[𝑎, 𝑏], such that 𝑓(𝑎)𝑓(𝑏) < 0 .Using intermidate value theorem, it follows that there exists at
least one zero (root) of 𝑓 in (a,b).To simplify our discussion ,we assume that 𝑓 has exactly one
root 𝛼.Such a function is shown in figure 2.1
Prepared by Abe N
2
NUMERICAL METHODS
y
f(x)
(a,f(a))
x0 =( a+b)/2
a x =(a+x )/2
b
1
0
x
(b,f(b))
Figure 2.1: The bisection method and the first two approximations to its root 𝛼.
The bisection method is based on repeated halvingof the interval [a, b]to determine a smaller
and smaller interval with in which the root𝛼 must lie. The procuder is carried out by first finding
the midpoint of [𝑎, 𝑏]and at each step, locating the half containing the root. The first step of this
method is finding the midpoint𝑥0 =
𝑎+𝑏
2
of the interval [𝑎, 𝑏]and evaluating 𝑓 at 𝑥0 , if𝑓(𝑥0 ) =
0,then 𝑥0 is the required root and we stop,if not compute the product 𝑓(𝑥0 )𝑓(𝑏).If the product
is negative ,then the new interval containing the root 𝛼 is [𝑥0 , 𝑏]otherwise the root is in the
interval [𝑎, 𝑥0 ].The new interval containing the root is bisected again. The process of halving the
new interval containing the root continues until the numerical solution is accurate enough
according to the given condition or tolerance satisfied.
Procedure for Bisection Method to find the root of the equation𝒇(𝒙) = 𝟎
Step 1: Choose the interval [a, b] such that𝑓(𝑎). 𝑓(𝑏) < 0
Step2: Evaluate the mid point𝑥𝑖 =
𝑎+𝑏
2
and 𝑓(𝑥𝑖 ).
Step 3: If 𝑓(𝑥𝑖 ) = 0, the root is 𝑥𝑖 stop, else If 𝑓(𝑎). 𝑓(𝑥𝑖 ) < 0,then set 𝑏 = 𝑥𝑖 else set
𝑎 = 𝑥𝑖 and go back to step 2.
Prepared by Abe N
3
NUMERICAL METHODS
Step 4: Stop the evaluation when the difference between two successive approximation is less
than the given tolerance i.e.|𝑥𝑖+1 − 𝑥𝑖 | <tolerance.
Examples 2.1: Find the root of the equation𝑓(𝑥) = 𝑥 3 − 𝑥 − 1 = 0 lying between 1 and 2
using bisection method.
Solution:𝑓(1) = 1 − 1 − 1 = −1 < 0, 𝑓(2) = 23 − 2 − 1 = 5 > 0
Since 𝑓(1)𝑓(2) = −5 < 0 a root lies in the interval [1, 2].
First approximation:𝑥0 =
𝑎+𝑏
2
=
1+2
2
= 1.5
⟹ 𝑓(1.5) = (1.5)3 − 1.5 − 1 = 3.375 − 1.5 − 1 = 0.875, which is positive, so the root now
lies between [1,1.5].
Second iteration:𝑥1 =
1+1.5
2
2.5
= 2 = 1.25.
𝑓(1.25) = (1.25)3 − 1.25 − 1 = −0.297 < 0
⟹The the root lies between 1.25 and 1.5.
Third iteration:𝑥2 =
1.25+1.5
2
= 1.375, 𝑓(1.375) = 0.2246 > 0
The root lies between 1.25 and 1.375.and so on.
Using the C++program the iterations are given in table 2.1.
Enter the interval [a, b], maximum iteration and allowed error respectively:
1 2 12 0.0001
Since (𝑎)𝑓(𝑏) < 0 , a root lies between a and b the iterations are:
Table 2.1_________________________________________________________
i
a
b
𝑥𝑖 𝑓(𝑥𝑖 )|𝑥𝑖+1 − 𝑥𝑖 |
_________________________________________________________
0 1.000000
2.000000
1.500000
0.875000
1 1.000000
1.500000
1.250000 -0.296875
0.250000
Prepared by Abe N
4
NUMERICAL METHODS
2 1.250000
1.500000
1.375000
0.224609
0.125000
3 1.250000
1.375000
1.312500
-0.051514
0.062500
4 1.312500
1.375000
1.343750
0.082611
0.031250
5 1.312500
1.343750
1.328125
0.014576
0.015625
6 1.312500
1.328125
1.320313
-0.018711
0.007813
7 1.320313
1.328125
1.324219
-0.002128
0.003906
8 1.324219
1.328125
1.326172
0.006209
0.001953
9 1.324219
1.326172
1.325195
0.002037
0.000977
10 1.324219
1.325195
1.324707
-0.000047
0.000488
11 1.324707
1.325195
1.324951
0.000995
0.000244
12 1.324707
1.324951
1.324829
0.000474
0.000122
13 1.324707
1.324829
1.324768
0.000214
0.000061
________________________________________________________
The root converges after iteration 13, the root is 𝑥 =1.324768.
Example 2.2: Perform 3 iterations of the bisection method to obtain a root the equation
𝑓(𝑥) = cos 𝑥 − 𝑥𝑒 𝑥 = 0 in[0,1].
Solution:𝑓(0) = cos 0 − 0𝑒 0 = 1 > 0
𝑓(1) = cos 1 − 1𝑒 1 =cos 1 − 𝑒 < 0 thus, there exists a root in [0,1]
First approximation:𝑥1 =
𝑎+𝑏
2
= 0.5
𝑓(𝑥1 ) = 𝑓(0.5) = cos(0.5) -0.5𝑒 0.5 = 0.0532 > 0
Since (𝑎)𝑓(𝑥0 ) > 0, the root lies in [0.5,1]
Second approximation:𝑥2 =
0.5+1
2
= 0.75
𝑓(𝑥2 ) = 𝑓(0.75) = cos(0.75) − 0.75𝑒 0.75 = −0.8561 < 0
Prepared by Abe N
5
NUMERICAL METHODS
Thus, the root lies in [0.5,0.75]
Third approximation:𝑥3 =
0.5+0.75
2
= 0.625
Thus, the approximate root is 𝑥3 = 0.625
Example2.3: Find the solution of the equation 𝑓(𝑥) = 𝑥 3 + 4𝑥 2 − 10 in [1, 2] using bisection
method with tolerance 0.0003.
Solution: The resultsusing C++programming is given in table 2.2.
Enter the interval [𝑎, 𝑏], maximum iteration and allowed error respectively:
1
2 10 0.003
Since 𝑓(𝑎)𝑓(𝑏) < 0 ,a root lies between a and b, the iterations are:
Table 2.2_________________________________________________________
i
a
b
xi 𝑓(𝑥𝑖 )|𝑥𝑖+1 − 𝑥𝑖 |
__________________________________________________________
0 1.000000
2.000000
1.500000
2.375000
1 1.000000
1.500000
1.250000
-1.796875
0.250000
2 1.250000
1.500000
1.375000
0.162109
0.125000
3 1.250000
1.375000
1.312500
-0.848389
0.062500
4 1.312500
1.375000
1.343750
-0.350983
0.031250
5 1.343750
1.375000
1.359375
-0.096409
0.015625
6 1.359375
1.375000
1.367188
0.032356
0.007813
7 1.359375
1.367188
1.363281
-0.032150
0.003906
8 1.363281
1.367188
1.365234
0.000072
0.001953
__________________________________________________________
The root converges after iteration 8, the root is 𝑥 =1.365234
Example 2.4: Use the bisection method to approximate the solution of the equation
𝑓(𝑥) = 𝑥 3 − 27𝑥 + 1 = 0 in[0,1]with |𝑥𝑖+1− 𝑥𝑖 | < 0.0005
Solution: The resultsusing C++programming is given in table 2.3.
Prepared by Abe N
6
NUMERICAL METHODS
Enter the interval [a, b], maximum iteration and allowed error respectively:
0 1 15 0.0005
Since𝑓 (𝑎) 𝑓 (𝑏) < 0, a root lies between a and b, the iterations are:
Table 2.3__________________________________________________________
i
a
b
𝑥𝑖 𝑓(𝑥𝑖 ) |𝑥𝑖+1 − 𝑥𝑖 |
__________________________________________________________
0 0.000000
1.000000
0.500000 -12.375000
1 0.000000
0.500000
0.250000
-5.734375
0.250000
2 0.000000
0.250000
0.125000
-2.373047
0.125000
3 0.000000
0.125000
0.062500
-0.687256
0.062500
4 0.000000
0.062500
0.031250
0.156281
0.031250
5 0.031250
0.062500
0.046875
-0.265522
0.015625
6 0.031250
0.046875
0.039063
-0.054628
0.007813
7 0.031250
0.039063
0.035156
0.050825
0.003906
8 0.035156
0.039063
0.037109
-0.001902
0.001953
9 0.035156
0.037109
0.036133
0.024461
0.000977
10 0.036133
0.037109
0.036621
0.011280
0.000488
_________________________________________________________
The root converges after iteration 10, the root is 𝑥 = 0.036621.
Example 2.5: Using bisection method to find the real root of the equation
𝑓(𝑥) = 3𝑥 − √1 + 𝑠𝑖𝑛𝑥 = 0in the intrval[0,1].
Solution: The resultsusing C++programming is given in table 2.4.
Enter the interval [𝑎, 𝑏],maximum iteration and allowed error respectively:
Prepared by Abe N
7
NUMERICAL METHODS
0 1 16 0.0005
Since 𝑓(𝑎)𝑓(𝑏) < 0 , a root lies between 𝑎and 𝑏, the iterations are:
Table 2.4_________________________________________________________
𝑖a b
xi 𝑓(𝑥𝑖 )|𝑥𝑖+1 − 𝑥𝑖 |
_________________________________________________________
0 0.000000
1.000000
0.500000
0.283684
1 0.000000
0.500000
0.250000
-0.366872
0.250000
2 0.250000
0.500000
0.375000
-0.043877
0.125000
3 0.375000
0.500000
0.437500
0.119321
0.062500
4 0.375000
0.437500
0.406250
0.037578
0.031250
5 0.375000
0.406250
0.390625
-0.003185
0.015625
6 0.390625
0.406250
0.398438
0.017187
0.007813
7 0.390625
0.398438
0.394531
0.006999
0.003906
8 0.390625
0.394531
0.392578
0.001906
0.001953
9 0.390625
0.392578
0.391602
-0.000640
0.000977
10 0.391602
0.392578
0.392090
0.000633
0.000488
___________________________________________________________
The root converges after iteration 10, the root is 𝑥 = 0.392090.
Theorem2.1: Suppose that 𝑓𝜖𝑐[𝑎, 𝑏] and 𝑓(𝑎)𝑓(𝑏) < 0.The Bisection method generates a
𝑏−𝑎
sequence {𝑝𝑛 }∞
𝑛=1 approximating a zero of 𝑓 with |𝑝𝑛 − 𝑝| ≤ 2𝑛 with 𝑛 ≥ 1.
𝑏−𝑎
Proof: For each 𝑛 ≥ 1,we have 𝑏𝑛 − 𝑎𝑛 = 2𝑛−1 and 𝑝 ∈ (𝑎𝑛 , 𝑏𝑛 )
Since 𝑝𝑛 =
𝑎𝑛 +𝑏𝑛
2
(2.1)
for all 𝑛 ≥ 1it follows that
Prepared by Abe N
8
NUMERICAL METHODS
1
𝑏−𝑎
2
2.2𝑛−1
|𝑝𝑛 − 𝑝| ≤ (𝑏𝑛 − 𝑎𝑛 ) =
𝑏−𝑎
= 2𝑛
(From (2.1))
𝑏−𝑎
⟹ |𝑝𝑛 − 𝑝| ≤ 2𝑛 , Thus, the sequence {𝑝𝑛 }∞
𝑛=1 converges to 𝑝 with rate
1
1
of convergence 𝑂(2𝑛) that is 𝑝𝑛 = 𝑝 + 𝑂(2𝑛)
1
𝑝𝑛 → 𝑝as𝑛 → ∞ with 𝑂(2𝑛)
Example2.6: Determine the number of iterations required to solve 𝑓(𝑥) = 𝑥 3 + 4𝑥 2 − 10 = 0
with accuracy 10−3using 𝑎 = 1, 𝑏 = 2.
𝑏−𝑎
Solution:|𝑝𝑛 − 𝑝| ≤ 2𝑛
𝑏−𝑎 2−1
= 𝑁 < 10−3
2𝑁
2
⟹ 2−𝑁 < 10−3
⟹ 𝑙𝑜𝑔2−𝑁 < 𝑙𝑜𝑔10−3
⟹ −𝑁𝑙𝑜𝑔2 < −3𝑙𝑜𝑔10
⟹ −𝑁 < −
3
3
⟹𝑁>
≈ 9.96 ≈ 10
𝑙𝑜𝑔2
𝑙𝑜𝑔2
Therefore, the maximum number of iterations required is 𝑛 = 10.
2.3. False position method (2 hours)
Objective
At the end of this subtopic students should beable to:
Determine whether a root exists in a given interval or not.
Use false position method to find a root an equation of the form𝑓(𝑥) = 0.
Prepared by Abe N
9
NUMERICAL METHODS
False position method (also known as regulafalsi method) is a bracketing method for finding a
numerical solution of an equation of the form 𝑓(𝑥) = 0 when it is known that with in a given
interval [a, b],𝑓(𝑥) is continuous and the equation has a solution. False position method has the
advantage of being slitly faster than the bisection method.As the bisection method the function
assumed to be continuous over the interval [a, b] and 𝑓(𝑎)𝑓(𝑏) < 0.In this method, the first
estimate of the solution 𝑥0 is selected as appoint of intersection of the 𝑥 axis and the straight line
joining the points (𝑎, 𝑓(𝑎)) and (𝑏, 𝑓(𝑏)) as shown in the figure 2.1.
y
(a,f(a))
α
a
x2 x1
x0
b
x
(b,f(b))
Figure 2.2: Method of false position on [a, b]
The line passing through (a, f (a)) and (b, f (b)) has slope
𝑚=
𝑓(𝑏)−𝑓(𝑎)
𝑏−𝑎
0−𝑓(𝑎)
= 𝑥 −𝑎
(2.2)
0
Both are the slope of the same line, because the slope of a line is independent of the choice of the
points on the line
Now, solve for 𝑥1 from equation (2.2), to get the first approximation
That is, (𝑥0 − 𝑎)(𝑓(𝑏) − 𝑓(𝑎)) = (𝑏 − 𝑎)(−𝑓(𝑎))
⟹ 𝑥0 (𝑓(𝑏) − 𝑓(𝑎)) − 𝑎(𝑓(𝑏) − 𝑓(𝑎)) = −𝑏𝑓(𝑎) + 𝑎𝑓(𝑎)
⟹ 𝑥0 (𝑓(𝑏) − 𝑓(𝑎)) = 𝑎𝑓(𝑏) − 𝑎𝑓(𝑎) − 𝑏𝑓(𝑎) + 𝑓(𝑎)
⟹ 𝑥0 (𝑓(𝑏) − 𝑓(𝑎)) = 𝑎𝑓(𝑏) − 𝑏𝑓(𝑎)
Prepared by Abe N
10
NUMERICAL METHODS
⟹ 𝑥0 =
𝑎𝑓(𝑏)−𝑏𝑓(𝑎)
(2.3)
𝑓(𝑏)−𝑓(𝑎)
Alternatively, for a given interval [a, b], the equation of the straight line that connects point
(𝑎, 𝑓(𝑎)) to point (𝑏, 𝑓(𝑏)) is given by:
𝑦=
𝑓(𝑏)−𝑓(𝑎)
𝑏−𝑎
(𝑥 − 𝑏) + 𝑓(𝑏)
(2.4)
The point 𝑥1 where the line intersects the 𝑥 axis is determined by substituting 𝑦 = 0 in Eq. (2.4)
and solving the equation for 𝑥1 one can get
𝑥0 =
𝑎𝑓(𝑏) − 𝑏𝑓(𝑎)
𝑓(𝑏) − 𝑓(𝑎)
To find the next approximation, compute 𝑓(𝑥0 )
and check the sign changes, that is if
𝑓(𝑥0 )𝑓(𝑏) < 0 ,then the new interval containing the root is [𝑥1 , 𝑏] and set 𝑎 = 𝑥0 otherwise the
root lies in the interval [𝑎, 𝑥0 ] ,if so set 𝑏 = 𝑥0 .The end points of the second interval are
connected with a straight line ,and the point where this new line crosses the 𝑥 axis is the second
estimate of the solution 𝑥1 .For the third iteration a new sub interval selected and the iteration
continue in the same way until the numerical solution is deemed accurate enough.
Procedures in False position method to find the root of the 𝒇(𝒙) = 𝟎
Step 1: Choose the interval [a, b] such that𝑓(𝑎). 𝑓(𝑏) < 0
Step2: Find the first approximation using the formula 𝑥𝑖 =
𝑎𝑓(𝑏)−𝑏𝑓(𝑎)
𝑓(𝑏)−𝑓(𝑎)
and evaluate 𝑓(𝑥𝑖 ).
Step 3: If (𝑥𝑖 ) = 0 , the root is 𝑥𝑖 stop else If 𝑓(𝑎). 𝑓(𝑥𝑖 ) < 0,then set 𝑏 = 𝑥𝑖 else set 𝑎 = 𝑥𝑖 and
go back to step 2.
Step 4: Stop the evaluation when the given condition satisfied or the difference between two
successive approximation is less than the given tolerance i.e.|𝑥𝑖+1 − 𝑥𝑖 | <tolerance.
Examples 2.7: Find the root of the equation𝑥 3 − 𝑥 − 1 = 0 lying between 1 and 2 using false
position method.
Solution: let 𝑓(𝑥) = 𝑥 3 − 𝑥 − 1 = 0
Prepared by Abe N
11
NUMERICAL METHODS
Since 𝑓(1) = 13 − 1 − 1 = −1 < 0 and 𝑓(2) = 23 − 2 − 1 = 5 > 0 so at least one root lies in
the interval [1, 2].
First approximation: 𝑥1 =
𝑎𝑓(𝑏)−𝑏𝑓(𝑎)
𝑓(𝑏)−𝑓(𝑎)
=
5−2(−1)
5—1
7
= 6 = 1.16667
⟹ 𝑓(1.16667) = (1.16667)3 − 1.16667 − 1 = −0.578704, which is negative, so the root
now lies between [1.16667,2].
Set 𝑥1 = 𝑎and𝑏 = 2
𝑎𝑓(𝑏)−𝑏𝑓(𝑎)
Second iteration: 𝑥2 =
𝑓(𝑏)−𝑓(𝑎)
continue the process until you get the desired accuracy.
Using C++ program the iterations are givenin table 2.5:
Enter a, b, maximum iteration and allowed error:
1 2 18 0.0001
Since 𝑓(𝑎)𝑓(𝑏) < 0 ,aroot lies between a and b, the iterations are:
Table 2.5_________________________________________________
𝑖a
b
𝑥𝑖 𝑓(𝑥𝑖 )
_________________________________________________
1 1.000000
2.000000
1.166667
-0.578704
2
1.166667
2.000000
1.253112
-0.285363
3
1.253112
2.000000
1.293437
-0.129542
4
1.293437
2.000000
1.311281
-0.056588
5
1.311281
2.000000
1.318989
-0.024304
6
1.318989
2.000000
1.322283
-0.010362
7
1.322283
2.000000
1.323684
-0.004404
8
1.323684
2.000000
1.324279
-0.001869
9
1.324279
2.000000
1.324532
-0.000793
10
1.324532
2.000000
1.324639
-0.000336
Prepared by Abe N
12
NUMERICAL METHODS
11 1.324639
2.000000
1.324685
.000142__________________________________________________
The root converges after iteration 11, the root is 𝑥 =1.324685.
Example2.8: Find the solution of the equation 𝑓(𝑥) = 𝑥 3 + 4𝑥 2 − 10 in [1, 2] using false
position method with tolerance 0.0001.
Solution: The resultsusing C++programming are given in table 2.6.
Enter a, b, maximum iteration and allowed error:
1 2 10 0.0003
Since 𝑓(𝑎)𝑓(𝑏) < 0 ,aroot lies between a and b, the iterations are:
Table 2.6_____________________________________________
𝑖a
b
𝑥𝑖 𝑓(𝑥𝑖 )
______________________________________________
1
1.000000
2.000000
1.263158
-1.602275
2
1.263158
2.000000
1.338828
-0.430365
3
1.338828
2.000000
1.358546
-0.110010
4
1.358546
2.000000
1.363547
-0.027762
5
1.363547
2.000000
1.364807
-0.006982
6
1.364807
2.000000
1.365124
-0.001755
7
1.365124
2.000000
1.365203
-0.000442
_______________________________________________
The root converges after iteration 7, the root is 𝑥 =1.365203.
Example 2.9: Use the False position method to approximate the solution of the equation 𝑓(𝑥) =
𝑥 3 − 27𝑥 + 1 = 0 in [0,1] with |𝑥𝑖+1− 𝑥𝑖 | < 0.0005
Prepared by Abe N
13
NUMERICAL METHODS
Solution: The resultsusing C++programming are given in table 2.7.
Enter a, b, maximum iteration and allowed error:
0 1 8 0.0005
Since 𝑓(𝑎)𝑓(𝑏) < 0 , a root lies between a and b, the iterations are:
Table 2.7 _______________________________________________
ia
b
𝑥𝑖 𝑓(𝑥𝑖 )
________________________________________________________________
1
0.000000
1.000000
0.038462
-0.038405
2
0.000000
0.038462
0.037039
-0.000004
3
0.000000
0.037039
0.037039
0.000000
________________________________________________
The root converges after iteration 3, the root is𝑥 =0.03703892.
2.4.
Fixed-point iteration (1 hour)
Objective
At the end of this subtopic students should beable to:
Find the iteration function for a given equation.
Use fixed point iteration method to solve an equation of the form 𝑓(𝑥) = 0.
Identify the convergency condition.
In fixed-point iteration method, first rewrite the equation f ( x) 0 in the form x g ( x ) and
approximate the root using the formula in equation (2.5). The fixed -point iteration method starts
by taking an initial guess 𝑥0 to the root and continue our iteration until we get the desire solution.
𝑥𝑖+1 = 𝑔(𝑥𝑖 )𝑖 = 0,1,2 …
(2.5)
Here 𝑔(𝑥) is called the iteration function.
Prepared by Abe N
14
NUMERICAL METHODS
Theorem 2.2(Fixed-Point Theorem)
If 𝑔(𝑥) and 𝑔′ (𝑥) are continuous on an interval containing the root of the equation x g ( x ) ,
and if |𝑔′ (𝑥)| < 1 for all 𝑥 in the interval , then the sequence 𝑥𝑛+1 = 𝑔(𝑥𝑛 ) with initial guess
interval will converge to the root.
Example2.10:Find a root of 𝑓(𝑥) = −3𝑥 + 𝑒 𝑥 = 0 using fixed point iteration method in the
𝑒𝑥
interval [0,1]with 𝑔(𝑥) = 3 ,continue until|𝑥(𝑖+1) − 𝑥𝑖 | < 0.0005.
Solution: The resultsusing C++programming are given in table 2.8.
Enter x0, allowed error and maximum iteration:
0.5 0.0005 12
Table 2.8___________________________
i𝑥𝑖 𝑓(𝑥𝑖 )
______________________________________
0
0.500000
0.148721
1
0.549574
0.083793
2
0.577505
0.049073
3
0.593862
0.029382
4
0.603657
0.017824
5
0.609598
0.010898
6
0.613231
0.006695
7
0.615462
0.004125
8
0.616837
0.002546
9
0.617686
0.001573
10
0.618210
0.000973
11
0.618535
0.000602
_______________________________________
The root converges after 11 iterations, the root is 𝑥 = 0.618535.
Prepared by Abe N
15
NUMERICAL METHODS
2.5. Newton-Raphson method (2 hours)
Objective
At the end of this subtopic students should beable to:
Derive the formula of Newton-Rapson method.
Use Newton-Raphson method to find a root of an equation of the form 𝑓(𝑥) = 0.
Let 𝑥0 be an initial approximate root of 𝑓(𝑥) = 0 and 𝑥1 = 𝑥0 + ℎ such that 𝑓(𝑥1 ) = 0 and 𝑓 is
differentiable. Then, using Taylor series expansion 𝑓(𝑥) can be expanded as:
𝑓(𝑥) = 𝑓(𝑥0 ) + 𝑓 ′ (𝑥0 )(𝑥 − 𝑥0 ) + 𝑓 ′′ (𝑥0 )
(𝑥 − 𝑥0 )2
(𝑥 − 𝑥0 )𝑛
(𝑛)
+ ⋯ + 𝑓 (𝑥0 )
2!
𝑛!
Then, 𝑓(𝑥1 ) = 𝑓(𝑥0 ) + 𝑓 ′ (𝑥0 )(𝑥1 − 𝑥0 ) + 𝑓 ′′ (𝑥0 )
ℎ2
(𝑥1 −𝑥0 )2
2!
+ ⋯ + 𝑓 (𝑛) (𝑥0 )
(𝑥1 −𝑥0 )𝑛
𝑛!
ℎ𝑛
0= 𝑓(𝑥0 ) + 𝑓 ′ (𝑥0 )ℎ + 𝑓 ′′ (𝑥0 ) 2! + ⋯ + 𝑓 (𝑛) (𝑥0 ) 𝑛!
Now, neglect the second and higher order derivatives and we get
𝑓(𝑥0 ) + ℎ𝑓 ′ (𝑥0 ) = 0 ⟹ ℎ = −
⟹ 𝑥1 − 𝑥0 = −
𝑥2 = 𝑥1 −
𝑓(𝑥0 )
𝑓 ′ (𝑥0 )
𝑓(𝑥0 )
𝑓(𝑥0 )
⟹ 𝑥1 = 𝑥0 − ′
′
𝑓 (𝑥0 )
𝑓 (𝑥0 )
𝑓(𝑥1 )
𝑓(𝑥2 )
,
𝑥
=
𝑥
−
3
2
𝑓 ′ (𝑥1 )
𝑓 ′ (𝑥2 )
In general, the Newton Raphson method is given by:
𝑓(𝑥 )
𝑥𝑛+1 = 𝑥𝑛 − 𝑓′ (𝑥𝑛 ) , Provided that 𝑓 ′ (𝑥𝑛 ) ≠ 0
𝑛
(2.6)
The process terminates when two successive values of 𝑥𝑖 are nearly equal with the prescribed
error.
Procedurs in Newton-Raphson method to find the root of the equation 𝒇(𝒙) = 𝟎
Prepared by Abe N
16
NUMERICAL METHODS
Step 1: Choose a point 𝑥0 as an initial guess of the root.
Step 2: For 𝑖 = 0,1,2, …, until the error is smaller than a specified value calculates 𝑥𝑖+1 by using
Eq. (2.6)
Example 2.11: Solve the equation 𝑥 3 − 5𝑥 + 3 = 0 using Newton Raphson method with initial
point 𝑥0 = 0and𝜀 = 0.001.
Solution: Here, 𝑓(𝑥) = 𝑥 3 − 5𝑥 + 3, 𝑥0 = 0and 𝑓 ′ (𝑥) = 3𝑥 2 − 5, then
𝑥1 = 𝑥0 −
𝑓(𝑥0 )
𝑓(0)
=0− ′
= 0.6
′
𝑓 (𝑥0 )
𝑓 (0)
and|𝑥1 − 𝑥0 | = |0.6 − 0| = 0.6 > 0.001
𝑥2 = 𝑥1 −
𝑓(𝑥1 )
𝑓(0.6)
=
0.6
−
= 0.65510204
𝑓 ′ (𝑥1 )
𝑓 ′ (0.6)
and|𝑥2 − 𝑥1 | = |0.65510204 − 0.6| = 0.05510204 > 0.001
𝑥3 = 𝑥2 −
𝑓(𝑥2 )
𝑓(0.65510204)
= 0.65510204 − ′
= 0.656619
′
𝑓 (𝑥2 )
𝑓 (0.65510204)
and|𝑥3 − 𝑥2 | = |0.656619 − 0.65510204| = 0.00151696 > 0.001
𝑥4 = 𝑥3 −
𝑓(𝑥3 )
𝑓(0.656619)
=
0.656619
−
= 0.65662
𝑓 ′ (𝑥3 )
𝑓 ′ (0.656619)
and|𝑥4 − 𝑥3 | = |0.65662 − 0.656619| = 0.000001 < 0.001
Since,|𝑥4 − 𝑥3 | = 0.000001 < 0.001 = 𝜀, the process terminates and the approximate root is
𝑥4 = 0.65662.
Example2.12: Approximate a root of 𝑓(𝑥) = 𝑥 3 + 4𝑥 2 − 10 = 0 in the interval [1, 2] using
Newton-Raphson method continue your iteration until |𝑥𝑖+1 − 𝑥𝑖 | ≤ 0.000005.
Solution: The resultsusing C++programming are given in table 2.9.
Enter xo, allowed error and maximum iteration:
Prepared by Abe N
17
NUMERICAL METHODS
1.5 0.0000005 8
Table 2.9__________________________________________________
𝑖𝑓(𝑥𝑖−1 )𝑓′(𝑥𝑖−1 )𝑥𝑖 𝑓(𝑥𝑖 )
__________________________________________________
1 2.3750000 18.7500000 1.3733333
0.1343455
2
0.1343455
16.6448002
1.3652620
0.0005287
3
0.0005287
16.5139179
1.3652300
-0.0000002
4 -0.0000002 16.5133991 1.3652300
-0.0000002
__________________________________________________
The root converges after iteration 4, the root is 𝑥 = 1.3652300
Example2.13: Find the solution of the equation 𝑓(𝑥) = 𝑥 3 − 𝑥 − 1 = 0 using
Newton-Raphson method with tolerance 0. 000001.Take 𝑥0 = 1.5
Solution: The resultsusing C++programming are given in table 2.11.
Enter x0, allowed error and maximum iteration:
1.5 0.0000005 10
Table 2.11__________________________________________________
𝑖𝑓(𝑥𝑖−1 )
𝑓′(𝑥𝑖−1 )
𝑥𝑖 𝑓(𝑥𝑖 )
__________________________________________________
1 0.8750000 5.7500000 1.3478261
0.1006823
2
0.1006823
4.4499059
1.3252004
0.0020585
3
0.0020585
4.2684684
1.3247181
0.0000007
4 0.0000007 4.2646341 1.3247180
0.0000002
__________________________________________________
The root converges after iteration 4, the root is 𝑥 =1.3247180
Example2.14: Find a root of the equation 𝑓(𝑥) = 𝑒 𝑥 + 2−𝑥 + 2𝑐𝑜𝑠𝑥 − 6 using NewtonRaphson method with tolerance 0. 000001.Take 𝑥0 = 0
Solution: The resultsusing C++programming are given in table 2.12.
Enter xo, allowed error and maximum iteration respectively:
Prepared by Abe N
18
NUMERICAL METHODS
0 0.000001 12
Table 2.12__________________________________________________
𝑖𝑓(𝑥𝑖−1 ) 𝑓′(𝑥𝑖−1 )𝑥𝑖 𝑓(𝑥𝑖 )
_________________________________________________
1 -2.0000000 1.6931472 1.1812322
-1.5410681
2 -1.5410681
1.7138977
2.0803921
1.2684095
3
1.2684095
6.4256196
1.8829933
0.2299713
4
0.2299713
4.8577557
1.8356522
0.0258462
5
0.0258462
4.5331569
1.8299507
0.0023270
6
0.0023270
4.4953299
1.8294331
0.0002030
7
0.0002030
4.4919090
1.8293879
0.00001762
8
0.0000176
4.4916105
1.8293840
0.0000015
9
0.0000015
4.4915843
1.8293836
0.0000000
__________________________________________________
The root converges after iteration 9, the root is 𝑥 =1.8293836
Example 2.15: Use the Newton- Raphson method to approximate the solution of the equation
𝑓(𝑥) = 𝑥 3 − 27𝑥 + 1 = 0 in [0,1] with |𝑥𝑖+1− 𝑥𝑖 | < 0.0000005
Solution: The resultsusing C++programming are given in table 2.13.
Enter xo, allowed error and maximum iteration:
0.5 0.0000005 6
Table2.13_____________________________________________________
𝑖𝑓(𝑥𝑖−1 ) 𝑓′(𝑥𝑖−1 )𝑥𝑖 𝑓(𝑥𝑖 )
_____________________________________________________
1 -12.3750000 -26.2500000 0.0285714
0.2285948
2
0.2285948
-26.9975510
0.0370387
0.0000067
3 0.0000067
-26.9958839 0.0370389
0.0000000
_____________________________________________________
The root converges after iteration 3, the root is 𝑥 = 0.0370389
Prepared by Abe N
19
NUMERICAL METHODS
2.6. Secantmethod (1 hour)
Objective
At the end of this subtopic students should beable to:
Use secant method to find a root of an equation of the form 𝑓(𝑥) = 0.
Identify the difference between false position and secant method.
Newton Raphson method is very powerful, but the evaluation of the derivatives involved
sometimes may be difficult. This suggests the idea of replacing the derivative 𝑓 ′ (𝑥𝑛 ) in
Newton –Rapsonformula, given below,
𝑓(𝑥 )
𝑥𝑖+1 = 𝑥𝑖 − 𝑓′ (𝑥𝑖 ) (2.7)
𝑖
By the difference quotient
𝑓 ′ (𝑥𝑖 ) =
𝑓(𝑥𝑖 ) − 𝑓(𝑥𝑖−1 )
𝑥𝑖 − 𝑥𝑖−1
Thus, instead of equation (2.7), we have
𝑓(𝑥𝑖 )
𝑥𝑖+1 = 𝑥𝑖 − 𝑓(𝑥 )−𝑓(𝑥
𝑖
𝑖−1 )
𝑥𝑖 −𝑥𝑖−1
𝑥 −𝑥
𝑖
𝑖−1
𝑥𝑖+1 = 𝑥𝑖 − 𝑓(𝑥 )−𝑓(𝑥
𝑖
𝑖−1 )
𝑓(𝑥𝑖 )
(2.8)
Equation (2.8) is called secant method
Example2.16: Solve the equation 𝑓(𝑥) = 𝑥 2 − 25 = 0 using secant method with 𝑥0 = 4, 𝑥1 =
7and 𝜀 = 0.05.
Solution: Here 𝑓(𝑥) = 𝑥 2 − 25, 𝑥0 = 4, 𝑥1 = 7 and 𝜀 = 0.05
𝑥𝑖+1 =
𝑥2 =
(𝑥𝑖−1 )𝑓(𝑥𝑖 ) − 𝑥𝑖 𝑓(𝑥𝑖−1 )
𝑓(𝑥𝑖 ) − 𝑓(𝑥𝑖−1 )
𝑥0 𝑓(𝑥1 ) − 𝑥1 𝑓(𝑥0 ) 4𝑓(7) − 7𝑓(4)
=
= 4.81818182
𝑓(𝑥1 ) − 𝑓(𝑥0 )
𝑓(7) − 𝑓(4)
Prepared by Abe N
20
NUMERICAL METHODS
𝑒1 = |𝑥2 − 𝑥1 | = |4.81818182 − 7| = 2.1818182 > 0.05
𝑥3 =
𝑥1 𝑓(𝑥2 ) − 𝑥2 𝑓(𝑥1 ) 7𝑓(4.81818182) − 4.81818182𝑓(7)
=
= 4.96923075
𝑓(𝑥2 ) − 𝑓(𝑥1 )
𝑓(4.81818182) − 𝑓(7)
𝑒2 = |𝑥3 − 𝑥2 | = |4.96923075 − 4.81818182| = 0.151048913 > 0.05
𝑥4 =
𝑥2 𝑓(𝑥3 ) − 𝑥3 𝑓(𝑥2 ) 4.81818182𝑓(4.96923075) − 4.96923075𝑓(4.81818182)
=
𝑓(𝑥3 ) − 𝑓(𝑥2 )
𝑓(4.96923075) − 𝑓(4.81818182)
= 5.00057164
𝑒3 = |𝑥4 − 𝑥3 | = |5.00057164 − 4.96923075| = 0.03134089 < 0.05
Since 𝑒3 = 0.03134089 < 0.05 = 𝜀, the process terminates and the approximate root of the
equation is 𝑥4 = 5.00057164.
Example2.17: Find a root of the equation 𝑓(𝑥) = 𝑥 3 − 𝑥 − 4 = 0 in the interval [1,2] using
a. Bisection Method.
b. False position Method
c. Newton –Raphson Method
Solution a: The resultsusing C++programming are given in table 2.14.
Enter the interval [a, b], maximum iteration and allowed error respectively.
1 2 15 0.0005
Since 𝑓(𝑎)𝑓(𝑏) < 0 ,a root lies between a and b the iterations are:
Table 2.14_____________________________________________________
𝑖a
b
𝑥𝑖 𝑓(𝑥𝑖 )
|𝑥𝑖+1 − 𝑥𝑖 |
_____________________________________________________
0 1.00000
2.00000
1.50000
-2.12500
1 1.50000
2.00000
1.75000
-0.39063
0.25000
2 1.75000
2.00000
1.87500
0.71680
0.12500
3 1.75000
1.87500
1.81250
0.14185
0.06250
4 1.75000
1.81250
1.78125
-0.12961
0.03125
5 1.78125
1.81250
1.79688
0.00480
0.01563
Prepared by Abe N
21
NUMERICAL METHODS
10 1.79590
6 1.78125
1.79688
1.78906
-0.06273
0.00781
7 1.78906
1.79688
1.79297
-0.02905
0.00391
8 1.79297
1.79688
1.79492
-0.01214
0.00195
9 1.79492
1.79688
1.79590
-0.00367
0.00098
1.79688
1.79639
0.00056
0.00049
_______________________________________________________
The root converges after iteration 10, the root is x= 1.79639.
Solution b: The resultsusing C++programming are given in table 2.15.
Enter a, b, maximum iteration and allowed error:
1 2 12 0.0005
Since 𝑓(𝑎)𝑓(𝑏) < 0 ,aroot lies between a and b, the iterations are:
Table 2.16______________________________________________
𝑖a
b
𝑥𝑖 𝑓(𝑥𝑖 )
_______________________________________________
1 1.000000
2.000000
1.666667
-1.037037
2 1.666667
2.000000
1.780488
-0.136098
3
1.780488
2.000000
1.794474
-0.016025
4
1.794474
2.000000
1.796107
-0.001862
5 1.796107
2.000000
1.796297
-0.000217
_______________________________________________
The root converges after iteration 5, the root is 𝑥 =1.79629695
Solution c: The resultsusing C++programming are given in table 2.17.
Enter𝑥0 , allowed error and maximum iteration:
1.5 0.0005 8
Table 2.17_________________________________________________
𝑖𝑓(𝑥𝑖−1 )
𝑓′(𝑥𝑖−1 )
𝑥𝑖 𝑓(𝑥𝑖 )
_________________________________________________
1 -2.1250000 5.7500000 1.8695652
0.6650780
2
0.6650780
9.4858227
1.7994524
Prepared by Abe N
0.0272268
22
NUMERICAL METHODS
3
0.0272268
8.7140875
1.7963279
0.0000525
4
0.0000525
8.6803827
1.7963219
-0.0000003
_________________________________________________
The root converges after iteration 4, the root is 𝑥 = 1.7963219.
Summary
Bisection, false position methods are bracketing methods, that is it starts by choosing an
interval [𝑎, 𝑏] contaning a root.
Newton-Raphson and fixed-point iteration methods are commonly known as open
methods. These method starts the iteration by taking an initial guess to the root.
Review exercise 2
1. Using bisection method find a root of the equation 𝑓(𝑥) = 𝑥sin𝑥 − 1 = 0 that lies in
[1,1.5].Compute the first four iterations.
2. Find a root of the equation𝑓(𝑥) = 𝑥 3 − 9𝑥 + 1 = 0 in [2.5,3] by using bisection method
with tolerance 0.005.
3.
Find a root of the equation𝑓(𝑥) = 𝑥 3 − 3𝑥 − 5 = 0 in [2,3] by using false position method
with tolerance 0.005.
4.
Find the real root of the equation 𝑓(𝑥) = 3𝑥 − cos𝑥 − 1 = 0 using Newton-Raphson
method take 𝑥0 = 0.5,with tolerance 0.00005.
5. Determinethe number of iterationsrequired to solve 𝑓(𝑥) = 𝑥 3 + 𝑥 2 − 10 = 0 with
tolerance of error 10−5in the interval[1,2].
Prepared by Abe N
23
NUMERICAL METHODS
CHAPTER THREE
SYSTEMS OF LINEAR EQUATIONS
3.1.
Introduction
System of linear equations that have to be solved simultaneously arise in problems that include
several variables that are dependent on each other. Such problems occure not only in engineering
and scince, but also in any discipline such as bussines, statistics, economics, etc. A system of two
or three equations with two or three unknowns can be solved simultinuoesly but solving a system
in this way is practicaliy impossible as the number of equations (unknowns) increase byoned
three.
Objective
At the end of this unit students shoud be able to:
Understand what is meant by system of equations and augmented matrix.
solve system of linear equation using direct method such as Gauss-elimination,
Gauss-Jordan elimination and LU decomposition method.
Use Thomas Algorithm to solve tridiagonal system of linear equations.
Use iterative methods to solve system of linear equation.
Identify the convergence condition for iterative methods.
Solve system of non-linear equations.
Allowted time to complete this chapter is 14 hours
Activity 3.1
Solve the following system of nonlinear equations.
𝑥 2 + 2𝑥 + 2𝑦 2 − 26 = 0
2𝑥 3 − 𝑦 2 + 4𝑦 − 19 = 0
Prepared by Abe N
24
NUMERICAL METHODS
The general form of a system of m equations with n unknowns (variables) is:
a11 x1 a12 x2 a13 x3 ...a1n xn b1
a 21 x1 a 22 x2 a 23 x3 ... a 2 n xn b2 (3.1)
.
a m1 x1 a m 2 x2 a m 3 x3 ... a mn xn bn
x1
a11 a12 a13 ...a1n
x
b1
2
b then
Now define the matrices A a 21 a 22 a 23 .... a 2 n , X . , and
2
b
.
a m1 a m 2 a m 3 ..a mn
bn
xn
a11
AX a 21
a m1
a12
a 22
am2
x a11 x1 a12 x 2 a13 x3 ... a1n x n b1
1
a 21 x1 a 22 x 2 a 23 x3 ... a 2 n x n b 2
a 23 .... a 2 n
x
2
a m 3 ..a mn x n a m1 x1 a m 2 x 2 a m 3 x3 ... a mn x n b n
a13 ...a1n
a11 a12 a13 ...a1n
The matrix
a22 a23 .... a2 n is called the coefficient matrix of the system (3.1)
a
A 21
.
am1 am 2 am 3 ..amn
x1
The column matrix X x 2 is the matrix of unknown.
xn
a11 a12 a13 ...a1n
a 22 a 23 .... a 2 n
a
[ A b] 21
a m1 a m 2 a m 3 ..a mn
b1
b2 is called the augmented
bn
matrix of the linear system (3.1)
Remark: If bi 0, i 1,2,...n then the linear system (3.1) is called Homogenous otherwise, nonHomogenous
Prepared by Abe N
25
NUMERICAL METHODS
Theorem3.1: If [ A b] and [C d ] are row equivalent, then the systems AX b and CX d
have exactly the same solutions.
Remark: If A is an m by n matrix then the linear system AX O has trivial solution X O .
3.2.
Direct methods to solve a linear system of equations (8 hours)
Objective
At the end of this topic students shoud be able to:
solve system of linear equation using direct method such as Gauss-elimination,
Gauss-Jordan elimination and LU decomposition method.
Use Thomas Algorithm to sovletridiagonal system of linear equations.
3. 2.1. Gaussian elimination (2 hours)
Objective
At the end of this subtopic students shoud be able to:
Understand what is meant by system of equations and augmented matrix.
solve system of linear equation using direct method such as Gauss-elimenation,
method.
Basic steps in Gauss- elimination method
Step 1: Form the augmented matrix [ A b]
Step 2: Transform [ A b] to row echelon form [C d ] using row operations.
Step 3: Solve the system CX d by back substitution.
Example3.1: Solve the following system using Gauss elimination method.
Prepared by Abe N
26
NUMERICAL METHODS
2 x3 3 x 2 x3 5
4 x1 14x2 12x3 10
6 x1 x2 5 x3 9
2 3 1 5
Solution: The augmented matrix of the system is 4 14 12 10
6 1 5 9
Applying, elementary row operations on this matrix to change into its echelon form.
2 3 1 5
2 3 1 5
2 3 1 5 R R 2 R
1
4 14 12 10 R R 3 R 0 20 10 0 R3 R3 2 R2 0 20 10 0
0 10 2 6
0 0 3 6
6 1 5 9
2
2
1
3
3_
1
Since rank ( [ A b] )=rank ( A ) 3 n the solution exists and is unique.
Hence the above equation is reduced to
2 x1 3 x 2 x3 5
20x 2 10x3 0
3 x 3 6
From this we get x3 2 and using backsubstitution we have x 2 1 and x1 0
Hence 0, 1, 2 is the solution of the system.
Example 3.2: Apply Gauss elimination method to solve the equations
𝑥 + 4𝑦 − 𝑧 = −5;
𝑥 + 𝑦 − 6𝑧 = −12;
3𝑥 − 𝑦 − 𝑧 = 4
We have
𝑥 + 4𝑦 − 𝑧 = −5
( 𝑖)
𝑥 + 𝑦 − 6𝑧 = −12 ( 𝑖𝑖)
Prepared by Abe N
27
NUMERICAL METHODS
3𝑥 − 𝑦 − 𝑧 = 4
(𝑖𝑖𝑖)
Step І: to eliminate𝑥, operate (𝑖𝑖) − (𝑖) and (𝑖𝑖𝑖) − 3(𝑖)
−3𝑦 − 5𝑧 = −7
( 𝑖𝑣)
−13𝑦 + 2𝑧 = 19
( 𝑣)
13
Step ІІ: to eliminate𝑦, operate(𝑣) − 3 (𝑖𝑣)
71
148
𝑧=
3
3
(𝑣𝑖)
Step ІІІ:by back substitution, we get
148
From(𝑣𝑖)𝑧 = 71 = 2.0845
7
5 148
−81
From(𝑖𝑣)𝑦 = 3 − 3 ( 71 ) = 71 = −1.1408
−81
148
117
From(𝑖) 𝑥 = −5 − 4 ( 71 ) + 71 = 71 = 1.6479
Hence, 𝑥 = 1.6479, 𝑦 = −1.1408, 𝑧 = 2.0845
Example 3.3: Solve the following system of equations using Gauss-elimination method.
𝑥 + 2𝑦 + 3𝑧 − 𝑢 = 10
2𝑥 − 𝑦 + 2𝑧 + 3𝑦 = 7
3𝑥 + 2𝑦 − 4𝑧 + 3𝑢 = 2
1 2
3 −1 𝑥
10
2 3 −3 −1 𝑦
1
Solution: we have [
][ ] = [ ]
𝑧
2 −1 2
3
7
3 2 −4 3 𝑢
2
Operate 𝑅2 − 2𝑅1 , 𝑅3 − 2𝑅1 , 𝑅4 − 3𝑅1
1
0
[
0
0
2
3
−1 𝑥
−10
−1 −9
1 𝑦
−19
][ ] = [
]
−5 −4
5 𝑧
−13
−4 −13 6 𝑢
−28
Prepared by Abe N
28
NUMERICAL METHODS
Operate 𝑅3 − 5𝑅2 , 𝑅4 −4𝑅2
1 2
0 −1
[
0 0
0 0
3 −1 𝑥
10
−9 1 𝑦
−19
][ ] = [
]
41 0 𝑧
82
23 2 𝑢
48
Thus, we have 41𝑧 = 82 i.e. 𝑧 = 2
23𝑧 + 2𝑢 = 48 i.e, 46 + 2𝑢 = 48 ∴ 𝑢 = 1
−𝑦 − 9𝑧 + 𝑢 = −19 i.e, – 𝑦 − 18 + 1 = −19 ∴ 𝑦 = 2
𝑥 + 2𝑦 = 3𝑧 − 𝑢 = 10 i.e, 𝑥 + 4 + 6 − 1 = 10 ∴ 𝑥 = 1
Hence 𝑥 = 1, 𝑦 = 2, 𝑧 = 2, 𝑢 = 1
3.2.2. Gauss- Jordan elimination (2 hours)
Objective
At the end of this subtopic students shoud be able to:
Understand what is meant by reduced row echelon form of a matrix.
Solve system of linear equation using Gauss-Jordan elimination method.
Basic steps in Gauss-Jordan elimination method
Step 1: Form the augmented matrix [ A b]
Step 2: Transform [ A b] to reduced row echelon form [C d ] using row operations.
Step 3: Solve the system CX d .
Example3.4: Solve the following system by Gauss-Jordan elimination method.
2 x1 3 x 2 4 x3 19
x1 2 x 2 x3 4
3 x1 x 2 x3 9
Prepared by Abe N
29
NUMERICAL METHODS
2 3 4 19
Solution: The augmented matrix of the system is 1 2 1 4 .
3 1 1 9
1 4
2 3 4 19
1 2 1 4 R2 R2 2 R1 1 2
R 1 R2
1 2 1 4
R3 R3 3 R1
2 3 4 19
0 1 2 11
0 7 4 3
3 1 1 9
3 1 1 9
1
4
1
4
1 2
1 2
1
R3 18
R
R3 R3 7 R2
0 1 2 11
0 1 2 11
3
0 7 4 3
0 0 18 80
4
26 R1 R1 5 R3 1 0 0 34 / 9
1 0 5
1 2 1
R 2 2 R3
0 1 2 11
R1 R1 2R2
0 1 2 11 R
2
0 1 0 19 / 9
0 0 1 40 / 9
0 0 1 40 / 9
0 0 1 40 / 9
R 2 R2
Hence the above system is reduced to
34
19
40
𝑥1 = 9 ,𝑥2 = − 9 ,and 𝑥3 = 9 is the solution of the system.
3.2.3 Solution of a tri-diagonal system (2 hours)
Objective
At the end of this subtopic students shoud be able
Understand what is meant by tridiagonal system of equation.
Use Thomas Algorithm to solve tridiagonal system of linear equations.
Definition 3.2.1: Let 𝐴 = (𝑎𝑖𝑗 )be a square matrix of order n. Then A is called a tri-diagonal
matrix if 𝑎𝑖𝑗 = 0 whenever|𝑖 − 𝑗| > 1.
1 2 0
Example3.4: A= 3 4 5 is a tri-diagonal matrix.
0 6 7
Prepared by Abe N
30
NUMERICAL METHODS
3.2.4. Thomas method
Consider the problem of solving the linear system
𝐴𝑌 = 𝐷
b1
a 2
0
Where 𝐴 = 0
0
c 0
b c 0
a b c
1
2
3
2
3
0
3
a
b
a
n 1
0
n 1
n
0
y
1
y2
Y
0
y
n 1
cn1
y n
bn
d1
d2
D
d n 1
dn
And 𝑎𝑖, 𝑏𝑖, 𝑐𝑖 are enters of their respective row and column.
Solution of a tridiagonalsystem is obtained by using ,the
steps:
, following ,three
;,
𝑐
𝑐
Step1: take 𝛼1 = 𝑏1 and 𝛼𝑖 = 𝑏 −𝑎 𝑖𝛼
1
𝑑
𝑖
𝑖 𝑖−1
, 𝑖 = 2,3, … , 𝑛 − 1
𝑑 −𝑎 𝛽
Step2: take 𝛽1 = 𝑏1 , 𝛽𝑖 = 𝑏𝑖−𝑎𝑖𝛼𝑖−1 , 𝑖 = 2,3, … , 𝑛
1
𝑖
𝑖 𝑖−1
Step3: take𝑦𝑛 = 𝛽𝑛 and𝑦𝑖 = 𝛽𝑖 − 𝛼𝑖 𝑦𝑖+1 , 𝑖 = 𝑛 − 1, 𝑛 − 2, … ,1 (back substitution)
This algorithm is known as Thomas algorithm, which is the simplified form of Gauss elimination
Example 3.5: Solve the following tri-diagonal system using Thomas algorithm.
2𝑥1 − 𝑥2 = 1
−𝑥1 + 2𝑥2 − 𝑥3 = 0
−𝑥2 + 2𝑥3 − 𝑥4 = 0
−2𝑥3 + 2𝑥4 = 1
Solution:
Prepared by Abe N
31
NUMERICAL METHODS
x1
0
2 1 0
1
1 2 1 0
0
; D ;𝑋 = x 2
A
x
0 1 2 1
0
3
0
0
2
2
1
x 4
⇒ 𝑏1 = 𝑏2 = 𝑏3 = 𝑏4 = 2; 𝑐1 = 𝑐2 = 𝑐3 = −1and 𝑎2 = 𝑎3 = −1;𝑎4 = −2.
𝑐
1
𝑐
2
𝑐
3
Step1:𝛼1 = 𝑏1 = − 2; 𝛼2 = 𝑏 −𝑎2 𝛼 = − 3 and 𝛼3 = 𝑏 −𝑎3 𝛼 = − 4
1
𝑑
2
1
2 1
𝑑 −𝑎 𝛽
3
1
𝑑3−𝑎 𝛽
3 2
𝑑4−𝑎 𝛽
1
Step2:𝛽1 = 𝑏1 = 2;𝛽2 = 𝑏2−𝑎2𝛼1 = 3 and 𝛽3 = 𝑏 −𝑎3 𝛼2 = 4;𝛽4 = 𝑏 −𝑎4 𝛼3 = 3
1
2
2 1
3
3 2
1
3
4
4 3
10
Step3: take𝛽4 = 𝑥4 = 3 and 𝑥3 = 𝛽3 − 𝛼3 𝑥4 = 4 — 4 (3) = 4 = 2.5
1 2
6
𝑥2 = 𝛽2 − 𝛼2 𝑥3 = — (2.5) = = 2;
3 3
3
𝑥1 = 𝛽1 − 𝛼1 𝑥2 =
1
1
3
− (− ) (2) = = 1.5
2
2
2
1.5
2
Therefore, the solution is X
2 .5
3
3.2.5 Lu Decomposition Method (2 hours)
Objective
At the end of this subtopic students shoud be able to:
Understand what is meant by lower triangular and upper triangular matrix.
Solve system of linear equation using LU decomposition method.
Prepared by Abe N
32
NUMERICAL METHODS
The LU decomposition method is a method for solving a system of linear equations of the form
𝐴𝑋 = 𝑏.In this method the matrix of coefficient 𝐴 is decomposed (factored) in to a product of
two matrices L and U.
𝐴 = 𝐿𝑈 (3.2)
Where the matrix 𝑳 is lower triangular and 𝑼 is upper triangular matrix. With this
decomposition, the system of equations to be solved has the form:
𝐿𝑈𝑋 = 𝑏 (3.3)
To solve this equation, the product 𝑈𝑋 is defined as:
𝑈𝑋 = 𝑌 (3.4)
and substituted in Eq. (3.3) to get:
𝐿𝑌 = 𝑏 (3.5)
Now, the solution 𝑥is obtained in two steps. First Eq. (3.5) is solved for 𝑌.Then the solution 𝑌 is
substituted in Eq. (3.4) and the resulting equation is solved for 𝑋.
Since 𝐿 is a lower triangular matrix, the solution 𝑌 in Eq. (3.5) is obtained by using forward
substitution method. Once𝑌 is known and substituted in Eq. (3.4), the resulting equation is
solved by using back substitution, since 𝑈 is upper triangular matrix.
3.2.6. Crout’s LU decomposition method
In crout’s decomposition, the main diagonals of U the upper triangular matrix is 1’s
To illustrate the method, considera system of threeequations
𝑎11 𝑥1 + 𝑎12 𝑥2 + 𝑎13 𝑥3 = 𝑏1
𝑎21 𝑥1 + 𝑎22 𝑥2 + 𝑎23 𝑥3 = 𝑏2
𝑎31 𝑥1 + 𝑎32 𝑥2 + 𝑎33 𝑥3 = 𝑏3
Prepared by Abe N
33
NUMERICAL METHODS
The above system can be writtenas
𝐴𝑋 = 𝐵
𝐴 = 𝐿𝑈 ⟹ 𝐿𝑈𝑋 = 𝐵
Let 𝑈𝑋 = 𝑌 ⇒ 𝐿𝑌 = 𝐵
𝑙11
𝐿𝑌 = (𝑙21
𝑙31
0
𝑙22
𝑙32
𝑦1
0
𝑏1
𝑦
0 ) ( 2 ) = (𝑏2 )
𝑙33 𝑦3
𝑏3
One can solve for Y using forward substitution, then
𝑈𝑋 = 𝑌
1 𝑢12
⟹ 𝑈𝑋 = (0 1
0 0
𝑎11
Where𝐴 = (𝑎21
𝑎31
𝑙11
𝐿 = (𝑙21
𝑙31
0
𝑙22
𝑙32
𝑎12
𝑎22
𝑎32
𝑎13
𝑥1
𝑏1
𝑎23 ),𝑋 = (𝑥2 )and𝐵 = (𝑏2 )
𝑎33
𝑥3
𝑏3
0
1
0 ) , 𝑈 = (0
𝑙33
0
𝑢12
1
0
𝑢13
𝑢23 )
1
𝑙11
𝐴 = 𝐿𝑈 = (𝑙21
𝑙31
0
0
1
0 ) (0
𝑙33 0
𝑎11
(𝑎21
𝑎31
𝑦1
𝑢13 𝑥1
𝑥
𝑦
𝑢23 ) ( 2 ) = ( 2 )
𝑥3
𝑦3
1
𝑎12
𝑎22
𝑎32
𝑙22
𝑙32
𝑎13
𝑙11
𝑎23 ) = (𝑙21
𝑎33
𝑙31
𝑢12
1
0
𝑎11
𝑢13
𝑢23 ) = (𝑎21
𝑎31
1
𝑙11 𝑢12
𝑙21 𝑢12 + 𝑙22
𝑙31 𝑢12 + 𝑙32
𝑎12
𝑎22
𝑎32
𝑎13
𝑎23 )
𝑎33
𝑙11 𝑢13
𝑙21 𝑢13 + 𝑙22 𝑢23 )
𝑙31 𝑢13 + 𝑙32 𝑢23 + 𝑙33
Now by comparing the elements of both sides
First column
𝑙11 = 𝑎11 , 𝑙21 = 𝑎21 , 𝑙31 = 𝑎31
First row
Prepared by Abe N
34
NUMERICAL METHODS
𝑙11 𝑢12 = 𝑎12 ⇒ 𝑢12 =
𝑎12
𝑎13
; 𝑙11 𝑢13 = 𝑎13 ⇒ 𝑢13 =
𝑙11
𝑙11
Second column
𝑙21 𝑢12 + 𝑙22 = 𝑎22 ⇒ 𝑙22 = 𝑎22 − 𝑙21 𝑢12 ; 𝑙31 𝑢12 + 𝑙32 = 𝑎32 ⇒ 𝑙32 = 𝑎32 − 𝑙31 𝑢12
Second row
𝑙21 𝑢13 + 𝑙22 𝑢23 = 𝑎23 ⇒ 𝑢23 = 𝑎23 −
𝑙21 𝑢13
𝑙22
Third row
𝑙31 𝑢13 + 𝑙32 𝑢23 + 𝑙33 = 𝑎33 ⇒ 𝑙33 = 𝑎33 − 𝑙31 𝑢13 − 𝑙32 𝑢23
Steps in LU decomposition
Step 1: Express the given system in the form 𝐴𝑋 = 𝐵
Step 2: Put 𝐴 = 𝐿𝑈 where L is lower triangular matrix and U is upper triangular matrix whose
every diagonal element is 1.
Step 3: Find the product LU and by setting 𝐴 = 𝐿𝑈 fined the elements of each.
Step 4: Set 𝑈𝑋 = 𝑌 ⇒ 𝐿𝑌 = 𝐵 and solve for Y using forward substitution.
Step5: solve 𝐿𝑋 = 𝑌 using back substitution.
Note: the method works when 𝑙𝑖𝑖 ≠ 0, ∀𝑖.if this happen rearrange the coefficient matrix 𝐴 so that
𝑙𝑖𝑖 ≠ 0 during decomposition if possible.
Example3.6: Solve the following system of equation using Crout’s decomposition method.
2𝑥1 − 3𝑥2 + 𝑥3 = 5
2𝑥1 + 7𝑥2 + 6𝑥3 = 5
6𝑥1 + 𝑥2 + 5𝑥3 = 9
Solution:
Prepared by Abe N
35
NUMERICAL METHODS
𝑙11
2 −3 1
𝐴 = (2 7 6) = (𝑙21
𝑙31
6 1 5
𝑙11 𝑢12
𝑙21 𝑢12 + 𝑙22
𝑙31 𝑢12 + 𝑙32
𝑙11 𝑢13
𝑙21 𝑢13 + 𝑙22 𝑢23 )
𝑙31 𝑢13 + 𝑙32 𝑢23 + 𝑙33
First column
𝑙11 = 2, 𝑙21 = 2 , 𝑙31 = 6
First row
𝑙11 𝑢12 = 𝑎12 ⇒ 𝑢12 =
𝑎12
3
=−
𝑙11
2
𝑙11 𝑢13 = 𝑎13 ⇒ 𝑢13 =
𝑎13 1
=
𝑙11 2
Second column
3
𝑙21 𝑢12 + 𝑙22 = 𝑎22 ⇒ 𝑙22 = 𝑎22 − 𝑙21 𝑢12 = 7 − 2 (− ) = 10
2
3
𝑙31 𝑢12 + 𝑙32 = 𝑎32 ⇒ 𝑙32 = 𝑎32 − 𝑙31 𝑢12 = 1 − 6 (− ) = 10
2
Second row
𝑙21 𝑢13 + 𝑙22 𝑢23 = 𝑎23 ⇒ 𝑢23 = 𝑎23 −
𝑙21 𝑢13 6 − 1 1
=
=
𝑙22
10
2
Third row
1
1
𝑙31 𝑢13 + 𝑙32 𝑢23 + 𝑙33 = 𝑎33 ⇒ 𝑙33 = 𝑎33 − 𝑙31 𝑢13 − 𝑙32 𝑢23 = 5 − 6 ( ) − 10 ( ) = −3
2
2
2
Hence,𝐴 = 𝐿𝑈 = (2
6
0
0
1 −1.5 0.5
)
(
10 0
0
1
0.5)
10 −3 0
0
1
2
𝐿𝑌 = 𝐵 ⇒ (2
6
𝑦1
0
0
5
𝑦
)
(
)
=
(
10 0
2
5)
𝑦
10 −3
3
9
Prepared by Abe N
36
NUMERICAL METHODS
5
2
⇒ 𝑦1 =
2𝑦1 + 10𝑦2 = 5 ⇒ 𝑦2 = 0
5
2
6𝑦1 + 10𝑦2 − 3𝑦3 = 9 ⇒ 𝑦3 = 2.Therefore 𝑌 = (0)
2
Now,𝑈𝑋 = 𝑌 that is:
1 −1.5 0.5 𝑥1
2.5
(0
1
0.5) (𝑥2 ) = ( 0 )
𝑥3
0
0
1
2
3
1
5
𝑥1 − 𝑥2 + 𝑥3 =
2
2
2
1
𝑥2 + 𝑥3 = 0
2
𝑥3 = 2
1
𝑥2 + 2 𝑥3 = 0 ⇒ 𝑥2 = −1Back substitution
0
𝑥1 − 2 𝑥2 + 2 𝑥3 = 2 ⇒ 𝑥1 = 0. Therefore, the solution vector is 𝑋 = (−1)
2
3
1
5
The 𝐿𝑈 decomposition performed by setting the main diagonal elements of the lower triangular
matrix 𝐿 one is known as Doolittle’s method
3.3. Iterative methods (4 hours)
Objective
At the end of this subtopic students shoud be able to:
Understand what is meant by iterative method.
Prepared by Abe N
37
NUMERICAL METHODS
Use iterative methods to solve system of linear equation.
Identify the convergence condition for iterative methods.
A system of linear equations can also be solved by using iterative approach. The process, in
principle is the same as in the fixed-point iteration method for a single none linear equation (in
chapter2).in iterative method the equations are written in an explicit form in which each
unknown in terms of the other unknown. The explicit form for a system of four equations is
illustrated below.
𝑎11 𝑥1 + 𝑎12 𝑥2 + 𝑎13 𝑥3 + 𝑎14 𝑥4 = 𝑏1
𝑎21 𝑥1 + 𝑎22 𝑥2 + 𝑎23 𝑥3 + 𝑎24 𝑥4 = 𝑏2
𝑎31 𝑥1 + 𝑎32 𝑥2 + 𝑎33 𝑥3 + 𝑎34 𝑥4 = 𝑏3
𝑎41 𝑥1 + 𝑎42 𝑥2 + 𝑎43 𝑥3 + 𝑎44 𝑥4 = 𝑏4
When writing the system in an explicit form:
𝑥1 = [𝑏1 − (𝑎12 𝑥2 + 𝑎13 𝑥3 + 𝑎14 𝑥4 )]/𝑎11
𝑥2 = [𝑏2 − (𝑎21 𝑥1 + 𝑎23 𝑥3 + 𝑎24 𝑥4 )]/𝑎21
𝑥3 = [𝑏3 − (𝑎31 𝑥1 + 𝑎32 𝑥2 + 𝑎34 𝑥4 )]/𝑎33
𝑥4 = [𝑏4 − (𝑎41 𝑥1 + 𝑎42 𝑥2 + 𝑎43 𝑥3 )]/𝑎44
The solution process starts by assuming an initial approximation for the unknowns (first
estimated solution). In the first iteration, the initial value is substituted on the right-hand side of
the equations, and the new values that are calculated for the unknowns are the second estimated
solution. In the second iteration, the second solution is substituted back in the equations to give
new values for the unknowns, which are the third estimated solution. The iteration continues in
the same manner, and when the method does work, the solution that are obtained as successive
iterations converge towards the actual solution. In general, for a system with n equations for the
𝑥𝑖 unknowns are:
Prepared by Abe N
38
NUMERICAL METHODS
1
𝑗=𝑛
𝑥𝑖 = 𝑎 [𝑏𝑖 − (∑𝑗=1 𝑎𝑖𝑗 𝑥𝑗 )] 𝑎𝑖𝑖 ≠ 0, 𝑖 = 1,2, … , 𝑛(3.6)
𝑖𝑖
𝑗≠𝑖
Condition for convergence
for a system of n equations [a][x] =[b], a sufficient condition for convergence is that in each row
of the matrix of coefficients [a] the absolute value of the diagonal element is greater than the sum
of the absolute values of the off- diagonal elements. i.e.
𝑗=𝑛
|𝑎𝑖𝑖 | > ||∑ 𝑎𝑖𝑗 ||
𝑗=1
𝑗≠𝑖
This condition is sufficient condition but not necessary for convergence when the iteration
method is used. When the above condition is satisfied, the matrix [a] is classified as diagonally
dominant, and the iteration process converges toward the solution. The solution may converge
even when the condition is not satisfied. In this section we will see Jacobi and Gauss-seidel
iterative methods for solving system of linear equations.
3.3.1 Jacobi iterative method (2 hours)
Objective
At the end of this subtopic students shoud be able to:
Understand use of iterative methods.
Use Jacobi iterative methods to solve system of linear equations.
Identify the convergence condition for iterative methods.
In the Jacobi method, an initial (first) values is assumed for each of the unknowns𝑿(𝟎) =
(0)
(0)
(0)
(𝑥1 , 𝑥2 , … , 𝑥𝑛 ).If no information is available regarding the approximate value of the
unknown, the initial value of the unknown can be assumed to be zero. The second estimate of
Prepared by Abe N
39
NUMERICAL METHODS
(2)
(2)
(2)
solution𝑿(𝟐) = (𝑥1 , 𝑥2 , … , 𝑥𝑛 )is calculated by substituting the first estimate in the right-hand
side of Eq. (3.2).
(1)
𝑥𝑖
1
(0)
= 𝑎 [𝑏𝑖 − ∑𝑛𝑗=1 𝑎𝑖𝑗 𝑥𝑗 ] , 𝑖 = 1,2, … , 𝑛
(3.7)
𝑖𝑖
In general, the (k+1) th estimate of the solution is calculated from (k)th estimate by:
( k 1)
x
i
1
(𝑘)
𝑗=𝑛
𝑎 [𝑏𝑖 − (∑𝑗=1 𝑎𝑖𝑗 𝑥𝑗 )] 𝑖 = 1,2, … , 𝑛
𝑖𝑖
𝑗≠𝑖
Where k indicates the iteration number.
The iteration continues until the difference between two successive iterations in each unknown is
small (less than the given tolerance or error).
Example 3.7: Solve the following system of equations usingJacobi’smethod.
5𝑥1 − 𝑥2 + 𝑥3 = 10
2𝑥1 + 4𝑥2 = 12
𝑥1 + 𝑥2 + 5𝑥3 = −1
(0)
(0)
(0)
(0)
1
Start with initial solution 𝑿(𝟎) = (𝑥1 , 𝑥2 , 𝑥3 ) = (2,3,0)
Solution:
1
(1)
(0)
First iteration:𝑥1 = 5 [10 + 𝑥2 − 𝑥3 ] = 5 [10 + 3 − 0] = 2.6
1
1
(0)
(0)
(1)
𝑥2 = [12 − 2𝑥1 − 𝑥3 ] = [12 − 4] = 2
4
4
1
1
(0)
(0)
(1)
𝑥3 = [−1 − 𝑥1 − 𝑥2 ] = [−1 − 2 − 3] = −1.2
5
5
(2)
1
(1)
(1)
1
Second iteration:𝑥1 = 5 [10 + 𝑥2 − 𝑥3 ] = 5 [10 + 2 + 1.2] = 2.64
(2)
𝑥2 =
1
1
(1)
(1)
[12 − 2𝑥1 − 𝑥3 ] = [12 − 5.2] = 1.70
4
4
Prepared by Abe N
40
NUMERICAL METHODS
(2)
𝑥3 =
1
(3)
1
1
(1)
(1)
[−1 − 𝑥1 − 𝑥2 ] = [−1 − 2.6 − 2] = −1.12
5
5
(2)
(2)
1
Third iteration:𝑥1 = 5 [10 + 𝑥2 − 𝑥3 ] = 5 [10 + 1.7 + 1.2] = 2.564
1
1
(2)
(2)
(3)
𝑥2 = [12 − 2𝑥1 − 𝑥3 ] = [12 − 5.28] = 1.68
4
4
1
1
(2)
(2)
(3)
𝑥3 = [−1 − 𝑥1 − 𝑥2 ] = [−1 − 2.64 − 1.7] = −1.068
5
5
(4)
1
( )
( )
1
Fourth iteration:𝑥1 = 5 [10 + 𝑥23 − 𝑥33 ] = 5 [10 + 1.68 + 1.068] = 2.5496
1
1
(3)
(3)
(4)
𝑥2 = [12 − 2𝑥1 − 𝑥3 ] = [12 − 5.128] = 1.7180
4
4
1
1
(3)
(4)
(3)
𝑥3 = [−1 − 𝑥1 − 𝑥2 ] = [−1 − 2.564 − 1.68] = −1.0488
5
5
and so on.
The solution for example 3.7 using the c++ programming are given in table 3.1:
Enter the elements of the augmented matrix row wise:
5 -1 1 10
2 4 0 12
1 1 5 -1
Enter the allowed error and maximum iteration
0.0001 12
The solution vectors are:
Prepared by Abe N
41
NUMERICAL METHODS
Table 3.1_________________________________________
Iteration
x1 x2 x3
_________________________________________
1
2.600000
2.000000
-1.200000
2
2.640000
1.700000
-1.120000
3
2.564000
1.680000
-1.068000
4
2.549600
1.718000
-1.048800
5
2.553360
1.725200
-1.053520
6
2.555744
1.723320
-1.055712
7
2.555806
1.722128
-1.055813
8
2.555588
1.722097
-1.055587
9
2.555537
1.722206
-1.055537
________________________________________
Converges after 9 iterations, the solutionsare:
𝑥1 = 2.555537,
𝑥2 = 1.722206,
𝑥3 = −1.055537
Example 3.8: Solve the following system of linear equations using Jacobi iterative method.
10𝑥1 − 2𝑥2 − 𝑥3 – 𝑥4 = 1 9
−2𝑥1 + 5𝑥2 – 𝑥3 – 𝑥4 = 13
−𝑥1 – 𝑥2 + 10𝑥3 − 2𝑥4 = −72
−𝑥1 – 𝑥2 – 𝑥3 + 2 𝑥4 = 15
Solution: The resultsusing C++programming are given in table 3.2.
Enter the elements of the augmented matrix row wise:
10 -2 -1 -1 9
-2 5 -1 -1 13
-1 -1 10 -2 -72
-1 -1 -1 2
15
Prepared by Abe N
42
NUMERICAL METHODS
Mr. Nurilign enter the allowed error and maximum iteration
0.01 23
The solution vectors are:
Table 3.2____________________________________________________
𝑖𝑥1 𝑥2 𝑥3 𝑥4
______________________________________________________________________
1
0.900000
2.600000
-7.200000
7.500000
2
1.450000
3.020000
-5.350000
5.650000
3
1.534000
3.240000
-5.623000
7.060000
4
1.691700
3.501000
-5.310600
7.075500
5
1.776690
3.629660
-5.265630
7.441050
6
1.843474
3.745760
-5.171155
7.570360
7
1.889073
3.817231
-5.127005
7.709040
8
1.921650
3.872036
-5.087562
7.789649
9
1.944616
3.909077
-5.062702
7.853062
10
1.960851
3.935918
-5.044018
7.895496
11
1.972331
3.954636
-5.031224
7.926375
12
1.980442
3.967963
-5.022028
7.947872
13
1.986177
3.977346
-5.015585
7.963189
14
1.990230
3.983992
-5.011010
7.973969
15
1.993094
3.988684
-5.007784
7.981606
____________________________________________________________________
Converges after 15 iterations, the roots are:
x1 =1.993094, x2 =3.988684, x3 = −5.007784 , x4 =7.981606
3.3.2. Gauss-Seidel iterative method (2 hours)
Objective
At the end of this subtopic students shoud be able to:
Understand what the difference between Jacobi’s and Gauss-seidel methods.
Use Gauss-seidel iterative methods to solve system of linear equation.
Identify the convergence condition for iterative methods.
Prepared by Abe N
43
NUMERICAL METHODS
In the Gauss-seidel method, initial (first) values are assumed for all the unknowns. In the Gaussseidel method, the current values of the unknowns are used to calculating the new value of
nextunknown. In other words, as the new value of an unknown is calculated, it is immediately
used for calculating the next unknown in the same iteration. But in the case of Jacobi the values
of the unknown obtained in a single iteration are used as a complete set for calculating the new
values of the unknowns in the next iteration. The values of the unknowns are not updated in the
middle of a single iteration.
The Gauss-seidel iteration formula is given by
1
(𝑘+1)
𝑥𝑖
=
[𝑏 −
𝑎𝑖𝑖 𝑖
𝑗=𝑖−1
∑
𝑗=𝑛
(𝑘+1)
𝑎𝑖𝑗 𝑥𝑗
+
𝑗=1
(𝑘)
∑ 𝑎𝑖𝑗 𝑥𝑗 ] 𝑎𝑖𝑖 ≠ 0, 𝑖 = 2,3, … , 𝑛
𝑗=𝑖+1
(𝑘+1)
Notice that the values of the unknowns in the (k+1) iteration 𝑥𝑖
(𝑘+1)
values 𝑥𝑗
are calculated by using the
obtained in the (k+1) iteration for 𝑗 < 𝑖 and using the values
(k )
x for𝑗 > 𝑖.The
j
stopping criterion is the same as that of Jacobi. The Gauss-seidel method is faster than the Jacobi
method and requires less computer memory when programmed.
Example 3.8: Solve the following system of equations usingGauss-seidelmethod.
5𝑥1 − 𝑥2 + 𝑥3 = 10
2𝑥1 + 4𝑥2 = 12
𝑥1 + 𝑥2 + 5𝑥3 = −1
Solution:
1
1
5
5
(0)
(0)
(1)
First iteration:𝑥1 = [10 + 𝑥2 − 𝑥3 ] = [10 + 3 − 0] = 2.6
(1)
𝑥2 =
(1)
1
(1)
(1)
1
1
(1)
(0)
[12 − 2𝑥1 − 𝑥3 ] = [12 − 5.2] = 1.7
4
4
1
𝑥3 = 5 [−1 − 𝑥1 − 𝑥2 ] = 5 [−1 − 1.7 − 2.6] = −1.06 Second iteration:
1
1
(1)
(1)
(2)
𝑥1 = [10 + 𝑥2 − 𝑥3 ] = [10 + 1.7 + 1.06] = 2.552
5
5
Prepared by Abe N
44
NUMERICAL METHODS
(2)
𝑥2 =
(2)
𝑥3 =
1
1
(2)
(1)
[12 − 2𝑥1 − 𝑥3 ] = [12 − 5.104] = 1.724
4
4
1
1
(2)
(2)
[−1 − 𝑥1 − 𝑥2 ] = [−1 − 2.552 − 1.724] = −1.0552
5
5
(3)
1
(2)
(2)
1
Third iteration:𝑥1 = 5 [10 + 𝑥2 − 𝑥3 ] = 5 [10 + 1.724 + 1.0552] = 2.55584
1
1
(3)
(2)
(3)
𝑥2 = [12 − 2𝑥1 − 𝑥3 ] = [12 − 5.11168] = 1.72208
4
4
1
1
(3)
(3)
(3)
𝑥3 = [−1 − 𝑥1 − 𝑥2 ] = [−1 − 2.55584 − 1.72208] = −1.05558
5
5
(4)
1
(3)
(3)
1
Fourth iteration:𝑥1 = 5 [10 + 𝑥2 − 𝑥3 ] = 5 [10 + 1.72208 + 1.05558] = 2.55553
1
1
(4)
(3)
(4)
𝑥2 = [12 − 2𝑥1 − 𝑥3 ] = [12 − 5.11106] = 1.72223
4
4
1
1
(4)
(4)
(4)
𝑥3 = [−1 − 𝑥1 − 𝑥2 ] = [−1 − 2.55553 − 1.72223] = −1.05555
5
5
and so on.
Example 3.9: Solve the problem in example 3.2 usingGauss-seidelmethod.
Solution: The resultsusing C++programming are given in table 3.3.
Enter the elements of the augmented matrix row wise:
5 -1 1 10
2 4 0 12
1 1 5 -1
Enter the allowed error and maximum iteration:
0.0001 12
The solution vectors are:
Table 3.3________________________________________
Iteration
𝑥1 𝑥2 𝑥3
________________________________________
Prepared by Abe N
45
NUMERICAL METHODS
1
2
2.600000
2.552000
1.700000
1.724000
-1.060000
-1.055200
3
2.555840
1.722080
-1.055584
4
2.555533
1.722234
-1.055553
________________________________________
Converges after 4 iterations, the solutions are:𝑥1 =2.555533, 𝑥2 =1.722234, 𝑥3 =-1.055553
Example 3.10: Solve the following system of linear equations using Gauss-Seidel iterative
method.
10𝑥1 − 2𝑥2 − 𝑥3 – 𝑥4 = 1 9
−2𝑥1 + 5𝑥2 – 𝑥3 – 𝑥4 = 13
−𝑥1 – 𝑥2 + 10𝑥3 − 2𝑥4 = −72
−𝑥1 – 𝑥2 – 𝑥3 + 2 𝑥4 = 15
Solution: The resultsusing C++programming are given in table 3.4.
Enter the elements of the augmented matrix row
10 − 2 − 1 − 1 9
−2 5 − 1 − 1 13
−1 − 1 10 − 2 − 72
−1 − 1 − 1 2 15
Enter the allowed error and maximum iteration:
0.01 20
The solution vectors are:
Table 3.4_______________________________________________________
i𝑥1 𝑥2 𝑥3 𝑥4
___________________________________________________
1
0.900000
2.960000
-6.814000
6.023000
2
1.412900
3.006960
-5.553414
6.933223
Prepared by Abe N
46
NUMERICAL METHODS
3
1.639373
3.531711
-5.296247
7.437418
4
1.820459
3.756418
-5.154829
7.711024
5
1.906903
3.874000
-5.079705
7.850599
6
1.951890
3.934935
-5.041198
7.922813
7
1.975148
3.966383
-5.021284
7.960124
8
1.987160
3.982632
-5.010996
7.979398
9
1.993367
3.991027
-5.005681
7.989356
______________________________________________________
The solution converges after 9 iterations, the solutions are:
𝑥1 =1.993367, 𝑥2 =3.991027, 𝑥3 =-5.005681, 𝑥4 =7.989356
3.3.3 Newton ‘s method to solve system of nonlinear equations (2 hours)
Objective
At the end of this subtopic students should be able to solve system of nonlinearequations.
Consider a system of two nonlinear equations
𝑓1 (𝑥, 𝑦) = 0
𝑓2 (𝑥, 𝑦) = 0 (3.8)
Let 𝑋 = (𝑥, 𝑦) and 𝐹 = (𝑓1 , 𝑓2 )
Then the above system can be written as
𝐹(𝑋) = 0
(3.9)
We want to find 𝑋 that satisfies equation (3.9)
Similar to Newton’s method for single variable, the solution process starts by choosing an initial
gusses to the roots 𝑋0 = (𝑥0 , 𝑦0 )
Prepared by Abe N
47
NUMERICAL METHODS
If 𝑥1 and 𝑥2 are the true solutions of the system, then the values of 𝑓1 and 𝑓2 at 𝑥1 and 𝑦1 can be
expressed using Taylor series expansion of functions of two variables about the point
𝑋 = (𝑥0 , 𝑦0 ), by neglecting second and higher order derivatives, we have
𝑓1 (𝑥1 , 𝑦1 ) = 𝑓1 (𝑥0 , 𝑦0 ) + (𝑥1 − 𝑥0 )
𝑓2 (𝑥1 , 𝑦1 ) = 𝑓2 (𝑋0 ) + (𝑥1 − 𝑥0 )
⟹ 0 = 𝑓1 (𝑥0 , 𝑦0 ) + ∆𝑥
𝜕𝑓
𝜕𝑓1
𝜕𝑓1
(𝑋0 ) + (𝑦1 − 𝑦0 )
(𝑋 )
𝜕𝑥
𝜕𝑦 0
𝜕𝑓2
𝜕𝑓2
(𝑋0 ) + (𝑦1 − 𝑦0 )
(𝑋 )
𝜕𝑥
𝜕𝑦 0
𝜕𝑓1
𝜕𝑓1
(𝑋0 ) + ∆𝑦
(𝑋 )
𝜕𝑥
𝜕𝑦 0
𝜕𝑓
0 = 𝑓2 (𝑋0 ) + ∆𝑥 𝜕𝑥2 (𝑋0 ) + ∆𝑦 𝜕𝑦2 (𝑋0 ) (3.10)
Where,∆𝑥 = 𝑥 − 𝑥0 and ∆𝑦 = 𝑦 − 𝑦0
Equation (3.10) can be written in matrix form as follow:
𝜕𝑓1
𝜕𝑓1
(𝑋0 )
(𝑋 )
𝜕𝑥
𝜕𝑦 0 ∆𝑥
−𝑓 (𝑋 )
[ ]=[ 1 0 ]
∆𝑦
𝜕𝑓2
𝜕𝑓2
−𝑓2 (𝑋0 )
(𝑋0 )
(𝑋0 )
[ 𝜕𝑥
𝜕𝑦
]
𝐽(𝑋0 )∆𝑋 = −𝑓(𝑋0 )
(3.11)
is called Jacobian matrix
Solving the above system for ∆𝑥 and ∆𝑦 and using
∆𝑥1 = 𝑥1 − 𝑥0 ⟹ 𝑥1 = ∆𝑥1 + 𝑥0
∆𝑦1 = 𝑦1 − 𝑦0 ⟹ 𝑦1 = ∆𝑦1 + 𝑦0
We repeat the process until we get the desired accuracy.
Similarliy we can follow the same procedur for more than two systems of nonlinear equations.
Prepared by Abe N
48
NUMERICAL METHODS
Example3.11: Solve the following system of nonlinear equations using Newton’s method of
solvin system of nonlinear equations with (𝑥0 , 𝑦0 ) = (2.828,2.828).
𝑥2 − 𝑦2 − 4 = 0
𝑥 2 + 𝑦 2 − 16 = 0
Solution: Let 𝑓1 (𝑥, 𝑦) = 𝑥 2 − 𝑦 2 − 4 = 0 and 𝑓2 (𝑥, 𝑦) = 𝑥 2 + 𝑦 2 − 16 = 0
𝜕𝑓1
𝜕𝑓1
= 2𝑥;
= −2𝑦
𝜕𝑥
𝜕𝑦
𝜕𝑓2
𝜕𝑓2
= 2𝑥;
= 2𝑦
𝜕𝑥
𝜕𝑦
𝜕𝑓1
𝜕𝑓1
(𝑋0 ) =
(2.828,2.828) = 5.656
𝜕𝑥
𝜕𝑥
𝜕𝑓2
𝜕𝑓2
(𝑋0 ) =
(2.828,2.828) = 5.656
𝜕𝑥
𝜕𝑥
𝜕𝑓1
𝜕𝑓1
(𝑋0 ) =
(2.828,2.828) = −5.656
𝜕𝑦
𝜕𝑦
𝜕𝑓2
𝜕𝑓2
(𝑋0 ) =
(2.828,2.828) = 5.656
𝜕𝑦
𝜕𝑦
−𝑓1 (𝑋0 ) = 4and−𝑓2 (𝑋0 ) = 0.005
First iteration:
From 𝐽(𝑋0 )∆𝑋 = −𝑓(𝑋0 ) we have
5.656 5.656 x1 4
5
.
656
5
.
656
0
.
005
y
1
Solving for ∆𝑥1 and ∆𝑦1,we get
Prepared by Abe N
49
NUMERICAL METHODS
∆𝑥1 = 0.354, ∆𝑦1 = −0.353
Hence,𝑥1 = ∆𝑥1 + 𝑥0 = 0.354 + 2.828 = 3.182
𝑦1 = 𝑦0 + ∆𝑦1 = 2.828 − 0.353 = 2.475
Second iteration:
𝜕𝑓1
𝜕𝑓1
(𝑋1 ) =
(3.182,2.475) = 6.364
𝜕𝑥
𝜕𝑥
𝜕𝑓2
𝜕𝑓2
(𝑋1 ) =
(3.182,2.475) = −4.95
𝜕𝑥
𝜕𝑥
𝜕𝑓1
𝜕𝑓1
(𝑋1 ) =
(3.182,2.475) = 6.364
𝜕𝑦
𝜕𝑦
𝜕𝑓2
𝜕𝑓2
(𝑋1 ) =
(3.182,2.475) = 4.95
𝜕𝑦
𝜕𝑦
−𝑓1 (𝑋1 ) = 0.001and−𝑓2 (𝑋1 ) = −0.251
𝐽(𝑋1 )∆𝑋2 = −𝑓(𝑋1 )
0.001
6.364 −4.95 ∆𝑥2
(
)(
)=(
)
∆𝑦2
−0.251
6.364 4.95
Solving for ∆𝑥2 and ∆𝑦2 ,we get
∆𝑥2 = −0.02, ∆𝑦2 = −0.026
Hence,𝑥2 = ∆𝑥2 + 𝑥1 = 3.182 − 0.02 = 3.162
𝑦2 = 𝑦2 + ∆𝑦1 = 2.745 − 0.026 − 0.353 = 2.449
Third iteration:
𝜕𝑓1
𝜕𝑓1
(𝑋2 ) =
(3.162,2.449) = 6.324
𝜕𝑥
𝜕𝑥
𝜕𝑓2
𝜕𝑓2
(𝑋2 ) =
(3.162,2.449) = 6.324
𝜕𝑥
𝜕𝑥
Prepared by Abe N
50
NUMERICAL METHODS
𝜕𝑓1
𝜕𝑓1
(𝑋2 ) =
(3.162,2.449) = −4.898
𝜕𝑦
𝜕𝑦
𝜕𝑓2
𝜕𝑓2
(𝑋2 ) =
(3.162,2.449) = 4.898
𝜕𝑦
𝜕𝑦
(
6.364
6.364
−4.898 ∆𝑥2
−0.001
)(
)=(
)
∆𝑦2
4.898
0.004
𝑥3 = 𝑥2 + ∆𝑥3 = 3.162, 𝑦3 = 𝑦2 + ∆𝑦3 = 2.449
Therefore, the root is𝑥 = 3.162, 𝑦 = 2.449.
This method can also used for nonlinear equations of more than two variables in the same way.
Summary
In this chapter we have learnet direct and iterative methods to solve system of linear
equations.
Direct methods are Gauss-elimaniation, Gauss-Jordan elimination, LU decomposition.
Thomas Algorithm helps us to solve tridiagonal system of linear equations.
The coefficent matrix bening diagonally dominant is sufficient condition for the
convergency of Jacobi’s and Gauss-Seidel iterative methods.
Prepared by Abe N
51
NUMERICAL METHODS
Reviwe Exercise 3
1. Solve the following system of equations using Gauss elimination method.
2𝑥1 + 𝑥2 + 𝑥3 = 10
3𝑥1 + 2𝑥2 + 3𝑥3 = 18
𝑥1 + 4𝑥2 + 9𝑥3 = 16
2. Solve the following tridiagonal system using Thomas Algorithm.
a.
2𝑥1 − 𝑥2 = 3
−𝑥1 + 2𝑥2 − 𝑥3 = −3
−𝑥2 + 2𝑥3 = 1
b.
3𝑥1 + 𝑥2 = 4
2𝑥1 + 5𝑥2 − 𝑥3 = 0
4𝑥2 + 𝑥3 − 𝑥4 = 1
6𝑥3 − 2𝑥4 = −5
3. Find the first two iterations for following system of equations using
i.Jacobi Method (ii). Gauss-seidel Method with tolerance 0.00005
a 7𝑥1 − 2𝑥2 + 𝑥3 = 17
𝑥1 − 9𝑥2 + 3𝑥3 − 𝑥4 = 13
2𝑥1 + 10𝑥3 + 𝑥4 = 15
𝑥1 − 𝑥2 + 𝑥3 + 6𝑥4 = 10
b. 3𝑥1 − 𝑥2 + 𝑥3 = 1
3𝑥1 + 6𝑥2 + 2𝑥3 = 0
Prepared by Abe N
52
NUMERICAL METHODS
3𝑥1 + 3𝑥2 + 7𝑥3 = 4
c.
3𝑥1 + 𝑥2 + 𝑥3 = 4
−2𝑥1 + 4𝑥2 = 1
−𝑥1 + 2𝑥2 + −6𝑥3 = 2
4. Solve the following system of nonlinear equations using Newton’s method.
𝑥2 + 𝑦 = 5
𝑦2 + 𝑥 = 3
Take (𝑥0 , 𝑦0 ) = (1.5,1) use 4 decimal places through out your computation, continue until
|𝑥𝑖+1 − 𝑥𝑖 | < 0.001.
Prepared by Abe N
53
NUMERICAL METHODS
CHAPTER 4
FINITE DIFFERENCE OPERATORS AND INTERPOLATION
4.1. Introduction
Suppose we are given the following values of 𝑦 = 𝑓(𝑥) corrosponging to a set of values of 𝑥:
𝒙
𝒙𝟎
𝒙𝟏
𝒙𝟐
…
𝒙𝒏
𝒚
𝑦0
𝑦1
𝑦2
…
𝑦𝑛
Then the process of finding the value of 𝑦 corresponding to any value of 𝑥 = 𝑥𝑖 between 𝑥0 and
𝑥𝑛 is called interpolation. And the technique of estimating the value of a function out side the
given range is called extrapolation, however, the term interpolation includes extrapolation.
Objective
At the end of this unit, the learner should be able to:
Define forward, backward, centeral and shift operators.
Construct the finite difference tables for a given set of data points.
Find the interpolating polynomial of the given data point using different interpolation
formulas.
Allowted time to complete this chapter is 12 hours
Activity 4.1
Given
𝒙
𝟎
𝟏
𝟐
𝟑
𝒚 = 𝒇(𝒙)
1
0
1
10
Based on the given data find 𝑓(𝑥) that thatisfies all the data points.
Prepared by Abe N
54
NUMERICAL METHODS
4.2. Finite Differences
The calculus of finite differences deals with the changes that takes place in the value of the
function (dependent variable), due to finite changes in the independent variable.Through this, we
also study the relations that exist between the values assumed by the function, whenever the
independent variable changes by finite jumps with equal or unequal spacing.In this chapter, we
will study the varations in the function when the independent variable changes by equal interval
or uniform spacing and unequal spacing.
4.2.1. Forward Differences (1 hour)
Objective
At the end of this subtopic the learner should be able to:
Define forward operator.
Construct the forward difference tables for a given set of data points.
Suppose the following data is given such that the values of 𝑥 are eqully spaced throughout the
data, that means the distance between any two consecutives 𝑥 values are constant all over the
data.
𝒙
𝒙𝟎
𝒙𝟏
𝒙𝟐
𝒙𝟑
𝒙𝟒
…
𝒙𝒏
𝒚
𝑦0
𝑦1
𝑦2
𝑦3
𝑦4
…
𝑦𝑛
Then the differences 𝑦1 − 𝑦0 , 𝑦2 − 𝑦1 , 𝑦3 − 𝑦2 , 𝑦4 − 𝑦3 , … , 𝑦𝑛 − 𝑦𝑛−1 when denoted by ∆𝑦0 ,
∆𝑦1 , ∆𝑦2 , ∆𝑦3 , … , ∆𝑦𝑛−1 repectively are known as first order forward differencesandthe operator
∆ is called forward difference operator and higher order forwardfinitedifference is defined
as:∆𝑛 𝑦𝑖 = ∆(∆𝑛−1 𝑦𝑖 ), 𝑖 = 0,1,2, … , 𝑛
Or we can write as:
Prepared by Abe N
55
NUMERICAL METHODS
𝑛
𝑛
∆ 𝑓𝑖 = ∆
𝑛−1
𝑓𝑖+1 − ∆
𝑛−1
𝑓𝑖 = ∑(−1)𝑘
𝑘=0
𝑛!
𝑓
𝑘! (𝑛 − 𝑘)! 𝑖+𝑛−𝑘
For example, ∆2 𝑦0 = ∆(∆𝑦0 ) = ∆(𝑦1 − 𝑦0 ) = ∆𝑦1 − ∆𝑦0
∆2 𝑦0 = 𝑦2 − 𝑦1 − (𝑦1 − 𝑦0 ) = 𝑦2 − 2𝑦1 + 𝑦0
∆3 𝑦0 = ∆2 𝑦1 − ∆2 𝑦0 = ∆𝑦2 − ∆𝑦1 − (∆𝑦1 − ∆𝑦0 )
= 𝑦3 − 𝑦2 − 𝑦2 + 𝑦1 − 𝑦2 + 𝑦1 + 𝑦1 − 𝑦0
= 𝑦3 − 3𝑦2 + 3𝑦1 − 𝑦0
Therefore,∆3 𝑦0 = 𝑦3 − 3𝑦2 + 3𝑦1 − 𝑦0
Suppose we are given the following data
𝒙
𝒙𝟎
𝒙𝟏
𝒙𝟐
𝒙𝟑
𝒙𝟒
𝒚
𝑦0
𝑦1
𝑦2
𝑦3
𝑦4
A forward difference table for the given data is given below.
X
Y
y
2 y
3 y
4 y
x0
y0
y0
2 y0
3 y0
4 y0
x1
y1
y1
2 y1
∆3 𝑦1
x2
y2
y 2
∆2 𝑦2
x3
y3
∆𝑦3
𝑥4
𝑦4
Constructing the forward or back ward difference table is important or the first step to use the
interpolation formula, because we read the coefficients that are aviliable in the forward or back
Prepared by Abe N
56
NUMERICAL METHODS
ward difference interpolation formula form the respective difference table. Therefore,
learnersshould be able to construct these difference tables in order to use the respective
interpolation formulas.
4.2.2. Backward Differences (1 hour)
Objective
At the end of this subtopic, the learner should be able to:
Define backward difference.
Construct backward difference tables for a given set of data points.
Suppose the following data is given such that the values of 𝑥 are eqully spaced throughout the
data, that means the distance between any two consecutives 𝑥 values are constant all over the
data.
𝒙
𝒙𝟎
𝒙𝟏
𝒙𝟐
𝒙𝟑
𝒙𝟒
…
𝒙𝒏
𝒚
𝑦0
𝑦1
𝑦2
𝑦3
𝑦4
…
𝑦𝑛
Then the differences 𝑦1 − 𝑦0 , 𝑦2 − 𝑦1 , 𝑦3 − 𝑦2 , 𝑦4 − 𝑦3 , … , 𝑦𝑛 − 𝑦𝑛−1 when denoted by ∇𝑦1 ,
∇𝑦2 , ∇𝑦3 , ∇𝑦4 , … , ∇𝑦𝑛 repectively are known as first order backward differencesandthe operator
∇ is called backward difference operator and higher order backward finitedifference can be
defined as:
∇2 𝑦2 = ∇(∇𝑦2 ) = ∇(𝑦2 − 𝑦1 ) = ∇y2 − ∇y1
∇2 𝑦2 = y2 − y1 − (y1 − y0 ) = y2 − 2y0 + y0
∇3 𝑦3 = ∇(∇2 𝑦3 ) = ∇(∇(𝑦3 − 𝑦2 ))
∇3 𝑦3 = ∇(∇y3 − ∇y2 ) = ∇y3 − ∇y2 − ∇(y2 − y1 )
∇3 𝑦3 = y3 − y2 − y2 + y1 − y2 + y1 + y1 − y0
Prepared by Abe N
57
NUMERICAL METHODS
∇3 𝑦3 = 𝑦3 − 3𝑦2 + 3𝑦1 − 𝑦0
In general, higher orders back ward differences are given by:
𝑛
𝛻 𝑛 𝑓𝑖 = 𝛻 𝑛−1 𝑓𝑖 − 𝛻 𝑛−1 𝑓𝑖−1 = ∑(−1)𝑘
𝑘=0
𝑛!
𝑓
𝑘! (𝑛 − 𝑘)! 𝑖−𝑘
Suppose we are given the following data
𝒙
𝒙𝟎
𝒙𝟏
𝒙𝟐
𝒙𝟑
𝒙𝟒
𝒚
𝑦0
𝑦1
𝑦2
𝑦3
𝑦4
A backward difference table for the above data is given below.
y
x
x
x
x
x
y
y
y
y
y
0
1
2
3
4
y
y
x
0
1
2
3
4
y
2
3
4
y
y y
y y y
y y y y
1
2
2
2
2
3
3
3
2
4
3
3
4
4
4
4
In order to construct difference tables, one must frist understand the definiation of backward and
forward differences, once you understand the definition, it will be very simple to construct
difference tables of a given data. The secrete to understand mathematics is understanding the
definition, every thing lies on it.
4.2.3. Central differences (1 hour)
Objective
At the end of this subtopic, the learner should be able to:
Define centeraldifferece.
Construct centeral difference table for a given set of data points.
Prepared by Abe N
58
NUMERICAL METHODS
Suppose the following data is given such that the values of 𝑥 are eqully spaced throughout the
data, that means the distance between any two consecutives 𝑥 values are constant all over the
data.
𝒙
𝒙𝟎
𝒙𝟏
𝒙𝟐
𝒙𝟑
𝒙𝟒
…
𝒙𝒏
𝒚
𝑦0
𝑦1
𝑦2
𝑦3
𝑦4
…
𝑦𝑛
Then the differences 𝑦1 − 𝑦0 , 𝑦2 − 𝑦1 , 𝑦3 − 𝑦2 , 𝑦4 − 𝑦3 , … , 𝑦𝑛 − 𝑦𝑛−1 when denoted by δ𝑦1 , δ𝑦3 ,
2
2
δ𝑦5 , … , δ𝑦𝑛+1 repectively are known as first order centeral differencesandthe symbol𝛿 is called
2
2
centeral difference operator .This operator is a linear operator.
From backward and forward difference operators, we have
𝛿𝑦1 = ∆y0 = ∇𝑦1
2
𝛿𝑦3 = ∆y1 = ∇𝑦2
2
𝛿𝑦5 = ∆y2 = ∇𝑦3
2
……………
… … … …and so, on
In general,δ𝑦𝑛+1 = ∆𝑦𝑛 = ∇𝑦𝑛+1 , 𝑛 = 0,1,2, …
2
The second order central differences, denoted by 𝛿 2 𝑦1 , 𝛿 2 𝑦2 , 𝛿 2 𝑦3 , …are defined as
𝛿 2 𝑦1 = 𝛿𝑦3 − 𝛿𝑦1
2
2
𝛿 2 𝑦2 = 𝛿𝑦5 − 𝛿𝑦3
2
2
… … ….
𝛿 2 𝑦𝑛 = 𝛿𝑦𝑛+ 1 − 𝛿𝑦𝑛−1
2
Prepared by Abe N
2
59
NUMERICAL METHODS
Higher order central differences are similarly defined. In general, the 𝑛𝑡ℎ central differences are
given by
i.
for odd 𝑛, 𝛿 𝑛 𝑦𝑟−1 = 𝛿 𝑛−1 𝑦𝑟 − 𝛿 𝑛−1 𝑦𝑟−1 , 𝑟 = 1,2,3, …
2
ii.
𝑛
for even 𝑛, 𝛿 𝑦𝑟 = 𝛿 𝑛−1 𝑦𝑟+ 1 − 𝛿 𝑛−1 𝑦𝑟−1 , 𝑟 = 1,2,3, …
2
2
Centeral difference table
The centeral difference table for the following data below
𝒙
𝒙𝟎
𝒙𝟏
𝒙𝟐
𝒙𝟑
𝒙𝟒
𝒙𝟓
𝒚
𝑦0
𝑦1
𝑦2
𝑦3
𝑦4
𝑦5
The centeral difference table is
x
x
0
y y
y
y
y
1
y
2y
x
x
x
x
2
3
4
5
y
3
y
4
5
0
1
2
x
y
2
1
y
y
y
y
2
3
4
y
y
y
y
1
3
2
2y
2
3y
y
3
5
2
2y
3
y
3
7
2
2y
3
2
5
2
4y
4y
2
5y
5
2
3
7
2
4
9
2
5
Prepared by Abe N
60
NUMERICAL METHODS
4.2.4. Shift Operater(E) (1 hour)
The operator E is called shift operator or displacement or translation operator. It shows the
operation of increasing the argument value 𝑥by its interval of differencing h so that.
𝐸𝑓 (𝑥) = 𝑓(𝑥 + ℎ) 𝑜𝑟𝐸𝑦(𝑥) = 𝑦(𝑥 + ℎ)
Similarly,, 𝐸 2 𝑓(𝑥) = 𝐸𝑓(𝑥 + ℎ) = 𝑓(𝑥 + 2ℎ)
Ingeneral𝐸 𝑛 𝑓(𝑥) = 𝑓(𝑥 + 𝑛ℎ)
And Inverse shift operator (𝐸 −1 ) is defined as
𝐸 −1 𝑓(𝑥) = 𝑓(𝑥 − ℎ)
𝐸 −2 𝑓(𝑥) = 𝑓(𝑥 − 2ℎ)
𝐸 −𝑛 𝑓(𝑥) = 𝑓(𝑥 − 𝑛ℎ)
4.2.5. Relation ship between operators
𝐸 =1+∆
∆𝑓(𝑥) = ∇𝑓(𝑥 + ℎ)
∇𝑓(𝑥) = ∆𝑓(𝑥 − ℎ) = 𝑓(𝑥) − 𝑓(𝑥 − ℎ)
𝑓(𝑥 − ℎ) = 𝑓(𝑥) − ∇𝑓(𝑥) = (1 − ∇)𝑓(𝑥) ⟹ 𝐸 −1 = 1 − ∇
Now, let us consider specific example to demonstrate how to construct the forward and
backward difference tables.
Example 4.1: Construct a forward and backward difference table for the following data.
𝒙
𝟏𝟎
𝟏𝟓
𝟐𝟎
𝟐𝟓
𝟑𝟎
𝟑𝟓
𝒚
15
17
20
21
24
30
Solution:in this specific example,𝑦0 = 15, 𝑦1 = 17, 𝑦2 = 20𝑦3 = 21, 𝑦4 = 24 and 𝑦5 = 30.
Thus, from the definition of forward differences, we have
∆𝑦0 = 𝑦1 − 𝑦0 = 17 − 15 = 2
∆𝑦1 = 𝑦2 − 𝑦1 = 20 − 17 = 3
Prepared by Abe N
61
NUMERICAL METHODS
∆𝑦2 = 𝑦3 − 𝑦2 = 21 − 20 = 1
∆𝑦3 = 𝑦4 − 𝑦3 = 24 − 21 = 3
∆𝑦4 = 𝑦5 − 𝑦4 = 30 − 24 = 6
All these differences are called first order forward differences because the order of the operator ∆
is one. Second order forward differences are obtained as follow:
∆2 𝑦0 = ∆(∆𝑦0 ) = ∆(𝑦1 − 𝑦0 ) = ∆𝑦1 − ∆𝑦0 = 3 − 2 = 1
∆2 𝑦1 = ∆(∆𝑦1 ) = ∆(𝑦2 − 𝑦1 ) = ∆𝑦2 − ∆𝑦1 = 1 − 3 = −2
∆2 𝑦2 = ∆(∆𝑦2 ) = ∆(𝑦3 − 𝑦2 ) = ∆𝑦3 − ∆𝑦2 = 3 − 1 = 1
∆2 𝑦3 = ∆(∆𝑦3 ) = ∆(𝑦4 − 𝑦3 ) = ∆𝑦4 − ∆𝑦3 = 6 − 3
Similarlly, we can obtain higher order forward differences.
For example,∆3 𝑦0 = ∆2 (∆𝑦0 ) = ∆2 (𝑦1 − 𝑦0 ) = ∆2 𝑦1 − ∆2 𝑦0 = −2 − 1 = −3.
In general, the forward difference table is given as:
x y y y y y y
2
3
4
5
10
10 15
2
1
3
7
15 17
3
2
4
3
20 20
1
2
1
25 21
3
3
30 24
6
35 30
Using the definition of backward differences, the backward difference table for the above data is
Prepared by Abe N
62
NUMERICAL METHODS
x y y y y y y
2
3
4
5
10 15
15 17
2
20 20
3
1
25 21
1
2
3
30 24
3
2
4
7
35 30
6
3
1
3
10
Note: The only difference in the forward and backward difference is position.
4.3. Interpolation with equally spaced data (4 hours)
Objective
At the end of these topic studentsould beable to:
Know how to derive NFDIF and NBDIF.
Apply NFDIF and NBDIF to find the interpolating polynomial for a given data.
4.3.1. Newton’s forward difference interpolationFormula (NFDIF) (2 hours)
Objective
At the end of these subtopicSudentssould beable to:
Know how to derive NFDIF.
Apply NFDIF to find the interpolating polynomial for a given data.
Derivation of the method
Suppose we are given the following data such that the values of 𝑥 are equally spaced with 𝑥𝑖 =
𝑥0 + 𝑖ℎ, for 𝑖 = 0,1,2, … , 𝑛.
Prepared by Abe N
63
NUMERICAL METHODS
𝒙
𝒙𝟎
𝒙𝟏
𝒙𝟐
𝒙𝟑
𝒙𝟒
…
𝒙𝒏
𝒚
𝑦0
𝑦1
𝑦2
𝑦3
𝑦4
…
𝑦𝑛
Our objective is to find a polynomial 𝑓(𝑥) that satisfies the given data, that is
𝑓(𝑥𝑖 ) = 𝑦𝑖 , ∀𝑖, 𝑖 = 0,1,2, … , 𝑛. (4.1)
Let 𝑓(𝑥)has the form
𝑓(𝑥) = 𝑎0 + 𝑎1 (𝑥 − 𝑥0 ) + 𝑎2 (𝑥 − 𝑥0 )(𝑥 − 𝑥1 ) + 𝑎3 (𝑥 − 𝑥0 )(𝑥 − 𝑥1 )(𝑥 − 𝑥2 ) + ⋯ +
𝑎𝑛−1 (𝑥 − 𝑥0 )(𝑥 − 𝑥1 ) … (𝑥 − 𝑥𝑛−2 ) + 𝑎𝑛 (𝑥 − 𝑥0 )(𝑥 − 𝑥1 ) … (𝑥 − 𝑥𝑛−1 )
(4.2)
From equation (4.1), we have 𝑓(𝑥0 ) = 𝑦0 and from equation (1.2) we get 𝑓(𝑥0 ) = 𝑎0
From which, we have 𝑦0 = 𝑎0 .
From equation (4.1) and (4.2), we have 𝑓(𝑥1 ) = 𝑦1 and 𝑓(𝑥1 ) = 𝑎0 + 𝑎1 (𝑥1 − 𝑥0 ) respectively.
Then,𝑦1 = 𝑎0 + 𝑎1 (𝑥1 − 𝑥0 ) = 𝑎0 + 𝑎1 ℎ (Because𝑥1 − 𝑥0 = ℎ)
⟹ 𝑦1 = 𝑦0 + 𝑎1 ℎ.
(Because 𝑦0 = 𝑎0 )
Solving for 𝑎1 we get
𝑎1 =
𝑦1 − 𝑦0 ∆𝑦0 ∆𝑦0
=
=
ℎ
ℎ
1! ℎ
Again, from the above two equations we will have
𝑓(𝑥2 ) = 𝑦2 and𝑓(𝑥2 ) = 𝑎0 + 𝑎1 (𝑥2 − 𝑥0 ) + 𝑎2 (𝑥2 − 𝑥0 )(𝑥2 − 𝑥1 )
𝑦 −𝑦
Then,𝑦2 = 𝑎0 + 𝑎1 2ℎ + 𝑎2 2ℎ2 ⟹ 𝑦2 = 𝑦0 + 1 ℎ 0 2ℎ + 𝑎2 2ℎ2
⟹ 𝑦2 − 𝑦0 − 2𝑦1 + 2𝑦0 = 𝑎2 2ℎ2 ⟹ 𝑎2 2ℎ2 = 𝑦2 − 2𝑦1 + 𝑦0
∆2 𝑦0 ∆2 𝑦0
⟹ 𝑎2 2ℎ = ∆ 𝑦0 ⟹ 𝑎2 =
=
2ℎ2
2! ℎ2
2
2
Prepared by Abe N
64
NUMERICAL METHODS
Following the same procedure, we can obtain the rest of the coefficients as
∆3 𝑦
∆4 𝑦
∆𝑛 𝑦
𝑎3 = 3!ℎ30 ,𝑎4 = 4!ℎ40 , … . , 𝑎𝑛 = 𝑛!ℎ𝑛0
By substituting these coefficients in equation (1.2) one can get:
∆𝑦0
∆2 𝑦0
∆3 𝑦0
(𝑥 − 𝑥0 ) +
(𝑥 − 𝑥0 )(𝑥 − 𝑥1 ) +
(𝑥 − 𝑥0 )(𝑥 − 𝑥1 )(𝑥 − 𝑥2 ) + ⋯ +
𝑓(𝑥) = 𝑦0 +
ℎ
2! ℎ2
3! ℎ3
∆𝑛 𝑦0
𝑛!ℎ𝑛
(𝑥 − 𝑥0 )(𝑥 − 𝑥1 )(𝑥 − 𝑥2 ) … (𝑥 − 𝑥𝑛−1 )
(4.3)
Suppose we want to find 𝑦corresponding to any 𝑥with in the given data.
Let 𝑥 = 𝑥0 + 𝑘ℎ ⟹ 𝑥 − 𝑥0 = 𝑘ℎ
𝑥 − 𝑥1 = (𝑥0 + 𝑘ℎ) − (𝑥0 + ℎ) = ℎ(𝑘 − 1) (Because 𝑥 = 𝑥0 + 𝑘ℎ)
𝑥 − 𝑥2 = (𝑥0 + 𝑘ℎ) − (𝑥0 + 2ℎ) = ℎ(𝑘 − 2)
𝑥 − 𝑥3 = (𝑥0 + 𝑘ℎ) − (𝑥0 + 3ℎ) = ℎ(𝑘 − 3)
⋮
𝑥 − 𝑥𝑛−1 = (𝑥0 + 𝑘ℎ) − (𝑥0 + (𝑛 − 1)ℎ) = ℎ(𝑘 − (𝑛 − 1))
Substituting these in Eq. (1.3), we get
𝑓(𝑥) = 𝑦0 +
∆𝑦0
∆2 𝑦
∆3 𝑦
(𝑘ℎ)ℎ(𝑘 − 1)ℎ(𝑘 − 2) + ⋯ +
𝑘ℎ +
(𝑘ℎ)ℎ(𝑘
−
1)
+
ℎ
2! ℎ2
3! ℎ3
∆𝑛 𝑦
(𝑘ℎ)ℎ(𝑘 − 1)ℎ(𝑘 − 2) … ℎ(𝑘 − (𝑛 − 1))
𝑛! ℎ𝑛
After simplification we get the following interpolation formula
Δ2 𝑦0
Δ3 𝑦0
𝑓(𝑥) = 𝑦0 + Δ𝑦0 𝑘 +
𝑘(𝑘 − 1) +
𝑘(𝑘 − 1)(𝑘 − 2)
2!
3!
Δ4 𝑦
+ 4! 0 𝑘(𝑘 − 1)(𝑘 − 2)(𝑘 − 3)
+ ⋯+
Δ𝑛 𝑦0
𝑛!
𝑘(𝑘 − 1)(𝑘 − 2) … (𝑘 − (𝑛 − 1))(4.4)
Prepared by Abe N
65
NUMERICAL METHODS
Where 𝑘 =
𝑥−𝑥0
ℎ
We can write in compact form as:
𝑓(𝑥) = 𝑦(𝑥) = ∑𝑛𝑟=0(𝑘𝑟) ∆𝑟 𝑦0 , Where 𝑘 =
𝑥−𝑥0
ℎ
The formula in equation (4.4) is known as Newton’sforward difference interpolation formula
(NFDIF).
4.3.2. Newton’s backward difference interpolation (2 hours)
Objective
At the end of this topicsudentssould beable to:
Know how to derive NBDIF.
Apply NBDIF to find the interpolating polynomial for a given data.
In order to derive Newton’s backward difference interpolation formula, write the polynomial
𝑓(𝑥) in the following form.
𝑓(𝑥) = 𝑎0 + 𝑎1 (𝑥 − 𝑥𝑛 ) + 𝑎2 (𝑥 − 𝑥𝑛 )(𝑥 − 𝑥𝑛−1 ) + 𝑎3 (𝑥 − 𝑥𝑛 )(𝑥 − 𝑥𝑛−1 )(𝑥 − 𝑥𝑛−2 ) + ⋯ +
𝑎𝑛 (𝑥 − 𝑥𝑛 )(𝑥 − 𝑥𝑛−1 )(𝑥 − 𝑥𝑛−2 ) … ((𝑥 − 𝑥1 )
Then by applying the same technique as the forward case, we get the Newton Back ward
difference interpolation formula
𝑓(𝑥) = 𝑦𝑛 + ∇𝑦𝑛 𝑘 +
+⋯+
∇𝑛 𝑦𝑛
𝑛!
Where 𝑘 =
∇2 𝑦𝑛
∇3 𝑦𝑛
∇4 𝑦𝑛
𝑘(𝑘 + 1) +
𝑘(𝑘 + 1)(𝑘 + 2) +
𝑘(𝑘 + 1)(𝑘 + 2)(𝑘 + 3)
2!
3!
4!
𝑘(𝑘 + 1)(𝑘 + 2) … (𝑘 + (𝑛 − 1))
(4.5)
𝑥−𝑥𝑛
ℎ
In compact form:
Prepared by Abe N
66
NUMERICAL METHODS
𝑓(𝑥) = 𝑦(𝑥) = ∑𝑛𝑟=0(−𝑘
) (−1)𝑟 ∇𝑟 𝑦𝑛 , Where 𝑘 =
𝑟
𝑥−𝑥𝑛
ℎ
Equation (4.5) is called Newton’s backward difference interpolation formula (NBDIF).
Example 4.2: Given data
𝒙
𝟎
𝟏
𝟐
𝟑
𝟒
𝒚
6
11
66
273 806
Find the interpolating polynomial using NFDIF and evaluate it at𝑥 = 1.5
Solution: The FD table is:
x
y y y y y
0
6
1
2
3
4
5
50
102
72
11
55
152
174
2
66
207
326
3
273
533
4
806
Δ2 𝑦0
Δ3 𝑦0
Δ4 𝑦0
𝑓(𝑥) = 𝑦0 + Δ𝑦0 𝑘 +
𝑘(𝑘 − 1) +
𝑘(𝑘 − 1)(𝑘 − 2) +
𝑘(𝑘 − 1)(𝑘 − 2)(𝑘
2!
3!
4!
𝑥 − 𝑥0 𝑥 − 0
− 3)𝑘 =
=
=𝑥
ℎ
1
𝑓(𝑥) = 6 + 5𝑥 + 25𝑥(𝑥 − 1) +
102
72
𝑥(𝑥 − 1)(𝑥 − 2) + 𝑥(𝑥 − 1)(𝑥 − 2)(𝑥 − 3)
6
24
= 6 + 5𝑥 − 25𝑥 + 34𝑥 − 18𝑥 + 25𝑥 2 − 51𝑥 2 + 33𝑥 2 + 17𝑥 3 − 18𝑥 3 + 3𝑥 4
= 6 − 4𝑥 + 7𝑥 2 − 𝑥 3 + 3𝑥 4
𝑓(𝑥) = 3𝑥 4 − 𝑥 3 + 7𝑥 2 − 4𝑥 + 6is the interpolating polynomial.
And 𝑓(1.5) = 27.5625
Example 4.3: Find the interpolating polynomial which takes the following values using NBDIF.
Prepared by Abe N
67
NUMERICAL METHODS
𝒙
𝟎
𝟏
𝟐
𝟑
𝒚
1
0
1
10
Solution:The BD table is:
x y y y y
2
0
1
1
0
1
2
1
1
2
3
10
9
8
𝑓(𝑥) = 𝑦𝑛 + ∇𝑦𝑛 𝑘 +
3
6
∇2 𝑦𝑛
𝑘(𝑘 + 1) +
2!
∇3 𝑦𝑛
3!
𝑘(𝑘 + 1)(𝑘 + 2)and𝑘 =
𝑥−𝑥𝑛
ℎ
=
𝑥−3
1
=𝑥−3
𝑓(𝑥) = 10 + 9(𝑥 − 3) + 4(𝑥 − 3)(𝑥 − 2) + (𝑥 − 3)(𝑥 − 2)(𝑥 − 1)
= 10 + 9𝑥 − 27 + 4(𝑥 2 − 5𝑥 + 6) + 𝑥 3 − 6𝑥 2 + 11𝑥 − 6
= 1 − 2𝑥 2 + 𝑥 3
𝑓(𝑥) = 𝑥 3 − 2𝑥 2 + 1and𝑓(4) = 33 we call it extrapolation because 4 is not in[ 𝑥0 , 𝑥𝑛 ].
4.4. Interpolation with unequal intervals (4 hours)
Objective
At the end of these topics sudentssouldbeable to:
To construct NDD table and use it to find the interpolating polynomial of a given data.
Understand the concept how to derive NDDIF and LIF.
Apply NDDIF and LIF to find the interpolating polynomial for a given data.
Prepared by Abe N
68
NUMERICAL METHODS
4.4.1. Newton’s divided difference (2 hours)
Objective
At the end of this topicSudentssould beable to:
To construct NDD table for a given data.
Let
(𝑥0, 𝑦0 ) , (𝑥1, 𝑦1) , (𝑥2, 𝑦2), (𝑥3, 𝑦3),… , ( 𝑥𝑛, 𝑦𝑛 ) be given data points, where the values of 𝑥
may not be necessarly equally spaced.Then the first orderdivided difference for two arguments
𝑥0, 𝑥1 is defined as:
𝑦 −𝑦
𝑦
𝑦
[𝑥0, 𝑥1 ] = 𝑥1 −𝑥0 , [𝑥1, 𝑥2 ] = 𝑥2−𝑥1 , …
1
2
2− 1
The second order divided difference is [𝑥0 , 𝑥1 , 𝑥2 ] =
[𝑥1 ,𝑥2 ]−[𝑥0 ,𝑥1 ]
The third order divided difference is [𝑥0 , 𝑥1 , 𝑥2 , 𝑥3 ] =
𝑥2 −𝑥0
[𝑥1 ,𝑥2 ,𝑥3 ]−[𝑥0 ,𝑥1 ,𝑥2 ]
𝑥3 −𝑥0
The kth order divided difference is [𝑥0 , 𝑥1 , 𝑥2 , … , 𝑥𝑘 ] =
…
[𝑥1 ,𝑥2 ,…,𝑥𝑘 ]−[𝑥0 ,𝑥1 ,…,𝑥𝑘−1 ]
𝑥𝑘 −𝑥0
Divided difference table for five data points
x y
x y
0
0
x y
1
x y
2
2
3
3
4
3
x , x
3
x y
2
x , x
2
x y
1
x , x
1
3
Dy
x , x
0
1
2
Dy
x , x , x
0
1
2
x , x , x
1
2
3
x , x , x
2
3
4
Dy
Dy
x , x , x , x
0
1
2
3
x , x , x , x
1
2
3
x x , x x , x
0
1
2
3
4
4
4
4
4
Prepared by Abe N
69
NUMERICAL METHODS
4.4.2. Newton’s divided difference Interpolation formula (NDDIF) (2 hours)
Objective
At the end of this subtopicsudentssould beable to:
To construct NDD table and use it to find the interpolating polynomial of a given data.
Understand the concept how to derive NDDIF.
Apply NDDIF to find the interpolating polynomial for a given data.
Let (𝑥0, 𝑦0 ), (𝑥1, 𝑦1) , (𝑥2, 𝑦2 ), (𝑥3, 𝑦3),… , ( 𝑥𝑛, 𝑦𝑛 ) be given data points in which the values of 𝑥
may not be necessarly equally spaced and let 𝑥be a value within the data such that 𝑦 = 𝑓(𝑥).
Then from the definition of divided difference:
𝑦 −𝑦
[𝑥, 𝑥0 ] = 0
𝑥0 −𝑥
𝑦−𝑦
= 𝑥−𝑥0 .
0
Now, solve for 𝑦 i.e. 𝑦 − 𝑦0 = [𝑥, 𝑥0 ](𝑥 − 𝑥0 )
⟹ 𝑦 = 𝑦0 + (𝑥 − 𝑥0 )[𝑥, 𝑥0 ] (4.6)
Again [𝑥, 𝑥0 , 𝑥1 ] =
[𝑥0 ,𝑥1 ]−[𝑥,𝑥0 ]
𝑥1 −𝑥
⟹ [𝑥, 𝑥0 ] = [𝑥0 , 𝑥1 ] + (𝑥 − 𝑥1 )[𝑥, 𝑥0 , 𝑥1 ]
Substituting the value of[𝑥, 𝑥0 ] in equation (4.6), we get
𝑦 = 𝑦0 + (𝑥 − 𝑥0 )[𝑥0 , 𝑥1 ] + (𝑥 − 𝑥0 )(𝑥 − 𝑥1 )[𝑥, 𝑥0 , 𝑥1 ]
And from [𝑥, 𝑥0 , 𝑥1 , 𝑥2 ] =
(4.7)
[𝑥0 ,𝑥1 ,𝑥2 ]−[𝑥,𝑥0 ,𝑥1 ]
𝑥2 −𝑥
⟹ [𝑥, 𝑥0 , 𝑥1 ] = (𝑥 − 𝑥2 )[𝑥0 , 𝑥1 , 𝑥2 ] +[𝑥, 𝑥0 , 𝑥1 , 𝑥2 ]
(4.8)
Substituting (4.8) in equation (4.7)
𝑦 = 𝑦0 + (𝑥 − 𝑥0 )[𝑥0 , 𝑥1 ] + (𝑥 − 𝑥0 )(𝑥 − 𝑥1 )[𝑥0 , 𝑥1 , 𝑥2 ] +
(𝑥 − 𝑥0 )(𝑥 − 𝑥1 )(𝑥 − 𝑥2 )[𝑥, 𝑥0 , 𝑥1 , 𝑥2 ]
Prepared by Abe N
70
NUMERICAL METHODS
Continuing in the same manner, eventually we get:
𝑦 = 𝑦0 + (𝑥 − 𝑥0 )[𝑥0 , 𝑥1 ] + (𝑥 − 𝑥0 )(𝑥 − 𝑥1 )[𝑥0 , 𝑥1 , 𝑥2 ] + (𝑥 − 𝑥0 )(𝑥 − 𝑥1 )
(𝑥 − 𝑥2 )[𝑥0 , 𝑥1 , 𝑥2 , 𝑥3 ] + ⋯ + (𝑥 − 𝑥0 )(𝑥 − 𝑥1 ) … (𝑥 − 𝑥𝑛−1 )[𝑥0 , 𝑥1 , 𝑥2 , … , 𝑥𝑛 ]
(4.9)
Equation (4.9) is called Newton’s divided difference interpolation formula (NDDIF)
Example 4.3: Using Newton’s divided difference interpolation formula to find the interpolating
polynomial for the following data.
𝒙
−𝟏
𝟎
𝟏
𝟑
𝒚
2
1
0
−1
Solution: the DD table is:
x
1
y
Dy
2
D y
3
D y
2
1
0
1
0
1
24
1
1
1
6
0
3
1
1
2
The Newton’s divided difference formula is
𝑦 = 𝑦0 + (𝑥 − 𝑥0 )[𝑥0 , 𝑥1 ] + (𝑥 − 𝑥0 )(𝑥 − 𝑥1 )[𝑥0 , 𝑥1 , 𝑥2 ] +
(𝑥 − 𝑥0 )(𝑥 − 𝑥1 )(𝑥 − 𝑥2 )[𝑥0 , 𝑥1 , 𝑥2 , 𝑥3 ] + ⋯ +
(𝑥 − 𝑥0 )(𝑥 − 𝑥1 )(𝑥 − 𝑥2 ) … (𝑥 − 𝑥𝑛−1 )[𝑥0 , 𝑥1 , 𝑥2 , … 𝑥𝑛 ]
𝑦 = 2 + (𝑥 + 1)(−1) + (𝑥 + 1)(𝑥)(0) +
Prepared by Abe N
1
(𝑥 + 1)(𝑥)(𝑥 − 1)
24
71
NUMERICAL METHODS
=2−𝑥−1+
=1−𝑥+
1 2
(𝑥 − 1)(𝑥)
24
1 3
1 3
(𝑥 − 𝑥) =
(𝑥 − 25𝑥 + 24)
24
24
1
Therefore, 𝑦 = 𝑓(𝑥) = 24 (𝑥 3 − 25𝑥 + 24) is the interpolating polynomial using NDDIF.
Example 4.4: Using Newton’s divided difference interpolation formula find the interpolating
polynomial for the following data and evaluate it at 𝑥 = 1.5and 𝑥 = 8.
𝒙
𝟎
𝟏
𝟐
𝟒
𝟓
𝟔
𝒚
1
14 15
5
6
19
Solution: The DD table is:
x
y
0
1
Dy
2
3
4
5
Dy Dy Dy Dy
13
6
1 14
1
1
2
2 15
5
4
5
1
2
1
5
0
6
0
0
1
6
13
6 19
𝑓(𝑥) = 𝑦 = 𝑦0 + (𝑥 − 𝑥0 )[𝑥0 , 𝑥1 ] + (𝑥 − 𝑥0 )(𝑥 − 𝑥1 )[𝑥0 , 𝑥1 , 𝑥2 ] +
(𝑥 − 𝑥0 )(𝑥 − 𝑥1 )(𝑥 − 𝑥2 )[𝑥0 , 𝑥1 , 𝑥2 , 𝑥3 ] + ⋯
𝑦(𝑥) = 1 + (𝑥 − 0)(13) + (𝑥 − 0)(𝑥 − 1)(−6) + (𝑥 − 0)(𝑥 − 1)(𝑥 − 2)(1)
+(𝑥 − 0)(𝑥 − 1)(𝑥 − 2)(𝑥 − 4)(0) + 0
Prepared by Abe N
72
NUMERICAL METHODS
= 1 + 𝑥(13) − 6𝑥(𝑥 − 1) + 𝑥(𝑥 − 1)(𝑥 − 2) + 0 + 0
= 1 + 13𝑥 − 6𝑥 2 + 6𝑥 + 𝑥 3 − 3𝑥 2 + 2𝑥
= 𝑥 3 − 9𝑥 2 + 21𝑥 + 1
Therefore,𝑦(𝑥) = 𝑥 3 − 9𝑥 2 + 21𝑥 + 1 is the interpolating polynomial using NDDIF.
Hence,𝑓(1.5) = 1.53 − 9(1.5)2 + 21(. 5) + 1 = 15.625
and𝑓(8) = 83 − 9(8)2 + 21(8) + 1 = 105
Example4.5: construct the divided difference table and find the interpolating polynomial for the
following data points.
𝒙
𝟏
𝟐
𝟑
𝟓
𝟕
𝒚
3
5
9 11 15
Solution: DD table is given by:
x
y
1
3
2
5
Dy
D
2
y
3
D y
D
4
y
2
1
4
3
11
2
7
1
8
1
9
1
4
1
5
1
2
1
4
15
1
𝑦(𝑥) = 3 + 2(𝑥 − 1) + (1)(𝑥 − 1)(𝑥 − 2) + (− ) (𝑥 − 1)(𝑥 − 2)(𝑥 − 3)
2
1
+ (𝑥 − 1)(𝑥 − 2)(𝑥 − 3)(𝑥 − 5)
8
Prepared by Abe N
73
NUMERICAL METHODS
1
= (𝑥 4 − 15𝑥 3 + 73𝑥 2 − 11𝑥 + 78)
8
4.4.2. Lagrange’s interpolation formula (LIF) (2 hours)
Objective
At the end of this subtopicsudentssould beable to:
Understand the concept how to derive LIF.
Apply LIF to find the interpolating polynomial for a given data.
If 𝑦 = 𝑓(𝑥) takes the values 𝑦0 , 𝑦1 , … , 𝑦𝑛 corresponding to𝑥0 , 𝑥1 , … , 𝑥𝑛 , then 𝑦(𝑥) is given by:
𝑦(𝑥) =
(𝑥 − 𝑥1 )(𝑥 − 𝑥2 ) … (𝑥 − 𝑥𝑛 )
(𝑥 − 𝑥0 )(𝑥 − 𝑥2 ) … (𝑥 − 𝑥𝑛 )
(𝑦0 ) +
(𝑦 )
(𝑥0 − 𝑥1 )(𝑥0 − 𝑥2 ) … (𝑥0 − 𝑥𝑛 )
(𝑥1 − 𝑥0 )(𝑥1 − 𝑥2 ) … (𝑥1 − 𝑥𝑛 ) 1
(𝑥−𝑥 )(𝑥−𝑥 )…(𝑥−𝑥
)
𝑛−1
(𝑦 ) (4.10)
+ ⋯ + (𝑥 −𝑥 1)(𝑥 −𝑥2 )…(𝑥 −𝑥
) 𝑛
𝑛
0
𝑛
1
𝑛
𝑛−1
Or it can be written in compact form as
𝑛
𝑛
𝑓(𝑥) = ∑ 𝑓(𝑥𝑖 ) ∏ (
𝑖=0
𝑗=0
𝑗≠𝑖
𝑥 − 𝑥𝑗
)
𝑥𝑖 − 𝑥𝑗
Equation (1.10) is known as Lagrange’s interpolation formula (LIF).
Proof:
Let 𝑦 = 𝑓(𝑥) be a function which takes the value 𝑦0 , 𝑦1 , … , 𝑦𝑛 corresponding to𝑥0 , 𝑥1 , … , 𝑥𝑛 .
Since there are 𝑛 + 1 pairs of 𝑥 and y we can express𝑓(𝑥) as a polynomial in 𝑥 of degree 𝑛.
Let this polynomial be in the form:
𝑓(𝑥) = 𝑎0 (𝑥 − 𝑥1 )(𝑥 − 𝑥2 )(𝑥 − 𝑥3 ) … (𝑥 − 𝑥𝑛 ) + 𝑎1 (𝑥 − 𝑥0 )(𝑥 − 𝑥2 )(𝑥 − 𝑥3 ) … (𝑥 − 𝑥𝑛 )
+ ⋯ + 𝑎𝑛 (𝑥 − 𝑥0 )(𝑥 − 𝑥1 )(𝑥 − 𝑥2 ) … (𝑥 − 𝑥𝑛−1 ) (4.11)
Prepared by Abe N
74
NUMERICAL METHODS
Now put 𝑥 = 𝑥0 , 𝑦 = 𝑦0 in equation (4.11), we get
𝑦0 = 𝑎0 (𝑥0 − 𝑥1 )(𝑥0 − 𝑥2 )(𝑥0 − 𝑥3 ) … (𝑥0 − 𝑥𝑛 ) ⟹ 𝑎0
𝑦0
=
(𝑥0 − 𝑥1 )(𝑥0 − 𝑥2 )(𝑥0 − 𝑥3 ) … (𝑥0 − 𝑥𝑛 )
Similarly, by putting 𝑥 = 𝑥1 ,𝑦 = 𝑦1 in equation (4.11) we have
𝑦1 = 𝑎1 (𝑥1 − 𝑥0 )(𝑥1 − 𝑥1 )(𝑥1 − 𝑥2 ) … (𝑥1 − 𝑥𝑛 )
⟹ 𝑎1 =
𝑦1
(𝑥1 − 𝑥0 )(𝑥1 − 𝑥1 )(𝑥1 − 𝑥2 ) … (𝑥1 − 𝑥𝑛 )
Continuing in the same way we can obtain 𝑎2 ,𝑎3 , … , 𝑎𝑛 .
𝑎𝑛 =
𝑦𝑛
(𝑥𝑛 − 𝑥0 )(𝑥𝑛 − 𝑥1 )(𝑥𝑛 − 𝑥2 ) … (𝑥𝑛 − 𝑥𝑛−1 )
Substituting these values in equation (4.11) one can get equation (4.10).
Example 4.5: Use Lagrange’s interpolation formula (LIF) to find the interpolating polynomial
𝑓(𝑥) of the following data.
𝒙
𝟎
𝟏
𝟐
𝟒
𝒚
8
9
0
48
Solution:
𝑓(𝑥) =
(𝑥 − 1)(𝑥 − 2)(𝑥 − 4)
(𝑥 − 0)(𝑥 − 2)(𝑥 − 4)
(𝑥 − 0)(𝑥 − 1)(𝑥 − 4)
(8) +
(9) +
(0)
(−1)(−2)(−4)
(1 − 0)(1 − 2)(1 − 4)
(2 − 0)(2 − 1)(2 − 4)
+
(𝑥 − 0)(𝑥 − 1)(𝑥 − 2)
(48)
(4 − 0)(4 − 1)(4 − 2)
(𝑥 2 − 3𝑥 + 2)(𝑥 − 4)
(𝑥)(𝑥 2 − 6𝑥 + 8)
𝑥(𝑥 2 − 3𝑥 + 2)
(8) +
=
(9) + 0 +
(48)
−8
3
24
= −𝑥 3 + 3𝑥 2 − 2𝑥 + 4𝑥 2 − 12𝑥 + 8 + 3𝑥 3 − 18𝑥 2 + 24𝑥 + 2𝑥 3 − 6𝑥 2 + 4𝑥
= 4𝑥 3 − 17𝑥 2 + 14𝑥 + 8
Prepared by Abe N
75
NUMERICAL METHODS
Therefore, the interpolatingpolynomial is 𝑓(𝑥) = 4𝑥 3 − 17𝑥 2 + 14𝑥 + 8.
Example4.6: Given data
𝒙
-1
0
1
3
𝒚
2
1
0
-1
Then
(a) Find 𝑓(𝑥) using LIF.
(b) Evaluate 𝑓(𝑥)at 𝑥 = 2.
Solution:(a)
𝑓(𝑥) =
(𝑥 − 𝑥1 )(𝑥 − 𝑥2 ) … (𝑥 − 𝑥𝑛 )
(𝑥 − 𝑥0 )(𝑥 − 𝑥2 ) … (𝑥 − 𝑥𝑛 )
(𝑦0 ) +
(𝑦 ) + ⋯
(𝑥0 − 𝑥1 )(𝑥0 − 𝑥2 ) … (𝑥0 − 𝑥𝑛 )
(𝑥1 − 𝑥0 )(𝑥1 − 𝑥2 ) … (𝑥1 − 𝑥𝑛 ) 1
𝑥(𝑥−1)(𝑥−3)
𝑓(𝑥) = (−1)(−2)(−4) (2) +
(𝑥+2)(𝑥−1)(𝑥−3)
(1)(−1)(−3)
(1) +
(𝑥+1)(𝑥)(𝑥−3)
(2)(1)(−2)
(0) +
(𝑥+1)(𝑥)(𝑥−1)
(4)(3)(2)
(−1)
𝑥 3 − 4𝑥 2 + 3𝑥 𝑥 3 − 3𝑥 2 − 𝑥 + 3 −𝑥 3 + 𝑥
=
+
+
−4
3
24
=
1
(−6𝑥 3 + 24𝑥 2 − 18𝑥 + 8𝑥 3 − 24𝑥 2 − 8𝑥 + 24 − 𝑥 3 + 𝑥)
24
=
1
1
1 3
(𝑥 − 25𝑥 + 24)
24
−3
(b) 𝑓(2) = 24 (28 − 50 + 24) = 24 (−18) = 4
Summary
In this chapter we have learned:
Different types of difference operators, these are forward difference, backward difference
and centeral difference denoted by ∆, ∇ and𝛿 respectively.
In the case of equally spaced data points Newtonforward difference interpolation formula
and Newton backward differnec interpolation formula where as in the case of un equal
Prepared by Abe N
76
NUMERICAL METHODS
spaced data points we use Newton divided diefference interpolation formula and
Lagrange’s interpolation formula to find the interpolating polynomial for a given data.But
we can also use NDDIF and LIF in the case of equally spaced data.
Review exercise 4
1. Find the interpolating polynomial using NBDIF for the following data.
𝒙
𝟎
𝟏
𝟐
𝟑
𝒚
1
3
7
13
2. Find the interpolating polynomial using NFDIF for the following data
𝒙
𝟑
𝟒
𝟓
𝟔
𝒚
6
24
60
120
3. Use Lagrange’s formula to find the value of y at 𝑥 = 6 for the following data.
𝒙
𝟑
𝟕
𝟗
𝟏𝟎
𝒚
168
120
72
63
4. Given data
𝒙
𝟎
𝟐
𝟑
𝟔
𝒚
648 704 729 792
Then based on the given data:
(a) Find 𝑓(𝑥) using LIF.
(b) Evaluate 𝑓(𝑥) at𝑥 = 1.
Prepared by Abe N
77
NUMERICAL METHODS
CHAPTER 5
NUMERICAL DIFFERNTIATION AND INTEGRATION
5.1. Introduction
Why we need numerical differentation and integration?
The integrand can be an analytical function or a set of discrete points (tabulated data). When the
integrand is a mathematical expression for which the antiderivative can be found easily, the
value of the definite integral can be determined analytically. Numerical method is needed when
analytical differentiation and (or integration) is difficult or not possible, and when the integrand
is given as a set of discrete points.
Objective
At the end of this unit the learner would have been able to:
Define whatnumerical integration mean.
Differentiate analytical approach and numerical approach of differentation and integration
1
3
Identify where Simpson’s 3 and Simpson’s8 rules are used interms of number of
subintervals.
Solve problems using numerical differentiation and integration formulas.
Allowted time to complete this chapter is 8 hours
Prepared by Abe N
78
NUMERICAL METHODS
Activity 5.1
If 𝑓(𝑥) is given by the following table, then based on the data
a. Find the first derivative of 𝑓(𝑥)
6
b. Evaluate ∫0 𝑓(𝑥)𝑑𝑥
𝒙
0
1
2
3
4
5
6
𝒚
6.9897 7.4036 7.7815 8.1291 8.4510 8.7506 9.0309
5.2. Numerical differentiation (4 hours)
Objective
At the end of this topic the learner should be able to:
Differentiate analytical approach and numerical approach of differentation.
Solve problems using numerical differentiation formulas.
5.2.1. Derivatives using NFDIF
Consider Newton’s forward difference interpolation formula
𝑦(𝑥) = 𝑦0 + Δ𝑦0 𝑘 +
Δ2 𝑦0
Δ3 𝑦0
𝑘(𝑘 − 1) +
𝑘(𝑘 − 1)(𝑘 − 2)
2!
3!
Δ4 𝑦0
Δ𝑛 𝑦0
+
𝑘(𝑘 − 1)(𝑘 − 2)(𝑘 − 3) + ⋯ +
𝑘(𝑘 − 1)(𝑘 − 2) … (𝑘 − (𝑛 − 1))
4!
𝑛!
Where 𝑘 =
𝑥−𝑥0
ℎ
Δ2 𝑦0 2
Δ3 𝑦0 3
(𝑘 − 𝑘) +
(𝑘 − 3𝑘 2 + 2𝑘) +
𝑦(𝑥) = 𝑦0 + Δ𝑦0 𝑘 +
2!
3!
Δ4 𝑦0 4
(𝑘 − 6𝑘 3 + 11𝑘 2 − 6𝑘) + ⋯
4!
Prepared by Abe N
79
NUMERICAL METHODS
𝑑𝑦
𝑑𝑦 𝑑𝑘
𝑑𝑦 1
1 𝑑𝑦
𝑑𝑘
1
= 𝑑𝑘 𝑑𝑥 = 𝑑𝑘 ℎ = ℎ 𝑑𝑘 (Because𝑑𝑥 = ℎ)
𝑑𝑥
𝑑𝑦
Δ2 𝑦0
Δ3 𝑦0
Δ4 𝑦0
(3𝑘 2 − 6𝑘 + 2) +
(4𝑘 3 − 18𝑘 2 + 22𝑘 − 6) + ⋯
= Δ𝑦0 +
(2𝑘 − 1) +
𝑑𝑘
2!
3!
4!
𝑑𝑦
1
= ℎ[Δ𝑦0 +
𝑑𝑥
Δ2 𝑦0
(2𝑘 − 1) +
2!
Δ3 𝑦0
3!
(3𝑘 2 − 6𝑘 + 2) +
Δ4 𝑦0
4!
(4𝑘 3 − 18𝑘 2 + 22𝑘 − 6) + ⋯] (5.1)
By differentiating Eq. (5.1) with respect to 𝑥,we can obtaine the formula for second order
derivative as follows.
𝑑2 𝑦
𝑑
𝑑𝑦 𝑑𝑘
1
= 𝑑𝑘 (𝑑𝑘 ) 𝑑𝑥 = ℎ2[Δ𝑦0 +
𝑑𝑥 2
Δ2 𝑦0
(2𝑘 − 1) +
2!
Δ3 𝑦0
3!
(3𝑘 2 − 6𝑘 + 2)
Δ4 𝑦
+ 4! 0 (4𝑘 3 − 18𝑘 2 + 22𝑘 − 6) + ⋯]
5.2.2. Derivatives using backward difference interpolation formula (2 hours)
Consider Newton’s backward difference interpolation formula
𝑓(𝑥) = 𝑦𝑛 + ∇𝑦𝑛 𝑘 +
∇2 𝑦𝑛
∇3 𝑦𝑛
∇4 𝑦𝑛
𝑘(𝑘 + 1) +
𝑘(𝑘 + 1)(𝑘 + 2) +
𝑘(𝑘 + 1)(𝑘 + 2)(𝑘 + 3)
2!
3!
4!
+⋯+
∇𝑛 𝑦𝑛
𝑘(𝑘 + 1)(𝑘 + 2) … (𝑘 + (𝑛 − 1))
𝑛!
Differentiating both sides with respect to 𝑘,we get:
𝑑𝑦
∇2 𝑦𝑛
∇3 𝑦𝑛
∇4 𝑦𝑛
(2𝑘 + 1) +
(3𝑘 2 + 6𝑘 + 2) +
(4𝑘 3 + 18𝑘 2 + 22𝑘 + 6) + ⋯
= ∇𝑦𝑛 +
𝑑𝑘
2!
3!
4!
𝑘=
Since
𝑑𝑦
𝑑𝑥
𝑥 − 𝑥𝑛
𝑑𝑘 1
⟹
=
ℎ
𝑑𝑥 ℎ
𝑑𝑦 𝑑𝑘
= 𝑑𝑘 𝑑𝑥 ,we have
𝑑𝑦 1
∇2 𝑦𝑛
∇3 𝑦𝑛
∇4 𝑦𝑛
(2𝑘 + 1) +
(3𝑘 2 + 6𝑘 + 2) +
(4𝑘 3 + 18𝑘 2 + 22𝑘 + 6) + ⋯ ]
= [∇𝑦𝑛 +
𝑑𝑥 ℎ
2!
3!
4!
Again, differentiating the above equation, we get
Prepared by Abe N
80
NUMERICAL METHODS
𝑑2 𝑦
𝑑 𝑑𝑦 𝑑𝑘
1 𝑑 𝑑𝑦
1 𝑑 𝑑𝑦
1 𝑑 𝑑𝑦 𝑑𝑘
1 𝑑 𝑑𝑦
1 𝑑2𝑦
=
(
)=
( )=
( )=
(
)= 2
( ) = 2 ( 2)
𝑑𝑥 2 𝑑𝑥 𝑑𝑘 𝑑𝑥
ℎ 𝑑𝑥 𝑑𝑘
ℎ 𝑑𝑘 𝑑𝑥
ℎ 𝑑𝑘 𝑑𝑘 𝑑𝑥
ℎ 𝑑𝑘 𝑑𝑘
ℎ 𝑑𝑘
𝑑2 𝑦
∇4 𝑦
1
Hence,𝑑𝑥 2 = ℎ2 [∇2 𝑦𝑛 + ∇3 𝑦𝑛 (𝑘 + 1) + 12𝑛 (6𝑘 2 + 18𝑘 + 11) + ⋯ ]
Simlarly higher order derivatives can be obtained.
Example 5.1: Based on the following data find 𝑓 ′ (0) and 𝑓 ′′ (0)
𝒙
0
1
2
3
𝒚
1
3
9
21
Solution: The forward difference table for the data is given as follows
x y y y y
2
3
2
0
1
2
4
1
3
6
6
2
9
12
3
21
𝑑𝑦 1
∆2 𝑦0
∆3 𝑦0
∆4 𝑦0
2
(3𝑘 − 6𝑘 + 2) +
(4𝑘 3 − 18𝑘 2 + 22𝑘 − 6) + ⋯ ]
= [∆𝑦0 +
(2𝑘 − 1) +
𝑑𝑥 ℎ
2
3!
4!
And𝑥0 = 0, ℎ = 1, 𝑘 =
𝑓
′′ (𝑥)
𝑥−𝑥0
ℎ
2
= 𝑥, but here 𝑥 = 0 ⇒ 𝑓 ′ (0) = 2 + 2(−1) + 3 and
1 2
∆3 𝑦0
∆4 𝑦0
(12𝑘 2 − 36𝑘 + 22) + ⋯ ]
= 2 [∆ 𝑦0 +
(6𝑘 − 6) +
ℎ
6
4!
2
⇒ 𝑓 ′′ (0) = 4 + (−6) = 4 − 2 = 2
6
Example 5.2: Based on the folloeing date find 𝑓 ′′ (10) using the back-ward difference derivative
formula.
𝒙
0
2
4
6
8
10
𝒚
6
8
18
36
62
96
Prepared by Abe N
81
NUMERICAL METHODS
Solution:
x y y y y y y
2
3
4
0
6
2
8
2
4
18
10
8
6
36
18
8
0
8
62
26
8
0
0
10
96
34
8
0
0
5
0
The second order derivative formula is given by
𝑑2𝑦
1 2
∇4 𝑦𝑛
3 (𝑘
(6𝑘 2 + 18𝑘 + 11) + ⋯ ]
= [∇ 𝑦𝑛 + ∇ 𝑦𝑛 + 1) +
𝑑𝑥 2 ℎ2
12
𝑓 ′′ (𝑥) =
1 2
1
(∇
(8) = 2.
𝑦
+
0)
=
𝑛
ℎ2
4
Therefore 𝑓 ′′ (10) = 2
5.3.
Numerical Integration (4 hours)
Objective
At the end of this subtopic the learner should be able to:
Define whatnumerical integration means.
Differentiate analytical approach and numerical approach of integration.
1
3
Identify where Simpson’s 3 and Simpson’s8 rule are used interms of number of
subintervals.
Solve problems using numerical integration rules.
It is well observed that polynomial approximation serves as the basis for a variety of integral
formulas that is why we need to have studied some polynomial approximation techniques. The
main idea is, if𝑃(𝑥) is an approximation to 𝑓(𝑥) then
Prepared by Abe N
82
NUMERICAL METHODS
𝑏
𝑏
∫𝑎 𝑃(𝑥)𝑑𝑥 = ∫𝑎 𝑓(𝑥)𝑑𝑥
(5.2)
The basic procedure of numerical integration is to divide the range of interval of integration into
sub intervals and obtain the integral over each strip of the interval and by composing them one
can found the estimation of the integral over the the entire interval [𝑎, 𝑏]. Thus, if the range or
limits of integration is [𝑎, 𝑏] (actually points in[𝑥0 , 𝑥𝑛 ]), then the interval [𝑥0 , 𝑥𝑛 ] can be
subdivided into 𝑛equal sub interval as𝑥𝑖 = 𝑥0 + 𝑖ℎ,𝑖 = 1,2, … , 𝑛.The derivations of these
formulas are very essential to the learning of numerical integration. While they are interested in
the learning of the topic, it also helps in the understanding of the workings of these formulae
rather than trying to memorize them. The most acceptable way of deriving all these rules listed
above is by using the Newton forward formula or Newton backward formula. However, we shall
restrict our learning to the Newton Forward formula for deriving the integration formula in this
book. The Newton Forward interpolation formula is given by:
Δ2 𝑦0 2
Δ3 𝑦0 3
(𝑘 − 3𝑘 + 2𝑘)
𝑦(𝑥) = 𝑦0 + Δ𝑦0 𝑘 +
(𝑘 − 𝑘) +
2!
3!
Δ4 𝑦
+ 4! 0 (𝑘 4 − 6𝑘 3 + 11𝑘 2 − 6𝑘) + ⋯
; Where 𝑘 =
𝑥−𝑥0
ℎ
(5.3)
Substituting Eq. (5.3) in Eq. (5.2) we will have
𝑥𝑛
Δ2 𝑦0 2
Δ3 𝑦0 3
(𝑘
(𝑘 − 3𝑘 2 + 2𝑘) + … ) 𝑑𝑥
∫ 𝑓(𝑥)𝑑𝑥 = ∫ (𝑦0 + Δ𝑦0 𝑘 +
− 𝑘) +
2!
3!
𝑎
𝑏
𝑥0
𝑘=
𝑥 − 𝑥0
⟹ 𝑥 = 𝑥0 + 𝑘ℎ ⟹ 𝑑𝑘ℎ = 𝑑𝑥;
ℎ
When 𝑥 = 𝑥0 ⟹ 𝑘 = 0 and when 𝑥 = 𝑥𝑛 ⟹ 𝑘 = 𝑛.
𝑛
Δ2 𝑦0 2
Δ3 𝑦0 3
(𝑘 − 𝑘) +
(𝑘 − 3𝑘 2 + 2𝑘) + ⋯ ) 𝑑𝑘
𝐼 = ℎ ∫ (𝑦0 + Δ𝑦0 𝑘 +
2!
3!
0
𝑛
𝑘 2 Δ2 𝑦0 𝑘 3 𝑘 2
Δ3 𝑦0 𝑘 4
𝐼 = ℎ (𝑦0 𝑘 + Δ𝑦0 +
( − )+
( − 𝑘 3 + 𝑘 2 ) + ⋯ )|
2
2!
3
2
3!
4
0
Prepared by Abe N
83
NUMERICAL METHODS
𝑛 Δ2 𝑦0 𝑛2 𝑛
Δ3 𝑦0 𝑛3
𝐼 = ℎ𝑛 (𝑦0 + Δ𝑦0 +
( − )+
( − 𝑛2 + 𝑛) + ⋯ )
2
2!
3 2
3!
4
𝑛 Δ2 𝑦0
Δ3 𝑦0 3
2
(2𝑛
(𝑛 − 4𝑛2 + 4𝑛) + ⋯ )
𝐼 = ℎ𝑛 (𝑦0 + Δ𝑦0 +
− 3𝑛) +
2
12
24
𝐼 = ℎ𝑛 (𝑦0 + Δ𝑦0
𝑛 Δ2 𝑦0
Δ3 𝑦0
+
𝑛(2𝑛 − 3) +
𝑛(𝑛 − 2)2 + ⋯ )
2
12
24
This is called Newton-Cotes integration formula.
Based on Newton-Cotes integration formula, we will derive:
Trapezoidal rule (n =1)
1
Simpson’s 3 rule (n =2)
3
Simpson’s 8 rule (n =3)
5.3.1. Trapezoidal Rule (2 hours)
Applying Newton-Cotes integration formula using 𝑛 = 1 that is by taking a single interval at a
time[𝑥𝑖 , 𝑥𝑖+1 ],for 𝑖 = 0,1,2, … , 𝑛 − 1.
𝑥1
𝑛
ℎ
ℎ
∫ 𝑓(𝑥)𝑑𝑥 = ℎ𝑛 (𝑦0 + Δ𝑦0 ) = (2𝑦0 + Δ𝑦0 ) = (2𝑦0 + 𝑦1 − 𝑦0 )
2
2
2
𝑥0
𝑥
ℎ
1
∫𝑥 𝑓(𝑥)𝑑𝑥 = 2 (𝑦0 + 𝑦1 )is the area of the first stipe or trapzim?
0
In general the integral over the interval [𝑥𝑖 , 𝑥𝑖+1 ] is
𝑥𝑖+1
𝑛
ℎ
ℎ
ℎ
∫ 𝑓(𝑥)𝑑𝑥 = ℎ𝑛 (𝑦𝑖 + Δ𝑦𝑖 ) = (2𝑦𝑖 + Δ𝑦𝑖 ) = (2𝑦𝑖 + 𝑦𝑖+1 − 𝑦𝑖 ) = (𝑦𝑖 + 𝑦𝑖+1 )
2
2
2
2
𝑥𝑖
𝑏
𝑥𝑛
∫ 𝑓(𝑥)𝑑𝑥 = ∫
𝑎
𝑥0
𝑥1
𝑥2
𝑥𝑛
𝑓(𝑥)𝑑𝑥 = ∫ 𝑓(𝑥)𝑑𝑥 + ∫ 𝑓(𝑥)𝑑𝑥 + ⋯ + ∫
𝑥0
Prepared by Abe N
𝑥1
𝑓(𝑥)𝑑𝑥
𝑥𝑛−1
84
NUMERICAL METHODS
𝑏
∫ 𝑓(𝑥)𝑑𝑥 =
𝑎
𝑏
ℎ
ℎ
ℎ
ℎ
ℎ
(𝑦0 + 𝑦1 ) + (𝑦1 + 𝑦2 ) + (𝑦2 + 𝑦3 ) … + (𝑦𝑛−2 + 𝑦𝑛−1 ) + (𝑦𝑛−1 + 𝑦𝑛 )
2
2
2
2
2
ℎ
∫𝑎 𝑓(𝑥)𝑑𝑥 = 2 [𝑦0 + 2(𝑦1 + 𝑦2 + 𝑦3 + ⋯ + 𝑦𝑛−1 ) + 𝑦𝑛 ]
(5.4)
Equation (5.4) isknown as composite Trapezoidal rule.
5.3.2. Simpson’s one- third rule (1 hours)
By dividing the interval [𝑎, 𝑏] in to 𝑛 = 2𝑚 subintervals and taking two intervals at a time or by
putting 𝑛 = 2 in Newton-Cotes integration formula, for each 𝑖 = 0,1,2, … , 𝑛. that is:
𝑥2
𝑛 Δ2 𝑦0
(2𝑛2 − 3𝑛))
∫ 𝑓(𝑥)𝑑𝑥 = ℎ𝑛 (𝑦0 + Δ𝑦0 +
2
12
𝑥0
𝑥2
Δ2 𝑦0
6𝑦0 + 6y1 − 6𝑦0 (𝑦2 − 2𝑦1 + 𝑦0 )
∫ 𝑓(𝑥)𝑑𝑥 = 2ℎ (𝑦0 + Δ𝑦0 +
) = 2ℎ (
+
)
6
6
6
𝑥0
𝑥2
𝑦0 + 4y1 + 3𝑦2
ℎ
∫ 𝑓(𝑥)𝑑𝑥 = 2ℎ (
) = (𝑦0 + 4𝑦1 + 𝑦2 )
6
3
𝑥0
𝑥
ℎ
2
∫𝑥 𝑓(𝑥)𝑑𝑥 = 3 (𝑦0 + 4𝑦1 + 𝑦2 )is the area over the interval [𝑥0 , 𝑥2 ]
0
In general the integral over the interval [𝑥𝑖 , 𝑥𝑖+2 ] is
𝑥𝑖+2
𝑛 Δ2 𝑦𝑖
ℎ
(2𝑛2 − 3𝑛)) = (𝑦𝑖 + 4𝑦𝑖+1 + 𝑦𝑖+2 ), 𝑖 = 0,2, … , 𝑛 − 2.
∫ 𝑓(𝑥)𝑑𝑥 = ℎ𝑛 (𝑦𝑖 + Δ𝑦𝑖 +
2
12
3
𝑥𝑖
𝑏
𝑥𝑛
∫ 𝑓(𝑥)𝑑𝑥 = ∫
𝑎
𝑏
∫ 𝑓(𝑥)𝑑𝑥 =
𝑎
𝑥0
𝑥2
𝑥4
𝑥𝑛
𝑓(𝑥)𝑑𝑥 = ∫ 𝑓(𝑥)𝑑𝑥 + ∫ 𝑓(𝑥)𝑑𝑥 + ⋯ + ∫
𝑥0
𝑥2
𝑓(𝑥)𝑑𝑥
𝑥𝑛−2
ℎ
ℎ
ℎ
(𝑦0 + 4𝑦1 + 𝑦2 ) + (𝑦2 + 4𝑦3 + 𝑦4 ) + ⋯ + (𝑦𝑛−2 + 4𝑦𝑛−1 + 𝑦𝑛 )
3
3
3
Prepared by Abe N
85
NUMERICAL METHODS
𝑏
∫ 𝑓(𝑥)𝑑𝑥 =
𝑎
ℎ
[𝑦 + 4(𝑦1 + 𝑦3 + ⋯ + 𝑦𝑛−1 ) + 2(𝑦2 + 𝑦4 + 𝑦6 + ⋯ ) + 𝑦𝑛 ]
3 0
ℎ
⇒ 𝐼 = 3 (𝑦0 + 𝑦𝑛 + 4(𝑦1 + 𝑦3 + 𝑦5 + ⋯ + 𝑦𝑛−1 ) + 2(𝑦2 + 𝑦4 + ⋯ + 𝑦𝑛−2 ))
(5.5)
1
Equation (5) is called Simpson’s 3 rule.
1
Notethat: In Simpson’s 3 rulethe number ofsubinterval 𝑁must be even.
5.3.3. Simpson’s three-eight rule (1 hours)
By dividing the interval [𝑎, 𝑏] in to 𝑛 = 3𝑚, 𝑚 ∈ 𝑁 subintervals and taking three intervals at a
time and putting 𝑛 = 3 in Newton-Cotes integration formula, for each 𝑖 = 0,1,2, … , 𝑛 and
1
following the same procuder as that of Simpson’s 3one can obtain the following formula:
𝑏
3ℎ
∫𝑎 𝑓(𝑥) 𝑑𝑥 = 8 [𝑦0 + 𝑦𝑛 + 3(𝑦1 + 𝑦2 + 𝑦4 + 𝑦5 + ⋯ + 𝑦𝑛−1 ) + 2(𝑦3 + y6 + … +yn−3 ) ]
3
This is known as Composite Simpson’s 8 rule.
𝟑
Note that: In Simpson’s𝟖 rule the number of subintervals must be a multiple of 3.
Example5.3: Given
𝒙
0
𝒇(𝒙) 1
0.5
1
1.5
2
2.5
3
2.028
2.718
3.403
4.113
4.860
5.652
3
Based on the above data Evaluate ∫0 𝑓(𝑥) 𝑑𝑥 by using:
a. Trapezoidal rule
1
b. Simpson’s 3 rule
3
c. Simpson’s 8 rule
Solution:
3
ℎ
a. ∫0 𝑓(𝑥) 𝑑𝑥 = 2 [𝑦0 + 𝑦𝑛 + 2(𝑦1 + 𝑦2 + ⋯ + 𝑦𝑛−1 )]
Prepared by Abe N
86
NUMERICAL METHODS
=
0.5
[1 + 5.652 + 2(2.028 + 2.718 + 3.403 + 4.113 + 4.860)]
2
1
1
= [6.652 + 34.244] = [40.896] = 10.224.
4
4
3
ℎ
b. ∫0 𝑓(𝑥) 𝑑𝑥 = 3 [𝑦0 + 𝑦𝑛 + 4(𝑦1 + 𝑦3 + 𝑦5 … + 𝑦𝑛−1 ) + 2(𝑦2 + y4 + ⋯ yn−2 )]
=
0.5
[1 + 5.652 + 4(2.028 + 3.403 + 4.860) + 2(2.718 + 4.113)]
3
=
1
[6.652 + 41.164 + 13.662]
4
1
= 4 [61.478] ≈ 10.2463.
3
3ℎ
c. ∫0 𝑓(𝑥) 𝑑𝑥 = 8 [𝑦0 + 𝑦𝑛 + 3(𝑦1 + 𝑦2 + 𝑦4 + 𝑦5 … + 𝑦𝑛−2 + 𝑦𝑛−1 ) + 2(𝑦3 + y6 + ⋯ yn−3 )]
=
3
[1 + 5.652 + 3(2.028 + 2.718 + 4.113 + 4.86) + 2(3.403)]
16
=
=
3
[6.652 + 3(13.719) + 6.806]
16
3
3
[6.652 + 41.157 + 6.806] =
[54.615] ≈ 10.2403.
16
16
Summary
Numerical differentiation helps us to find rate of changes when the function is given at
desecrate points
Numerical integration is important to find integrals which are difficult to find analytically
or when the integrand is given in tabular form.
The Trapezoidal rule is obtained from Newton cote’s integration formula by taking 𝑛 = 1.
1
3
Simpson’s 3 and 8 rules are obtaind from Newton cote’s general integration formula by
putting 𝑛 = 2and 𝑛 = 3 respectively.
Prepared by Abe N
87
NUMERICAL METHODS
1
The number of sub interval in Simpson’s3 must be an even number or multiple of two,
3
where as in Simpson’s 8 the number of sub intervals must be multiple of three.
Reviewexercise 5
1. Given
𝒙
0
𝒇(𝒙) 1
0.5
1
1.5
2
2.5
3
2.028
2.718
3.403
4.113
4.860
5.652
3
Based on the above data Evaluate ∫0 𝑓(𝑥) 𝑑𝑥 by using:
(i). Trapezoidal rule
1
(ii).Simpson’s3 rule
3
(iii). Simpson’s 8 rule
2. The following table gives the velocity of a particle at time t.
𝒕(𝒊𝒏𝒔𝒆𝒄𝒐𝒏𝒅)
0
2
4
6
8
10
𝒗(𝒎/𝒔)
4
6
16
34
60
94
Based on the given data find
(i)
The acceleration of the particle at𝑡 = 4 sec.
(ii)
(ii) The distance covered in 10 sec.
3. Compute the first and second derivative at 𝑥 = 51 from the following data
𝒙
50
60
𝒚
19.96 36.65 58.81 77.21 94.61
1
70
2
80
90
3
4. Evaluate the integral of ∫0 𝑒 𝑥 𝑑𝑥 using Simpson 8 with ℎ = 0.1 method.
Prepared by Abe N
88
NUMERICAL METHODS
CHAPTER SIX
NUMERICAL SOLUTION OF ORDINARY DIFFERENTIAL EQUATIONS
6.1. Introduction
Numerical methods for differential equations are of grate importance to engineering, science and
mathematics because of the nature of practical problems. It is help ful to approximate the
solution of differential equations which are imposible to solve using the analytical method. Also,
there are differential equations for which the solutions interms of formulae are too complex so
that one prefers to use a numerical method to approximate the solution of such type of equations.
Objective
At the end of this unit the learner should be able to:
Define the term ordinary differential equation.
Know meaning of an intial value problem (IVP).
Apply Euler’s, Taylor series method and Runge-Kutta method to solve an initial value
problem (IVP).
Allowted time to complete this chapter is 8 hours
Activity 6.1
𝑑𝑦
𝑦 2 −𝑥 2
Given an IVP 𝑑𝑥 = 𝑦 2 +𝑥 2 , 𝑦(0) = 1, then find 𝑦(0.2) and 𝑦(0.4) with ℎ = 0.2.
Prepared by Abe N
89
NUMERICAL METHODS
Definition 6.1: A differential equation (DE) is an equation that involves a dependent variable
and its derivative with respect to one or more independent variables.
Definition6.2: A differential equation that involves only one independent variable is called an
ordinary differential equation (ODE) otherwise it is called a partial differential equation (PDE).
Example 6.1:
a. 𝑦 ′ = −𝑥 is an ODE
b. 𝑢𝑥𝑥 + 𝑢𝑦𝑦 = 0 is PDE
Definition6.3: A differential equation together with a specified condition at a point in the
independent variable is called an initial value problem (IVP).
In this chaper we shall be concerned with numerical methods for solving problems of the form
𝑑𝑦
= 𝑓(𝑥, 𝑦), 𝑎 ≤ 𝑥 ≤ 𝑏
𝑑𝑥
Subject to an initial condition 𝑦(𝑎) = 𝑦0
Such types of problems are called an initial value problem (IVP).
6.2. Euler’s Method(2hours)
Objective
At the end of this subtopic the learner would have been able to:
Define the term ordinary differential equation.
Know meaning of an intial value problem (IVP).
Apply Euler’s, method to solve an initial value problem (IVP).
This method is named after an enormously creative swiss mathematician Leonnered Euler (17071783). He studied under JhonBernolli and became a proffesser of mathematics in St. Petersburg;
Russia. Euler’s method is the simplest method of all numerical methods for solving ordinary
Prepared by Abe N
90
NUMERICAL METHODS
differential equations. Although this methodseldom used, it is realatively easy to analize, and it
will illustrate the centeral ideas involved in the constraction of some more advanced methods.
Suppose we want to approximate the solution of the IVP
𝑑𝑦
𝑑𝑥
= 𝑓(𝑥, 𝑦), 𝑦(𝑎) = 𝑦0 , 𝑎 ≤ 𝑥 ≤ 𝑏
(6.1)
To begin the presentation of Euler’s method, let us divide the interval [𝑎, 𝑏] in to 𝑁 equal
intervals and define the mesh points as
𝑥𝑖 = 𝑥0 + 𝑖ℎ = 𝑎 + 𝑖ℎfor𝑖 = 0,1,2, … , 𝑁 with ℎ =
𝑏−𝑎
𝑁
,ℎ is kown as the step size.
Derivation of Euler’s method
Suppose that the exact solution of Eq. (6.1) is 𝑦(𝑥) and has continuous derivative
on[𝑎, 𝑏]applying the Taylor series expansion of 𝑦(𝑥) about the point𝑥 = 𝑥𝑖 , that is
𝑦(𝑥) = 𝑦(𝑥𝑖 ) + 𝑦 ′ (𝑥𝑖 )(𝑥 − 𝑥𝑖 ) +
𝑦 ′′ (𝑥𝑖 )
2!
(𝑥 − 𝑥𝑖 )2 +
𝑦 (3) (𝑥𝑖 )
3!
(𝑥 − 𝑥𝑖 )3 + ⋯
(6.2)
By evaluating Eq. (6.1) 𝑥 = 𝑥𝑖+1 we get
𝑦(𝑥𝑖+1 ) = 𝑦(𝑥𝑖 ) + 𝑦 ′ (𝑥𝑖 )(𝑥𝑖+1 − 𝑥𝑖 ) +
𝑦 ′′ (𝑥𝑖 )
𝑦 (3) (𝑥𝑖 )
(𝑥𝑖+1 − 𝑥𝑖 )2 +
(𝑥𝑖+1 − 𝑥𝑖 )3 + ⋯
2!
3!
By neglecting second and higher order derivatives one can get:
𝑦(𝑥𝑖+1 ) = 𝑦(𝑥𝑖 ) + 𝑦′(𝑥𝑖 )(𝑥𝑖+1 − 𝑥𝑖 )
𝑦(𝑥𝑖+1 ) = 𝑦(𝑥𝑖 ) + 𝑦′(𝑥𝑖 )ℎ Where ℎ = 𝑥𝑖+1 − 𝑥𝑖 for each 𝑖 = 0,1, … , 𝑁 − 1
𝑦𝑖+1 ≈ 𝑦𝑖 + 𝑦𝑖 ′ℎ , Since 𝑦′ = 𝑓(𝑥, 𝑦) we can write as
𝑦𝑖+1 ≈ 𝑦𝑖 + ℎ𝑓(𝑥𝑖 , 𝑦𝑖 , for 𝑖 = 0,1, … , 𝑁 − 1
(6.3)
Eq. (6.3) is called Euler’s method
The method is very slow and to obtain more accuracy the value of ℎ should be very small and
naturally it needs more computational time.
Prepared by Abe N
91
NUMERICAL METHODS
Example 6.2: Using Euler’s method solve the IVP 𝑦′ = 𝑦 + 𝑥 2 , 𝑦(0) = 1 , for 0 ≤ 𝑥 ≤ 0.1.
Withℎ = 0.01
Solution: The formula forEuler’s methodis
𝑦𝑖+1 = 𝑦𝑖 + 𝑦𝑖 ′ℎ, 𝑖 = 0,1, … , 𝑛 − 1
Given 𝑦(0) = 1,0 ≤ 𝑥 ≤ 0.1
and ℎ = 0.01
𝑦1 = 𝑦0 + 𝑦0′ ℎ = 𝑦0 + ℎ𝑓(𝑥0 , 𝑦0 ) (∵ 𝑦 ′ = 𝑓)
= 1 + 0.01𝑓(0,1) = 1 + 0.01(1 + 02 ) = 1 + 0.02(1) = 1 + 0.02 = 1.01
⟹ 𝑦1 = 𝑦(𝑥1 ) = 𝑦(0.01) = 1.01
𝑦2 = 𝑦1 + 𝑦1′ ℎ = 𝑦1 + ℎ𝑓(𝑥1 , 𝑦1 ) = 1.01 + 0.01𝑓(0.01,1.01)
= 1.01 + (1.01 + (0.01)2 ) = 1.01 + 0.01(1.01 + 0.0001)
= 1.01 + 0.01(1.0101) = 1.01 + 0.010101 = 1.020101
and so on. The complete solution is given below using C++ program.
The solution using Euler's Method is:
𝑖
𝑥𝑖
𝑦(𝑥𝑖 )
1
2
3
4
5
6
7
8
9
10
0.01
0.02
0.03
0.04
0.05
0.06
0.07
0.08
0.09
0.10
1.0100000
1.0201010
1.0303060
1.0406181
1.0510403
1.0615757
1.0722274
1.0829986
1.0938926
1.1049125
Example6.3: Using Euler’s method solve the IVP 𝑦 ′ = 𝑦 2 − 𝑥 2 , 𝑦(0) = 1 , for 0 ≤ 𝑥 ≤ 1.
Prepared by Abe N
92
NUMERICAL METHODS
Withℎ = 0.1
Solution: Given 𝑓(𝑥, 𝑦) = 𝑦 2 − 𝑥 2 , ℎ = 0.1, 𝑥0 = 0, 𝑦0 = 1
The formula for Euler’s method is given as
𝑦𝑖+1 = 𝑦𝑖 + ℎ𝑓(𝑥𝑖 , 𝑦𝑖 )
𝑦1 = 𝑦0 + ℎ𝑓(𝑥0 , 𝑦0 )
= 1 + 0.1(12 − 0) = 1.1
𝑦2 = 𝑦1 + ℎ𝑓(𝑥1 , 𝑦1 )
= 1.1 + 0.1[(1.1)2 − (0.1)2 ] = 1.22
In general, all the results are given in table 6.1.
Enter the values of xo, yo, xn, n:
0 1 1 10
ℎ = 0.100000
The solution using Euler's Method is:
Table 6.1 ______________________
𝑖𝑥[𝑖]
𝑦(𝑥[𝑖])
______________________________
1
0.10 1.1000000
2
0.20 1.2200000
3
0.30 1.3648400
4
0.40 1.5421189
5
0.50 1.7639320
6
0.60 2.0500777
7
0.70 2.4343596
8
0.80 2.9779701
9
0.90 3.8008008
10 1.00 5.1644096
_________________________
Prepared by Abe N
93
NUMERICAL METHODS
6.3. Modified Euler’s Method (2 hours)
Objective
At the end of this subtopic the learner would have been able to:
Apply modified Euler’s method to solve an initial value problem (IVP).
Understand the difference between Euler’s method and modified Euler’s method.
1
If we approximate𝑓(𝑥, 𝑦) by 2 [𝑓(𝑥0 , 𝑦0 ) + 𝑓(𝑥1 , 𝑦1 )] instead of 𝑓(𝑥0 , 𝑦0 ) in the derivation of
Euler’s method then we have
ℎ
𝑦1∗ = 𝑦0 + 2 [𝑓(𝑥0 , 𝑦0 ) + 𝑓(𝑥1 , 𝑦1 )]
(6.4)
The values of 𝑦1 can be obtained by Euler’s method and the ∗symbol in the super script case
denotes the modified value of 𝑦1 .Proceeding in the same way if we approximate 𝑓(𝑥, 𝑦) by
1
2
[𝑓(𝑥𝑛 , 𝑦𝑛 ) + 𝑓(𝑥𝑛+1 , 𝑦𝑛+1 )] instaed of 𝑓(𝑥𝑛 , 𝑦𝑛 ),then we have
1
∗
𝑦𝑛+1
= 𝑦𝑛 + 2 [𝑓(𝑥𝑛 , 𝑦𝑛 ) + 𝑓(𝑥𝑛+1 , 𝑦𝑛+1 )]
(6.5)
Where the value of 𝑦𝑛+1 can be obtained by Euler’s formula that is
𝑦𝑛+1 = 𝑦𝑛 + ℎ𝑓(𝑥𝑛 , 𝑦𝑛 )
Equation (6.8) is known as modified Euler’s method
𝑑𝑦
Working rule: If we wish to solve 𝑑𝑥 = 𝑓(𝑥, 𝑦), 𝑦(𝑥0 ) = 𝑦0
Step 1: solve the given equation by Euler’s method to get the solution at 𝑥 = 𝑎.
Step2: substitute the value of 𝑦(𝑥 = 𝑎) obtained in step 1 in to the modified Euler’s formula.
𝑑𝑦
Example 6.5: Solve 𝑑𝑥 = 𝑥 2 + 𝑦, 𝑦(0) = 1 by using modified Euler’s method with ℎ = 0.01.
Solution:𝑦1 = 𝑦0 + ℎ𝑓(𝑥0 , 𝑦0 ) = 1 + 0.01(𝑥02 + 𝑦0 ) = 1 + 0.01(02 + 1) = 1.01
Applying Euler’s formula, we have
Prepared by Abe N
94
NUMERICAL METHODS
ℎ
0.01 2
[0 + 1 + (0.01)2 + 1.01] = 1.01005
𝑦1∗ = 𝑦0 + [𝑓(𝑥0 , 𝑦0 ) + 𝑓(𝑥1 , 𝑦1 )] = 1 +
2
2
𝑦2 = 𝑦1 + ℎ𝑓(𝑥1 , 𝑦1 ) = 1.01 + 0.01[0.012 + 1.01] = 1.0201010
ℎ
0.01
𝑦2∗ = 𝑦1 + [𝑓(𝑥1 , 𝑦1 ) + 𝑓(𝑥2 , 𝑦2 )] = 1.01 +
[0.012 + 1.01 + 0.022 + 1.0201010]
2
2
= 1.01 + 0.005[2.030601] = 1.020153005 ≈ 1.020153and so on.
6.4. Taylor series Method of order N (2 hours)
Objective
At the end of this subtopic the learner should be able to:
Find partial derivatives of the given IVP.
Apply Taylor series method method to solve an initial value problem (IVP).
Euler’s method was derived from the Taylor series using two terms in the series.We can
construct an approximate solution of the IVP using a large number of terms. Assuming that the
solution 𝑦(𝑥)of the IVP has 𝑛 + 1 continuous derivatives and expanding 𝑦(𝑥) about 𝑥0 using
Taylor series expanision we have
𝑦(𝑥) = 𝑦(𝑥0 ) + 𝑦 ′ (𝑥0 )(𝑥 − 𝑥0 ) +
+
𝑦 (4) (𝑥0 )
4!
(𝑥 − 𝑥𝑖 )2 + ⋯ +
𝑦 (𝑛) (𝑥0 )
Where remainder term 𝑅 =
𝑛!
𝑦 ′′ (𝑥0 )
𝑦 ′′′ (𝑥0 )
(𝑥 − 𝑥0 )2 +
(𝑥 − 𝑥0 )3
2!
3!
(𝑥 − 𝑥0 )𝑛 + 𝑅
𝑦 (𝑛+1) (𝜂)
(𝑛+1)!
(6.6)
(𝑥 − 𝑥0 )𝑛+1 ; for some 𝜂𝜖(𝑥0 , 𝑥𝑛 )
Alternatively, we can write in the following form:
Evaluating it at 𝑥 = 𝑥𝑖+1
𝑦(𝑥𝑖+1 ) = 𝑦(𝑥𝑖 ) + 𝑦 ′ (𝑥𝑖 )ℎ +
ℎ2 ′′
ℎ3 ′′′
ℎ𝑛 (𝑛)
𝑦 (𝑥𝑖 ) + 𝑦 (𝑥𝑖 ) + ⋯ + 𝑦 (𝑥𝑖 )
2!
3!
𝑛!
Prepared by Abe N
95
NUMERICAL METHODS
By denoting 𝑦(𝑥𝑖 ) ≈ 𝑦𝑖 we can write
ℎ2 ′′ ℎ3 ′′′ ℎ4 (4)
ℎ𝑛 (𝑛)
𝑦𝑖 + 𝑦𝑖 + 𝑦𝑖 + ⋯ + 𝑦𝑖
2!
3!
4!
𝑛!
𝑦𝑖+1 = 𝑦𝑖 + 𝑦𝑖′ ℎ +
Where ℎ = 𝑥𝑖+1 − 𝑥𝑖
for 𝑖 = 0,1,2, … , 𝑛
Or 𝑦𝑖+1 = 𝑦𝑖 + 𝜓𝑛 (𝑥𝑖 , 𝑦𝑖 )
ℎ2
(6.7)
(ℎ)3
ℎ4
(4)
Where 𝜓𝑛 (𝑥𝑖 , 𝑦𝑖 ) = 𝑦𝑖′ ℎ + 2! 𝑦𝑖′′ + 3! 𝑦𝑖′′′ + 4! 𝑦𝑖
ℎ𝑛
(𝑛)
+ ⋯ + 𝑛! 𝑦𝑖
The above sechm is easy for computer programming.
We obtain the derivatives using chain rule. Thus, the first few derivatives are:
𝑦 ′ (𝑥) = 𝑓(𝑥, 𝑦)
𝑦 ′′ (𝑥) =
𝑦 ′′′ (𝑥) =
𝑑𝑓 𝜕𝑓 𝜕𝑓 𝑑𝑦
=
+
= 𝑓𝑥 + 𝑓𝑦 𝑓
𝑑𝑥 𝜕𝑥 𝜕𝑦 𝑑𝑥
𝝏 𝝏𝒇 𝝏𝒇 𝒅𝒚
𝝏 𝝏𝒇 𝝏𝒇 𝒅𝒚 𝒅𝒚
( +
)+
( +
)
𝝏𝒙 𝝏𝒙 𝝏𝒚 𝒅𝒙
𝝏𝒚 𝝏𝒙 𝝏𝒚 𝒅𝒙 𝒅𝒙
= (𝑓𝑥𝑥 + 𝑓𝑥𝑦 𝑓 + 𝑓𝑦 𝑓𝑥 ) + (𝑓𝑥𝑦 + 𝑓𝑦𝑦 𝑓 + 𝑓𝑦 𝑓𝑦 )𝑓
= 𝑓𝑥𝑥 + 2𝑓𝑥𝑦 𝑓 + 𝑓𝑦 𝑓𝑥 + 𝑓𝑦𝑦 𝑓 2 + 𝑓𝑦2 𝑓
Example 6.5: Using Third order Taylor’s Method approximate the solution of the IVP
𝑑𝑦
𝑑𝑥
= 2𝑥 − 𝑦, 𝑦(0) = −1,0 ≤ 𝑥 ≤ 1 With 𝑁 = 5
Solution: The first two derivatives of 𝑓(𝑥, 𝑦) are
𝑦 ′′ = 𝑓 ′ (𝑥, 𝑦) = 2 − 𝑦 ′ = 2(1 − 𝑥) + 𝑦
𝑦 ′′′ = 𝑓 ′′ (𝑥, 𝑦) = −2 + 𝑦 ′ = 2(𝑥 − 1) − 𝑦
𝑦0′ = 𝑦 ′ (𝑥0 ) = 1; 𝑦0′′ = 𝑦 ′′ (𝑥0 ) = 1; 𝑦 ′′′ (𝑥0 ) = −1
Substituting these values in the formula, we get:
Prepared by Abe N
96
NUMERICAL METHODS
𝑥2 𝑥3
𝑦(𝑥) = −1 + 𝑥 + −
2
6
Since 𝑁 = 5 ⟹ ℎ = 0.2
(0.2)2 (0.2)3
𝑦(0.2) = 𝑦(𝑥1 ) = −1 + 0.2 +
−
= −0.7813
2
6
𝑦(0.4) = −1 + 0.4 +
(0.4)2 (0.4)3
−
= −0.5307
2
6
(0.6)2 (0.6)3
𝑦(0.6) = −1 + 0.6 +
−
= −0.256
2
6
𝑦(0.8) = −1 + 0.8 +
(0.8)2 (0.8)3
−
= 0.03467
2
6
𝑦(1) = −1 + 1 +
1 1
− = 0.5
2 6
Example 6.6: Obtain the first five nonzero terms in the Taylor’s series solution of the initial
𝑑𝑦
value problem 𝑑𝑥 = 𝑥 2 + 𝑦 2 , 𝑦(0) = 1.And compute 𝑦(0.1)and 𝑦(0.2).
Solution: Taylor series method with five terms is
𝑦(𝑥) = 𝑦0 + 𝑦0′ (𝑥 − 𝑥0 ) + 𝑦0′′
(𝑥−𝑥0 )2
2
+ 𝑦0′′′
(𝑥−𝑥0 )3
3!
+𝑦0𝑖𝑣
(𝑥−𝑥0 )4
4!
Here 𝑦(0) = 1, 𝑦 ′ = 𝑥 2 + 𝑦 2
𝑦 ′′ = 2𝑥 + 2𝑦𝑦 ′
𝑦 ′′′ = 2 + 2[𝑦𝑦 ′ + (𝑦 ′ )2 ]
𝑦 𝑖𝑣 = 2[𝑦𝑦 ′′′ + 𝑦 ′′ 𝑦 ′ + 2𝑦′𝑦′′]
𝑦0′ = 0 + 1 = 1; 𝑦0′′ = 0 + 2(1)(1) = 2; 𝑦0′′′ = 2 + 2[1 × 2 × 12 ] = 8;
𝑦0𝑖𝑣 = 2[1 × 8 + 2 × 1 + 2 × 1 × 2] = 28
4
7
Therefore, 𝑦(𝑥) = 1 + 𝑥 + 𝑥 2 + 3 𝑥 3 + 6 𝑥 4
Prepared by Abe N
97
NUMERICAL METHODS
Putting 𝑥 = 0.1 and 0.2in 𝑦(𝑥),we get
4
7
𝑦(0.1) = 1 + 0.1 + (0.1)2 + (0.1)3 + (0.1)4 = 1.11145
3
4
4
7
𝑦(0.2) = 1 + 0.2 + (0.2)2 + (0.2)3 + (0.2)4 = 1.25253
3
4
6.5. Runge-Kutta Method (2hours)
Objective
At the end of this subtopic students should be able to fourth order Runge-Kutta method to
solve an IVP.
Runge-Kutta Method is one of the most widly used method. It is named after two German
mathematicians Carl Runge (1856-1927) and Wilhem Kutta (1867-1944). It is particularly
suitable in cases when the computation of higher order derivatives is difficult, in this case it will
be difficult to apply higher order Taylor series method. But the Runge-Kutta methods aviode this
difficulty since no need of differentiation in the Runge–Kutta method and gives the same
accuracy as that of Taylor series method of the same order. There are different order RungeKutta methods but popular and most commonly used Runge-Kutta method is the fourth order
Runge-Kutta method (4RKM) given by the formula:
1
𝑦𝑖+1 = 𝑦𝑖 + [𝑘1 + 2(𝑘2 + 𝑘3 ) + 𝑘4 ]
6
Where 𝑘1 = ℎ𝑓(𝑥𝑖 , 𝑦𝑖 )
𝑘2 = ℎ𝑓 (𝑥𝑖 +
ℎ
𝑘1
, 𝑦𝑖 + )
2
2
𝑘3 = ℎ𝑓 (𝑥𝑖 +
ℎ
𝑘2
, 𝑦𝑖 + )
2
2
𝑘4 = ℎ𝑓(𝑥𝑖 + ℎ, 𝑦𝑖 + 𝑘3 )
Prepared by Abe N
98
NUMERICAL METHODS
𝑑𝑦
Example 6.7: Solve 𝑑𝑥 = 𝑥𝑦, 𝑦(1) = 2, for 𝑥 = 1.4 using 4RKM with ℎ = 0.2.
𝑑𝑦
Solution: Given 𝑥0 = 1, 𝑦0 = 2, 𝑑𝑥 = 𝑓(𝑥, 𝑦) = 𝑥𝑦, ℎ = 0.2
𝑘1 = ℎ𝑓(𝑥0 , 𝑦0 ) = 0.2𝑓(1,2) = 0.2(2) = 0.4
ℎ
𝑘1
0.2
0.4
𝑘2 = ℎ𝑓 (𝑥0 + , 𝑦0 + ) = 0.2𝑓 (1 +
,2 +
) = 0.2𝑓(1.1,2.2) = 0.484
2
2
2
2
ℎ
𝑘2
𝑘3 = ℎ𝑓 (𝑥0 + , 𝑦0 + ) = 0.2𝑓(1.1,2.242) = 0.4932
2
2
𝑘4 = ℎ𝑓(𝑥0 + ℎ, 𝑦0 + 𝑘3 ) = 0.2𝑓(1.2,2.4932) = 0.5984
1
𝑦1 = 𝑦0 + (𝑘1 + 2(𝑘2 + 𝑘3 ) + 𝑘4 )
6
1
𝑦1 = 2 + (0.4 + 2(0.484 + 0.4932) + 0,5984) = 2 + 0.4921 = 2.4921
6
1
𝑦2 = 𝑦1 + 6 (𝑘1 + 2(𝑘2 + 𝑘3 ) + 𝑘4 )
𝑘1 = ℎ𝑓(𝑥1 , 𝑦1 ) = 0.2𝑓(1.2,2.4921) = 0.5981
ℎ
𝑘1
0.2
0.5981
𝑘2 = ℎ𝑓 (𝑥1 + , 𝑦1 + ) = 0.2𝑓 (1.2 +
, 2.4921 +
) = 0.2𝑓(1.3,2.7912)
2
2
2
2
= 0.7257
ℎ
𝑘2
0.7257
𝑘3 = ℎ𝑓 (𝑥1 + , 𝑦1 + ) = 0.2𝑓 (1.3,2.4921 +
) = 0.7423
2
2
2
𝑘4 = ℎ𝑓(𝑥1 + ℎ, 𝑦1 + 𝑘3 ) = 0.2𝑓(1.4,3.2344) = 0.9056
1
𝑦2 = 2.4921 + (0.5981 + 2(0.7257 + 0.7423) + 0.9056) = 2.4921 + 0.7400 = 3.2321
6
Therefore,𝑦(1.2) = 𝑦1 = 2.4921and 𝑦(1.4) = 𝑦2 = 3.2321.
𝑑𝑦
Example 6.8: Solve the IVP 𝑑𝑥 = 𝑥 + 𝑦, 𝑦(0) = 1using fourth order Runge-Kutta method for
0 ≤ 𝑥 ≤ 0.8 with ℎ = 0.1.
Prepared by Abe N
99
NUMERICAL METHODS
Solution: Here 𝑓(𝑥, 𝑦) = 𝑥 + 𝑦, ℎ = 0.1, 𝑥0 = 0, 𝑦0 = 1
𝑘1 = ℎ𝑓(𝑥0 , 𝑦0 ) = 0.1𝑓(0,1) = 0.1(1) = 0.1
ℎ
𝑘1
0.1
0.1
𝑘2 = ℎ𝑓 (𝑥0 + , 𝑦0 + ) = 0.1𝑓 (0 +
,1 +
) = 0.1(0.05 + 1.05) = 0.11
2
2
2
2
ℎ
𝑘2
𝑘3 = ℎ𝑓 (𝑥0 + , 𝑦0 + ) = 0.1(0.05 + 1.055) = 0.1105
2
2
𝑘4 = ℎ𝑓(𝑥0 + ℎ, 𝑦0 + 𝑘3 ) = 0.1(0.1 + 1.1105) = 0.1211
1
𝑦1 = 𝑦0 + (𝑘1 + 2(𝑘2 + 𝑘3 ) + 𝑘4 )
6
1
= 1 + (0.1 + 0.22 + 0.2210 + 0.12105) = 1.11034
6
Therefore,𝑦1 = 𝑦(𝑥1 ) = 𝑦(0.1) = 1.11034
Similarly, one can obtain the rest of the results.
In general, the solutions using c++ are given in table 6.2.
Enter the values of x0,y0,xn,n:
0 1 0.8 8
The solution using 4RKM is:
Table 6.2____________________________________________________________
𝑖𝑥𝑖 k1 k 2 k 3 k 4 k𝑦𝑖
____________________________________________________________
1 0.10 0.1000 0.1100 0.1105 0.1211
0.1103 1.1103
2 0.20
0.1210
0.1321
0.1326
0.1443
0.1325
1.2428
3 0.30
0.1443
0.1565
0.1571
0.1700
0.1569
1.3997
4 0.40
0.1700
0.1835
0.1841
0.1984
0.1839
1.5836
5 0.50
0.1984
0.2133
0.2140
0.2298
0.2138
1.7974
6 0.60
0.2297
0.2462
0.2471
0.2644
0.2468
2.0442
Prepared by Abe N
100
NUMERICAL METHODS
7 0.70
0.2644
0.2826
0.2836
0.3028
0.2833
2.3275
8 0.80 0.3028 0.3229 0.3239 0.3451
0.3236 2.6511
___________________________________________________________
Example6.9: Using 4RKM approximate the solution of the IVP
𝑑𝑦
𝑑𝑥
= 2𝑥 − 𝑦, 𝑦(0) = −1,0 ≤ 𝑥 ≤ 1With 𝑛 = 10.
Solution: The resultsusing C++programming are given in table 6.3.
Enter the values of x0, y0, xn, n:
0 -1 1 10
The solution using 4RKM is:
Table 6.3____________________________________________________________________
𝑖 𝑥𝑖 k1 k 2 k 3 k 4 k𝑦𝑖
____________________________________________________________________________________________
1 0.10 0.100000 0.105000 0.104750 0.109525 0.104837 -0.895163
2
0.20 0.109516 0.114040 0.113814 0.118135
0.113893 -0.781269
3
0.30 0.118127 0.122221 0.122016 0.125925
0.122088 -0.659182
4
0.40 0.125918 0.129622 0.129437 0.132974
0.129502 -0.529680
5
0.50 0.132968 0.136320 0.136152 0.139353
0.136211 -0.393469
6 0.60 0.139347 0.142380 0.142228 0.145124
0.142281 -0.251188
7
0.70 0.145119 0.147863 0.147726 0.150346
0.147774 -0.103414
8
0.80 0.150341 0.152824 0.152700 0.155071
0.152744
0.049329
9
0.90 0.155067 0.157314 0.157201 0.159347
0.157241
0.206570
10
1.00 0.159343 0.161376 0.161274 0.163216
0.161310
0.367880
___________________________________________________________________
𝑑𝑦
Example 6:10: Solve the IVP 𝑑𝑥 = 𝑥 + 2𝑦 , 𝑦(1) = 0 for 1 ≤ 𝑥 ≤ 4withℎ = 0.5 using 4RKM.
Solution: The resultsusing C++programming are given in table 6.4.
Prepared by Abe N
101
NUMERICAL METHODS
Enter the values of xo, yo, xn, n:
1046
The solution using 4RKM is:
Table
6.4___________________________________________________________________________
𝑖𝑥𝑖 𝑘1 𝑘2 𝑘3 𝑘4 k𝑦𝑖
_____________________________________________________________________________
1 1.50 0.500000
0.875000
1.062500
1.812500
1.031250
1.031250
2
2.00
1.781250
2.796875
3.304688
5.335938
3.220052
4.251302
3
2.50
5.251302
8.001953
9.377278
14.878580
9.148058
13.399360
4
3.00
14.649360
22.099039
25.823879
40.723240
25.203074
38.602432
5
3.50
40.102432
60.278648
70.366760
110.719193
68.685410
107.287842
6 4.00 109.037842 163.681763 191.003723 300.291565 186.450058 293.737915
______________________________________________________________________________
Summary
Euler’s method, Taylor’s series method and Runge-Kutta method helps us to
approximate the solution of Ordinary differential equations discussewhen the
analytical solution is difficult or impposible.
In Euler’s method, to get a better approximation the step size should be semall
enough.
Taylor’s method has the disadvantage of finding higher order partial derivatives
when the given problem is not simpleeventhough it gives a better approximation.
Fourth order Runge-Kutta method avoides the need of derivatives the involved in
the case of Taylor’s series method and gives nearly the same result as the Taylor’s
series method of reapective order.
Runge kutta method is easy to program in a compuer language.
Prepared by Abe N
102
NUMERICAL METHODS
Review exercise 6
𝑑𝑦
1. Solve the IVP 𝑑𝑥 = 𝑦𝑥 2 − 𝑦, 𝑦(0) = 1,0 ≤ 𝑥 ≤ 1, ℎ = 0.25 using Euler’s method.
2. Use Euler’s method to approximate the solution of each of the following IVPs.
a.
b.
c.
𝑑𝑦
𝑑𝑥
𝑑𝑦
1
= −5𝑦 + 5𝑥 2 + 2𝑥, 0 ≤ 𝑥 ≤ 1, 𝑦(0) = 3 , ℎ = 0.1.
𝑦2
𝑦
= 𝑥 − 𝑥 2 , 1 ≤ 𝑥 ≤ 2, 𝑦(1) = 0, ℎ = 0.2.
𝑑𝑥
𝑑𝑦
𝑑𝑥
= −(𝑦 + 1)(𝑦 + 3), 0 ≤ 𝑥 ≤ 2, 𝑦(0) = −2, ℎ = 0.2.
3. Given an IVP
𝑑𝑦
𝑑𝑥
= 𝑥 2 + 𝑥 2 𝑦, 1 ≤ 𝑥 ≤ 2,withℎ = 0.2. Solve using
a. Fourth order Tayler series method.
b. Fourth order Rungr-Kutta method.
𝑑𝑦
4. Solve the IVP 𝑑𝑥 = 𝑥 + 𝑦 2 , 𝑦(1) = 0 for 1 ≤ 𝑥 ≤ 2withℎ = 0.1 using 4RKM.
Prepared by Abe N
103
NUMERICAL METHODS
Reference
[1]. Dr.B. sGrawal; Introduction to Numerical methods.
[2]. Richard L. Burden and Faries; Numerical Analysis 9th edition.
[3]. AmostGilat and VishSubramaniam; Numerical methods an introduction with application
usingmathlab second edition 2011.
[4]. J.B. DIXIT; Numerical Methods first edition 2010.
[5]. AbdelwahabKharab and Ronald B. Guenther; An introduction to Numerical
Methods second edition 2012.
[6]. M.K. Jain, S.R.K. Iyengar, R.K. Jain; Numerical Methods for scientific and engineering
computation 6 edition 2012.
Prepared by Abe N
104
NUMERICAL METHODS
Apendix
Arsi University
Department of Computer Science
Time allowed: 15’
Name_________________________________
ID. No.____________
Show all the necessary steps clearly and neatly
1. If 𝑓(𝑥) = 𝑥 4 + 3𝑥 2 + 2 and 𝑥 = 1 with error 0.002, then determine ∆𝑦. (2.5 points)
2. Given 𝜔(𝑥, 𝑦) =
𝑦 4 𝑥+𝑥 2 𝑦
4𝑥
and 𝑥 = 2, 𝑦 = 3 with errors 0.02 and 0.03 respectively.
Based on the given determine ∆𝜔.
Prepared by Abe N
(2.5 points)
105
NUMERICAL METHODS
Arsi University
Department of Computer Science
Time allowed: 10’
Name_________________________________
ID. No._____________
Dept: ______________________
Show all the necessary steps clearly and neatly
3. If 𝑓(𝑥) = 2𝑥 4 + 3𝑥 + 5 and 𝑥 = 1 with error 0.002, then determine ∆𝑦. (2.5 pts)
4. Given 𝜔(𝑥, 𝑦) = 21𝑥 3 𝑦 2 and 𝑥 = 2, 𝑦 = 1 with errors 0.1 and 0.2 respectively.
Based on the given determine ∆𝜔.
Prepared by Abe N
(2.5 pts)
106
NUMERICAL METHODS
Arsi University
Department of Computer Science
1
Time allowed: 1 2hrs
Name_________________________________
ID. No._____________
Show all the necessary steps clearly and neatly (Use the indicated decimal places
throughout your computation).
1. Write the basic steps in Bisection Method.
(2 points)
2. Let 𝑓(𝑥) = 𝑥 3 − 3𝑥 + 1 = 0. Then
a. Use Newton-Raphson method to approximate a root of the equation 𝑓(𝑥) = 0 in
5decimal places. Continue the iteration until|𝑥𝑖+1 − 𝑥𝑖 | ≤ 0.00005. (Take 𝑥0 = 1.5 as
initial approximation).
(4 points)
b. Using Bisection Method approximate a root of the equation 𝑓(𝑥) = 0 in [1,2]. Compute
the first four iterations in 4 decimal places.
Prepared by Abe N
(4 points)
107
NUMERICAL METHODS
Arsi University
Department of Computer Science
1
Time allowed: 1 2hrs
Name_________________________________
ID. No._____________
Dept: Statistics
Show all the necessary steps clearly and neatly (Use the indicated decimal places
throughout your computation).
Let 𝑓(𝑥) = 𝑥 3 − 2𝑥 + 5 = 0. Then
1. Use Newton-Raphson method to approximate a root of the equation 𝑓(𝑥) = 0 in
4decimal places. Continue the iteration until|𝑥𝑖+1 − 𝑥𝑖 | ≤ 0.0005. (Take 𝑥0 = −2.3 as
initial approximation).
2. Using Bisection Method approximate a root of the equation 𝑓(𝑥) = 0 in [−3, −2].
Compute the first four iterations in 4 decimal places.
Prepared by Abe N
108
NUMERICAL METHODS
Arsi University
Department of Computer Science
Time allowed: 1hr
Name____________________________________
ID. No._____________
Dept: Statistics
Show all the necessary steps clearly and neatly.
1. Given data
𝑥
𝑦
2
3
4
5
6
33
8
59
a. Find the interpolating polynomial 𝑓(𝑥)using Newton’s forward interpolation formula.
b. Find 𝑓(3)
2. Use Newton’s divided difference formula to find the interpolating polynomial 𝑓(𝑥) of
the following data.
𝑥
𝑦
4
48
5
100
7
294
Prepared by Abe N
10
900
11
1210
109
NUMERICAL METHODS
Arsi University
Department of Computer Science
Time allowed: 𝟏hr
Numerical Analysis I
Name_____________________________________
ID. No._____________
Dept: ___________________
Show all the necessary steps clearly and neatly.
1. Given data
𝑥
𝑦
-2
-13
2
-1
0
-7
4
11
6
35
8
77
10
143
c. Find the interpolating polynomial 𝑓(𝑥)using Newton’s forward interpolation formula.
d. Find 𝑓(1)
2. Use Newton’s divided difference formula to find the interpolating polynomial 𝑓(𝑥) of
the following data.
𝑥
𝑦
0
1
1
3
3
55
Prepared by Abe N
4
105
7
351
110
NUMERICAL METHODS
Answers for Review exercises
Exercise 1
1
1
(1). a. 𝐸𝑎 = 30 , 𝐸𝑟 = 100 , 𝐸𝑝 = 1%
𝐸𝑎 =
1
1
, 𝐸𝑟 =
, 𝐸 = 10%
3
10 𝑝
𝐸𝑎 =
2
1
, 𝐸𝑟 = , 𝐸𝑝 = 20%
3
5
b.3.3 is the best approximation among the given.
(2).∆𝑦 = 0.002.
(3). ∆𝑢 = 0.05
Exercise 2
(1) .
Hi! Mr. Gada Enter the interval [a, b], maximum iteration and allowed error resp
1 1.54 0.05
Since 𝑓(𝑎)𝑓(𝑏) < 0 ,a root lies between a and b the iterations are:
_____________________________________________________
i
a
b
x[i]
f(x[i])
|x[i+1]-x[i]|
______________________________________________________
0 1.00000
1.50000
1.25000
0.18623
1
1.00000
1.25000
1.12500
0.01505
0.12500
2
1.00000
1.12500
1.06250
-0.07183
0.06250
3
1.06250
1.12500
1.09375
-0.02836
0.03125
Prepared by Abe N
111
NUMERICAL METHODS
4
1.09375
1.12500
1.10938
-0.00664
0.01563
__________________________________________________________
2).
Hi! Mr. Gada Enter the interval [a, b], maximum iteration and allowed error resp
2.5 3 16 0.005
Since f(a)f(b)<0, a root lies between a and b the iterations are:
___________________________________________________
i
a
b
x[i]
f(x[i])
|x[i+1]-x[i]|
_____________________________________________________
0
2.50000
3.00000
2.75000
-2.95313
1
2.75000
3.00000
2.87500
-1.11133
0.12500
2
2.87500
3.00000
2.93750
-0.09009
0.06250
3
2.93750
3.00000
2.96875
0.44626
0.03125
4
2.93750
2.96875
2.95313
0.17592
0.01563
5
2.93750
2.95313
2.94531
0.04238
0.00781
6
2.93750
2.94531
2.94141
-0.02399
0.00391
________________________________________________________
The root converges after iteration 6, the root is x= 2.94141
3).
Hi! Mr. Gada Please Enter a, b, maximum iteration and allowed error:
2 3 15 0.005
Since𝑓(𝑎)𝑓(𝑏) < 0 ,aroot lies between a and b, the iterations are:
Prepared by Abe N
112
NUMERICAL METHODS
_____________________________________________
i
a
b
x[i]
f(x[i])
_____________________________________________
1
2.000000
3.000000
2.187500
-1.094971
2
2.187500
3.000000
2.250619
-0.351826
3
2.250619
3.000000
2.270366
-0.108360
4
2.270366
3.000000
2.276397
-0.032937
5
2.276397
3.000000
2.278226
-0.009972
__________________________________________________
The root converges after iteration 5, the root is 2.27822590
4).
Hi! Mr. Gada Please enter xo, allowed error and maximum iteration:
0.5 0.00005 12
________________________________________________
i f(x[i-1]) f'(x[i-1])
x[i]
f(x[i])
________________________________________________
1 -0.377583
3.479425
0.608519
0.005060
2
0.005060
3.571653
0.607102
0.000001
3
0.000001
3.570490
0.607102
-0.000000
________________________________________________
The root converges after iteration 3, the root is 0.60710
(5).17
Exercise 3
(1). 𝑥1 = 7, 𝑥2 = −9 , 𝑥3 = 5
(2).𝑥1 = 1, 𝑥2 = −1, 𝑥3 = 0
Prepared by Abe N
113
NUMERICAL METHODS
(3). a.
Hi! Mr. Gada Please enter the elements of the augmented matrix row wise:
7 -2 1 0 17
1 -9 3 -1 13
2 0 10 1 15
1 -1 1 6 10
Hi! Mr. Gada Enter the allowed error and maximum iteration
0.00005 20
The solution vectors are:
___________________________________________________
Iteration
x[1]
x[2]
x[3]
x[4]
___________________________________________________
1
3.285714
-1.222222
1.100000
1.833333
2
1.922222
-0.916402
0.659524
0.732011
3
2.072525
-1.092357
1.042354
1.083642
4
1.967561
-0.987117
0.977131
0.965461
5
2.006948
-1.007390
1.009942
1.011365
6
1.996468
-0.997177
0.997474
0.995954
7
2.001168
-1.000785
1.001111
1.001480
8
1.999617
-0.999664
0.999618
0.999489
9
2.000150
-1.000113
1.000128
1.000183
10
1.999949
-0.999961
0.999952
0.999935
11
2.000018
-1.000015
1.000017
1.000023
12
1.999993
-0.999995
0.999994
0.999992
_______________________________________________________
The root Converges after 12 iterations, the roots are:
x[1]=1.999993
Prepared by Abe N
114
NUMERICAL METHODS
x[2]=-0.999995
x[3]=0.999994
x[4]=0.999992
(b).
Hi! Mr. Gada Please enter the elements of the augmented matrix row wise:
3 -1 1 1
3620
3374
Hi! Mr. Gada Enter the allowed error and maximum iteration
0.00005 20
The solution vectors are:
________________________________________
Iteration
x[1]
x[2]
x[3]
_________________________________________
1
1.333333
-1.000000
-1.571429
2
0.523809
-0.142857
0.428571
3
0.142857
-0.404762
0.408163
4
0.062358
-0.207483
0.683674
5
0.036281
-0.259070
0.633625
6
0.035768
-0.229349
0.666910
7
0.034580
-0.240187
0.654392
8
0.035140
-0.235421
0.659546
9
0.035011
-0.237419
0.657263
10
0.035106
-0.236593
0.658175
11
0.035077
-0.236945
0.657780
12
0.035092
-0.236799
0.657943
13
0.035086
-0.236860
0.657874
14
0.035088
-0.236835
0.657903
Prepared by Abe N
115
NUMERICAL METHODS
__________________________________________
Converges after 14 iterations, the roots are:
x[1]=0.035088
x[2]=-0.236835
x[3]=0.657903
(c).
Enter the elements of the augmented matrix row wise:
3114
-2 2 0 1
-1 2 -6 2
Hi! Mr. Gada Enter the allowed error and maximum iteration
0.00005 20
The solution vectors are:
_________________________________________
Iteration
x[1]
x[2]
x[3]
___________________________________________
1
0.333333
2.500000
0.333333
2
0.388889
0.833333
0.444444
3
0.907407
0.888889
-0.120370
4
1.077160
1.407407
-0.188272
5
0.926955
1.577160
-0.043724
6
0.822188
1.426955
0.037894
7
0.845050
1.322188
0.005287
8
0.890842
1.345050
-0.033446
9
0.896132
1.390842
-0.033457
__________________________________________
Converges after 9 iterations, the root is:
x[1]=0.896132
x[2]=1.390842
x[3]=-0.033457
(4).𝑥 = 2, 𝑦 = 1
Prepared by Abe N
116
NUMERICAL METHODS
Exercise 4
1. 𝑓(𝑥) = 𝑥 2 + 𝑥 + 1
(2).𝑓(𝑥) = 𝑥 3 − 3𝑥 2 + 2𝑥(3).147
4. (a).𝑓(𝑥) − 𝑥 2 + 30𝑥 + 648
(b). 677
Exercise 5
1.
i.
The value of the integral using Trapezoidal rule is 10.224
ii.
The value of the integral using Simpson’s 3is 10.2463
iii.
The value of the integral using Simpson’s 8 is 10.2403
1
3
2. i.7m/𝑠 2
ii.323.33m
3. 1.0316,0.2303
4. 1.40178
Exercise 6
1. a.Mr. Gada enter the values of xo, yo, xn, n:
0 0.333333 1 10
h=0.100000
The solution using Euler's Method is:
________________________________
| i | x[i] | y(x[i]) |
________________________________
| 1 | 0.10 | 0.1666665 |
| 2 | 0.20 | 0.1083332 |
| 3 | 0.30 | 0.1141666 |
| 4 | 0.40 | 0.1620833 |
| 5 | 0.50 | 0.2410417 |
| 6 | 0.60 | 0.3455208 |
| 7 | 0.70 | 0.4727604 |
| 8 | 0.80 | 0.6213802 |
| 9 | 0.90 | 0.7906901 |
| 10 | 1.00 | 0.9803451 |
Prepared by Abe N
117
NUMERICAL METHODS
_______________________________
b.Mr. Gada enter the values of xo, yo, xn, n:
1 0 2 10
h=0.100000
The solution using Euler's Method is:
_____________________
i x[i]
y(x[i])
______________________
1
1.10 0.0000000
2
1.20 0.0000000
3
1.30 0.0000000
4
1.40 0.0000000
5
1.50 0.0000000
6
1.60 0.0000000
7
1.70 0.0000000
8
1.80 0.0000000
9
1.90 0.0000000
10
2.00 0.0000000
_______________________
c. Mr. Gada enter the values of xo, yo, xn, n:
0 -2 2 10
h=0.200000
The solution using Euler's Method is:
_____________________
i x[i]
y(x[i])
_____________________
1
0.20 -1.8000000
2
0.40 -1.6079999
3
0.60 -1.4387327
4
0.80 -1.3017370
5
1.00 -1.1992512
6
1.20 -1.1274909
7
1.40 -1.0797453
8
1.60 -1.0491190
9
1.80 -1.0299540
10 2.00 -1.0181519
_____________________
Prepared by Abe N
118
NUMERICAL METHODS
4.Hi! Mr. Gada Please Enter the values of x0,y0,xn,n:
1025
The solution using 4RKM is:
_________________________________________________________
i x[i]
k[1]
k[2]
k[3]
k[4]
k
y
_________________________________________________________
1 1.20 0.2000 0.2220 0.2225 0.2499
0.2231 0.2231
2 1.40 0.2500 0.2842 0.2867 0.3320
0.2873 0.5104
3 1.60 0.3321 0.3915 0.3997 0.4857
0.4001 0.9105
4 1.80 0.4858 0.6061 0.6345 0.8374
0.6341 1.5446
5 2.00 0.8371 1.1508 1.2788 1.9943
1.2818 2.8263
________________________________________________________
Prepared by Abe N
119
NUMERICAL METHODS
Arsi University
College of Natural and Computational Science
Department of Statistics
Numerical Method Course syllabus for second year Computer Science students.
Program
B. Sc degree in Computer Science Science Students
Instructor's Contact
Information
Instructors Name Abe N
Module Information
Module Name: Computational
Module No.: 06 Module Code: Math-M2060
Module Coordinator: Abe N
Course Information
Course title: Numerical Methods for Computer Science Students
Course Code: Math2111 Course Credit points:5 EtCTS
Course Category: Supportive
Target group: Second Year Computer Science
Pre-requisites
Applied I/Calculus, and Programming
Academic Year 2021 Year: II Semester: II Enrollment: Regular Mode of Course delivery: Parallel
Students' Study Workload
distribution in hours
Gap
Lecture
Tutorial
48
Course Description
Lab
Work
Assessment
Home
study
Total study
32
8
47
135
The course mainly covers basic concepts in error estimation, solution of nonlinear equations, solutions of system of linear equations, finite differences,
interpolations, numerical differentiation and integration. and Numerical
solution of ODEs.
Course Objectives & Competences Acquired:
On completion of the course, successful students will be able to:
Prepared by Abe N
120
analyze errors and estimate error bounds in numerical computations
recognize when a mathematical problem should be solved numerically rather than analytically or
NUMERICAL METHODS
empirically
understand the roll of finite difference
grasp practical knowledge of polynomial interpolation in numerical differentiation and integration
understand range of iterative methods for solving linear and non-linear equations
translate mathematical algorithms in to computer programming
developed their scientific computation skills
Course Contents:
Teacher’s Activity
Wee
k
Contents
1
Chapter One: Basic concepts in error
Estimation
1.1. Introduction
Student’s Activity
Lecturing, Leading,
discussions, Asking and
answering questions, preparing
homework, giving assignment.
Listening and taking
short notes, asking and
answering questions,
doing home work.
Lecturing, Leading, discussions,
Asking
Listening to the lesson,
taking short notes,
asking
1.2. Errors
1.2.1. Definition and Source of errors
1.2.2. Absolute, relative and percentage
errors
1.2.3. Error propagation
2, 3
&4
Chapter Two: Non-linear equations
2.1. Bisection method
and answering questions,
Preparing
2.2. False position Method
2.3. Newton-Raphson method
and answering questions
homework, giving assignments
and feedback to the students.
Doing homework and
Chapter Three: Solution of System of
equations
Lecturing, Leading, discussions,
Asking
Equations linear equations
and answering questions,
Preparing
Listening to the lesson,
take short notes, asking
and
2.4. Fixed-point Iteration
Submitting assignments.
2.5. Secant method
5
and
6
3.1. Direct methods
3.1.1. Gauss Elimination method
homework, giving feedbacks to
the students.
Prepared by Abe N
Answering questions,
doing homework
121
NUMERICAL METHODS
3.1.2. Jordan’s Method
3.1.3. LU Decomposition
3.1.4. Tri-diagonal system
7
Lecturing, Leading discussions,
and
3.2. Iterative methods
3.2.1. Gauss-Jacob method
answering questions,
3.2.2. Gauss-Seidel method
Listening to the lesson,
take short notes, asking
andAnswering
questions,
3.3 Newton’s method for nonlinear
system.
8
Chapter Four: Difference Operators & Lecturing, Leading, discussions,
Asking and answering questions,
Interpolation
preparing homework, giving
4.1.1. Forward difference operator
feedback to home take exam.
Listening to the lesson,
take short notes, asking
and answering
questions,
4.1.2. Backward difference Operators
4.1.3 Central difference Operators
4.1.4 Shift operator
9&
4.2. Interpolation
10
4.2.1. Newton's Interpolation Formula
(Forward and Backward Formula)
11&
12
4.2.2 Divided difference Formula
Listening to the lesson,
take short notes, asking
and answering
questions, Doing
homework.
4.2.3 Lagrange's Interpolation Formula
.
Chapter Five: Numerical
Differentiation and Integration
5.1 Numerical Differentiation
Lecturing, Leading, discussions,
Asking and answering questions,
preparing homework, giving
feedback to home take exam.
Lecturing, Leading, discussions,
Asking and answering questions,
preparing homework, giving
feedback to home take exam.
Listening to the lesson,
take short notes, asking
and answering
questions,
Lecturing, Leading, discussions,
Asking and answering questions,
preparing homework, giving
Listening to the lesson,
take short notes, asking
and answering questions
5.2 Numerical Integration (Trapezoidal
and Simpson's Rules)
13&
14
Chapter Six: Numerical solution of
Ordinary Differential Equations
6.1. Taylor’s series method
Prepared by Abe N
122
NUMERICAL METHODS
6.2. Euler’s Method
feedback to home take exam
6.3. Modified Euler’s method
6.4. Runge-kutta method
Teaching-learning Methods (Methodology):
The course will be delivered through different ways of instructional methods including gap
lectures, discussions, individual work, group work, assignments, problem solving, presentation
of individual and group works.
Course Requirements/Policies:
All the University policies, and departmental policies regarding academic integrity, including
plagiarism, apply and will be enforced in this course. Specifically: Class attendance of at least 90% is required to sit for the final examination,
You are required to do individual assignments, group assignments, and presentation of
assignments,
You are required to collect assignments and submit the assignments due date. No late
assignments submission will be accepted. Copying and getting answers from someone
else will result zero mark.
You should take all tests and assignments as scheduled. If you miss, no makeup class
will be arranged for you unless you reported before and bring sufficient evidence,
Cheating will be strictly forbidden,
You should turn off your mobile phone during session and exam room.
The first thing to learn is discipline! The rest comes after it.
Assessment Types and their results:
Schedule of Assessments
Quizzes, Assignments, and Tests
Schedule
Quiz 1
Chapter 1
Date
Week
Percentage (%)
Remark
2
5
Compulsory
Test 1
Chapter 2
3
10
Compulsory
Assignment I
Chapter 3
3
10
Compulsory
Quiz 2
Chapter 4
6
5
Compulsory
Test 2
Test 3
Chapter 4
Chapter 5
7
9
10
10
Compulsory
Compulsory
Project I
Chapter
11
10
Compulsory
Prepared by Abe N
123
NUMERICAL METHODS
Final Examination
Chapters 3-6
12
40
Compulsory
Final Results
Assignment
&Project
20%
Quizzes
Tests
Final Exam
Total
10%
20%
50%
100%
Grading System:
The final grading system of students' result is based on "criteria referenced" system
Students group assignment grading includes written work and classroom presentation of
written workout problems
Textbook: Dr. B. S. Grewal, Numerical Methods in Engineering and science
References: [1] AlmosGilat, Numerical methods, second edition
[2] M. K. JAIN, S. R. K. Iyengar, R. K. Jain, Numerical Method for scientific and
Engineering computation, 6th edition.
Recommended reference: Burden, R.L. andFaires, J.D., Numerical Analysis,9th ed.,
Boston,1993.
Prepared by Abe N
124
0
You can add this document to your study collection(s)
Sign in Available only to authorized usersYou can add this document to your saved list
Sign in Available only to authorized users(For complaints, use another form )