Chapter 1 - Printed
Chapter 1 - Printed
Lecturer : M H M R S Dilhani
Module : IS5306 Numerical Methods
Type : Core
No. Credits :3
Prerequisites : None
Objective:
Provide an introduction to the students with numerical
approximation tools for solving engineering and science
problems.
Intended Learning Outcomes:
After following this module, students will be able to do the following.
• Understand of numerical approximation techniques.
• Use numerical techniques to solve different engineering and science
problems.
• Understand why numerical methods work and their limitation.
• Use of Matlab for solving numerical problems.
IS 5306 - M H M R S Dilhani 3
Mode of Assessment:
1. Continuous assessment 40%
• Assignments 20%
• In-Class Assessments 20%
IS 5306 - M H M R S Dilhani 4
Introduction
• In Linear Algebra, systems of linear equations can be implemented by
using row reduction as an algorithm.
• However, when these methods are not successful, we use the concept
of numerical methods.
• Numerical methods are used to approximate solutions of equations
when exact solutions can not be determined via algebraic methods.
• They construct successive approximations that converge to the exact
solution of an equation or system of equations.
IS 5306 - M H M R S Dilhani 5
Introduction
• Numerical method provide a way for the engineer to translate the language
of mathematics and physics into information that may be used to make
engineer decisions.
• This translation is implemented so that the calculation may be done by
machines (Computers).
• The types of problems that you encounter as an engineer may involve a
wide variety of mathematical phenomena, and hence it will benefit you to
have an equally wide range of numerical methods with which to approach
some of these problems.
• This course will provide you with an introduction to several of those
numerical methods which you may then find opportunity to practice later in
the curriculum.
IS 5306 - M H M R S Dilhani 6
Write down few examples in which numerical methods
offer a net benefit to the engineer
IS 5306 - M H M R S Dilhani 7
This course consists of six major units
1) Numerical Solution of nonlinear equations
2) Interpolating techniques
IS 5306 - M H M R S Dilhani 8
Numbers and their accuracy
There are two kinds of numbers:
1. Exact numbers, e.g. 1, 2, 3 .. ½, 5/2 etc.
2. Approximation numbers, e.g. 𝜋, 𝐾, … etc.
Significant Digit:
Digits that are used to express a number are called significant
digit/figures. The following statements describe the notion of significant
digits.
IS 5306 - M H M R S Dilhani 9
- All non zero digits
- All zeroes occurring between non-zero digits.
- Trailing zeros following a decimal point, e.g. 3.50, 65.0, 0.230 have
three significant digits.
- Zeros between the decimal point are preceding a non-zero digits are
not significant, e.g. 0.01234, 0.001234, 0.0001234 all have four
significant digits.
- When the decimal point is not written, trailing zeros are not considered
to be significant, e.g. 4500 contain only two significant digits.
IS 5306 - M H M R S Dilhani 10
Accuracy and precision:
The concept of accuracy and precision are closely related to significant
digits.
- Accuracy refers to the number of significant digits in a value, e.g. the
number 57.345 is accurate to five significant digits.
- Precision refer to the number of decimal position, i.e. the order of
magnitude of last digit in a value, e.g. 57.396 have a precision of
0.001.
IS 5306 - M H M R S Dilhani 11
Rules for rounding off:
To round off a number to n-significant digits, discard all digits to the
right of the nth digit if this discarded number is,
- Less than half a unit in the nth place, leave the nth digit unaltered.
- Greater than half a unit in nth place, increase the nth digit by unity.
- Exactly half a unit in the nth place, increase the nth digit by unit if it is
odd; otherwise leave it unchanged.
IS 5306 - M H M R S Dilhani 12
Different types of errors
a) Absolute Error: Numerical difference between true value of a quantity
and its approximate value.
Mathematically;
Absolute error 𝐸𝐴 = True Value 𝑋 − Approximate Value 𝑋1
= ∆𝑋
IS 5306 - M H M R S Dilhani 13
c) Percentage Error: The percentage value of relative error.
Mathematically;
Absolute Error 𝐸𝐴
Percentage error 𝐸𝑃 = × 100%
True Value (𝑋)
IS 5306 - M H M R S Dilhani 14
Mathematical Preliminaries
Theorem 1: If 𝑓(𝑥) is continuous in 𝑎 ≤ 𝑥 ≤ 𝑏, and if 𝑓 𝑎 and 𝑓(𝑏)
are of opposite signs, then 𝑓 𝑐 = 0 for at least one number 𝑐, such that
𝑎 < 𝑐 < 𝑏.
IS 5306 - M H M R S Dilhani 15
Theorem 3 (Intermediate Value Theorem): If 𝑓(𝑥) is continuous in
[𝑎, 𝑏] and let 𝐾 be any number between 𝑓 𝑎 and 𝑓 𝑏 , then there exist
a number 𝑐, such that 𝑓 𝑐 = 𝐾.
IS 5306 - M H M R S Dilhani 16
Theorem 5 (Taylor’s Series for a function of one variable): If 𝑓(𝑥) is
continuous and passes continuous derivatives of order in an interval and
includes 𝑥 = 𝑎, then:
𝑓 𝑥
𝑥 − 𝑎 2 𝑥 − 𝑎 𝑛−1
= 𝑓 𝑎 + 𝑥 − 𝑎 𝑓′ 𝑎 + 𝑓 ′′ 𝑎 + ⋯ + 𝑓 𝑛−1 𝑎
2! 𝑛−1 !
+ 𝑅𝑛 (𝑥)
𝑥−𝑎 𝑛 𝑛
Where; 𝑅𝑛 𝑥 : Remainder term = 𝑓 𝑐 ; 𝑎<𝑐<𝑏
𝑛!
IS 5306 - M H M R S Dilhani 17
1. Numerical solution of nonlinear equations
• The goal of this topic is to examine three different numerical methods
that are used to solve systems of nonlinear equations in several
variables.
Consider equation of the form 𝑓 𝑥 = 0, 𝑓 𝑥 is a nonlinear function.
Example:
𝑓 𝑥 = 𝑎𝑥 2 + 𝑏𝑥 + 𝑐 = 0
𝑓 𝑥 = 𝑥 4 + cos 𝑥𝑒 𝑥 − 10 = 0
In general we can write
𝑓 𝑥 = 𝑎0 𝑥 𝑛 + 𝑎1 𝑥 𝑛−1 + ⋯ + 𝑎𝑛 = 0
This is called as polynomial function.
IS 5306 - M H M R S Dilhani 18
𝑎𝑥 2 + 𝑏𝑥 + 𝑐 = 0 Quadratic equation
−𝑏 ± 𝑏 2 − 4𝑎𝑐
𝑥= There is
2𝑎
a
𝑎𝑥 3 + 𝑏𝑥 2 + 𝑐𝑥 + 𝑑 = 0 Cubic equation formula
𝑎𝑥 4 + 𝑏𝑥 3 + 𝑐𝑥 2 + 𝑑𝑥 + 𝑒 = 0 Biquadratic equation
𝑎𝑥 5 + 𝑏𝑥 4 + 𝑐𝑥 3 + 𝑑𝑥 2 + 𝑒𝑥 + 𝑓 = 0 There is no formula
IS 5306 - M H M R S Dilhani 19
Methods of Solving Non-Linear Equations
There are different methods to deal with non linear equations:
i. Direct analytical method
ii. Graphical method
iii. Trial and error method
iv. Iterative method
IS 5306 - M H M R S Dilhani 20
Iterative method
Iterative method begin with one or more guesses at the solution being
sought. It generates a sequence of estimate of the solution which is
expected to converge at the solution. Based on the number of guess, we
have two different methods.
A. Bracketing Method:
It starts with two guesses that brackets the root and then,
systematically reduced the width of bracket until the solution is
reached.
IS 5306 - M H M R S Dilhani 21
B. Open End Method
It uses single starting values or two values that do not necessarily
bracket the root.
IS 5306 - M H M R S Dilhani 22
Bisection Method
• This is one of the bracketing methods and is also known as Bolzano
Method, Binary Chopping or Half Interval method.
• It is a very simple and robust method, but the main disadvantage is that
convergence is slow.
IS 5306 - M H M R S Dilhani 23
Theorem: Bisection Method
Let 𝒇(𝒙) be the function defined in the interval 𝒂𝟎 , 𝒃𝟎 , where
𝒇(𝒂𝟎 ) and 𝒇(𝒃𝟎 ) are of opposite sign i.e. 𝒇(𝒂𝟎 ) 𝒇(𝒃𝟎 ) < 𝟎 then the
root of the function lies in between 𝒂𝟎 𝐚𝐧𝐝 𝒃𝟎 .
𝑓(𝑥) 𝑓(𝑏0 )
𝑎0
𝑥
𝑚 𝑏0
𝑓(𝑎0 )
IS 5306 - M H M R S Dilhani 24
Algorithm
1. Read 𝑎0 and 𝑏0 , define stopping criteria: error(𝜀)
2. Calculate, 𝑚 = (𝑎0 + 𝑏0 )/2
3. If 𝑏0 − 𝑎0 < 𝜀, go to step 6 (Optional)
4. Check for 𝑓(𝑚)
a) If 𝑓 𝑚 = 0, go to step 6
b) 𝑓 𝑚 < 0, 𝑎0 = 𝑚
c) 𝑓 𝑚 > 0, 𝑏0 = 𝑚
5. Repeat steps 2, 3, and 4 until 𝜀 is achieved
6. Print 𝑚
7. Stop
IS 5306 - M H M R S Dilhani 25
Example:
Find the root of 𝑓 𝑥 = 𝑥 2 − 5 by using the bisection method. Let the
starting interval is [2,3] and error is 𝜀𝑛 = 0.01.
𝑓 𝑥 = 𝑥2 − 5
∴ 𝑓 2 = −1, 𝑓 3 =4
∴ f 2 f 3 < 0, has opposite signs.
So, we can use bisection method to find the root, as 𝑓 𝑥 has at least
one root in between 2 and 3.
IS 5306 - M H M R S Dilhani 26
𝑎0 +𝑏0 2+3
Then, 𝑚1 = = = 2.5
2 2
𝑓 𝑚1 = 2.52 − 5 =6.25-5=1.25
IS 5306 - M H M R S Dilhani 27
In a tabular format
𝒂 𝒃 𝒇(𝒂) 𝒇(𝒃) 𝒎 𝒇(𝒎) Update New 𝒃 − 𝒂
a+b
=
2
2 3 -1 4 2.5 1.25 𝒃1 = m1 0.5
= 2.5
IS 5306 - M H M R S Dilhani 28
Thus, with the seventh iteration, we note that the final interval, [2.2344,
2.25] has a width less than 0.01 and 𝑓 2.2344 < 0.01, and therefore,
we choose 𝑎 = 2.2422 to be our approximation of the root.
Example 2:
Suppose you have to solve the function, 𝑥 2 − 𝑥 = 0, in the interval
−0.1,0.01 using the bisection method. The stopping criteria of this
function is 0.0001.
IS 5306 - M H M R S Dilhani 29
Advantages of Bisection method:
a) The bisection method is always convergent since the method
brackets the root, the method is guaranteed to converge
b) As iterations are conducted, the interval gets halved. So one can
guarantee the error in the solution of the equation.
IS 5306 - M H M R S Dilhani 30
c) If a function 𝑓(𝑥) is such that it just touches the x-axis, such as
𝑓 𝑥 = 𝑥 2 = 0 it will be unable to find the lower guess, 𝑎0 , and
upper guess, 𝑏0 , such that 𝑓 𝑎0 𝑓 𝑏0 < 0.
𝑓(𝑥)
1
The equation 𝑓 𝑥 = = 0 has no root, but changes sign.
𝑥
IS 5306 - M H M R S Dilhani 32
1
An example includes, 𝑓 𝑥 = , where 𝑎0 = −2, 𝑏0 = 3 are valid
𝑥
IS 5306 - M H M R S Dilhani 33
Convergence of Bisection
In bisection method, we choose a mid point m in the interval between
𝑎0 and 𝑏0 . Depending upon the sign of 𝑓 𝑚 , 𝑏0 or 𝑎0 is set equal to m
such that the root lies in the interval. In other case the interval
containing the root is reduced by a function of 2. The same process is
repeated for the new interval. If the procedure is repeated ‘n’ times, then
the interval containing the root is reduced to the size,
𝑏0 − 𝑎0 ∆𝑥
𝑛
= 𝑛
2 2
∆𝑥
After iteration the root must lies within ± of our estimate.
2
IS 5306 - M H M R S Dilhani 34
this mean the error bound at nth iteration is,
∆𝑥
𝜀𝑛 = 𝑛 .
2
Similarly,
∆𝑥 𝜀𝑛
𝜀𝑛+1 = 𝑛+1 =
2 2
Thus the error decrease linearly with each step by a factor of 0.5. This
method is therefore linearly convergent.
IS 5306 - M H M R S Dilhani 35
Stopping Criteria
The number of iterations can be calculated as follows; where 𝜀𝑛 is the
error at the nth iteration.
∆𝑥
𝜀𝑛 = 𝑛
2
𝑛
∆𝑥
2 =
𝜀𝑛
∆𝑥
log
𝜀𝑛
𝑛≥
log 2
IS 5306 - M H M R S Dilhani 36
1.2 Newton-Raphson method
Consider a graph 𝑓 𝑥 as shown in the below figure. Let us assume that
𝑥1 is an approximation root of 𝑓 𝑥 = 0. Draw a tangent curve 𝑓 𝑥 at
𝑥 = 𝑥1 as shown in the figure.
𝑓(𝑥)
T𝐚𝐧𝐠𝐞𝐧𝐭
(𝑥1 , 𝑓 𝑥1 )
(𝑥2 , 𝑓 𝑥2 )
𝑥𝑟𝑜𝑜𝑡 𝑥
𝑥3 𝑥2 𝑥1
IS 5306 - M H M R S Dilhani 37
The point of intersection of this tangent with the x-axis gives the second
approximation to the root. Let, the point of intersection be 𝑥2 . The slope
of the tangent is given by:
𝑓 𝑥1
tan 𝛼 = = 𝑓 ′ (𝑥1 )
𝑥1 − 𝑥2
Where; 𝑓′ 𝑥1 is the slope of 𝑓 𝑥 at 𝑥 = 𝑥1 .
Solving for 𝑥2 , we get:
𝑓 𝑥1
𝑥2 = 𝑥1 − ′
𝑓 (𝑥1 )
This is called Newton Raphson formula for first iteration.
IS 5306 - M H M R S Dilhani 38
Then the next approximation will be:
𝑓 𝑥2
𝑥3 = 𝑥2 − ′
𝑓 (𝑥2 )
In general
𝑓 𝑥𝑛
𝑥𝑛+1 = 𝑥𝑛 − ′
𝑓 (𝑥𝑛 )
IS 5306 - M H M R S Dilhani 39
Algorithm
1. Assign an initial value to x, say 𝑥0 and read the stopping criteria (𝜀).
2. Evaluate 𝑓 𝑥0 and 𝑓 ′ 𝑥0 . If 𝑓 𝑥0 = 0; then the root will be 𝑥0 .
3. Find the improved estimate of 𝑥0 a:
𝑓 𝑥0
𝑥1 = 𝑥0 − ′
𝑓 (𝑥0 )
𝑥1 −𝑥0
4. Check for accuracy of estimate: if < 𝜀; then stop and go to
𝑥1
step 6 otherwise continue.
5. Replace 𝑥0 by 𝑥1 and repeat steps 3 and 4.
6. Print 𝑥1 .
7. Stop.
IS 5306 - M H M R S Dilhani 40
Another way of obtaining Newton-Rapson method
Taylor’s Series
𝑥−𝑎 ′ 𝑥−𝑎 2 𝑥−𝑎 𝑛
𝑓 𝑥 =𝑓 𝑎 + 𝑓 𝑎 + 𝑓"(𝑎) + ⋯ + 𝑓 𝑛 (𝑎)
1! 2! 𝑛!
𝑓 𝛼 =0, so we have
2 𝑛
𝛼 − 𝑥0 ′ 𝛼 − 𝑥0 𝛼 − 𝑥0
0 = 𝑓 𝑥0 + 𝑓 𝑥0 + 𝑓"(𝑥0 ) + ⋯ + 𝑓 𝑛 (𝑥0 )
1! 2! 𝑛!
IS 5306 - M H M R S Dilhani 41
(𝛼 − 𝑥0 ) is the error initial stage.
Define 𝜀0 = 𝛼 − 𝑥0
So,
2 𝑛
′
𝜀 0 𝜀0 𝑛
0 = 𝑓 𝑥0 + 𝜀0 𝑓 𝑥0 + 𝑓"(𝑥0 ) + ⋯ + 𝑓 (𝑥0 )
2! 𝑛!
Since 𝜀0 is small, we can neglect 𝜀02 , 𝜀03 , 𝜀04 , …
∴ 0 ≈ 𝑓 𝑥0 + 𝜀0 𝑓 ′ 𝑥0
𝑓 𝑥0
𝜀0 ≈ −
𝑓′(𝑥0 )
𝑓 𝑥0
∴ 𝛼 ≈ 𝑥0 − ′ = 𝑥1
𝑓 𝑥0
IS 5306 - M H M R S Dilhani 42
As 𝑥1 is a better approximation to 𝛼 than 𝑥0 , we can obtain a closer
value to 𝛼 using 𝑥1 .
𝑓 𝑥1
𝑥2 = 𝑥1 − and we continue.
𝑓′ 𝑥1
So we get,
𝑓 𝑥𝑛
𝑥𝑛+1 = 𝑥𝑛 − ′ = 𝑔(𝑥𝑛 )
𝑓 𝑥𝑛
IS 5306 - M H M R S Dilhani 43
Example 1:
Solve the nonlinear equation, 𝑥 6 − 2.8𝑥 + 0.7 using the Newton-
Raphson method with a good initial value (starting value) 𝑥0 .
IS 5306 - M H M R S Dilhani 44
𝑓 𝑥𝑛 𝑥𝑛6 − 2.8𝑥𝑛 + 0.7
𝑥𝑛+1 = 𝑥𝑛 − ′ = 𝑥𝑛 −
𝑓 𝑥𝑛 6𝑥𝑛5 − 2.8
IS 5306 - M H M R S Dilhani 45
Example 2:
Solve 𝑥 2 + 2𝑥 + 1 = 0 using N-R method with the initial value 𝑥0 =
0.9.
𝑓 𝑥 = 𝑥 2 + 2𝑥 + 1, 𝑓 ′ 𝑥 = 2𝑥 + 2
𝑓 𝑥𝑛 (𝑥𝑛2 + 2𝑥𝑛 + 1)
𝑥𝑛+1 = 𝑥𝑛 − ′ = 𝑥𝑛 −
𝑓 𝑥𝑛 (2𝑥𝑛 + 2)
IS 5306 - M H M R S Dilhani 46
Note:
𝒇 𝒙 = 𝒙−𝜶 𝒎𝒈 𝒙 =𝟎
where 𝑔 𝑥 is a function such that 𝑔 𝛼 ≠ 0. m is the order of the
multiple root or the multiplicity. So, if we know the multiplicity of the
root, then we can modify N-R method as :
𝑚𝑓 𝑥𝑛
𝑥𝑛+1 = 𝑥𝑛 −
𝑓′(𝑥𝑛 )
IS 5306 - M H M R S Dilhani 47
Suppose you have function, 𝑓 𝑥 = 0 and 𝛼 is a root of this function.
𝑓′ 𝛼 = 0
If ൠ → 𝛼 is a double root.
𝑓"(𝛼) ≠ 0
IS 5306 - M H M R S Dilhani 48
Example 3:
𝑓 𝑥 = 𝑥2 + 𝑥7 = 0
We can re-write the function as,
𝑓 𝑥 = 𝑥 2 1 + 𝑥 5 = 𝑥 2 𝑔(𝑥)
Check whether the given equation has double root or not.
IS 5306 - M H M R S Dilhani 49
Advantages of N-R method
1) Convergence is faster (quadratic convergence)
2) Required only one guess
IS 5306 - M H M R S Dilhani 50
2) Oscillations near local maximum and minimum
0 𝑥
−1.75 −1 0.5 3.142
−0.3040
51
IS 5306 - M H M R S Dilhani
4) Root jumping
In some cases where the function 𝑓(𝑥) is oscillating and has a number
of roots, one may choose an initial guess close to a root. However, the
guess may jump and converge to some other root.
𝑓(𝑥)
𝒇 𝒙 = 𝐒𝐢𝐧 𝒙 = 𝟎
4.46
𝑥
0 0.55 7.54
IS 5306 - M H M R S Dilhani 52
1.3 Fixed Point Iteration Method
It is also known as direct substitution method or method of successive
approximation. It is applicable if the equation 𝑓 𝑥 = 0 can be
expressed in terms of 𝑥 = 𝑔 𝑥 . If 𝑥0 is the initial approximation to the
root, then the next approximation will be: 𝑥1 = 𝑔 𝑥0 and the next
again will be: 𝑥2 = 𝑔 𝑥1 and so on.
In general iterative method can be written as,
𝑥𝑛+1 = 𝑔 𝑥𝑛 , 𝑛 = 0,1,2, …
IS 5306 - M H M R S Dilhani 53
Definition: Fixed Point Iteration Method
If 𝜶 = 𝒈 𝜶 , then we say 𝜶 is a fixed point for the function 𝒈 𝒙 .
IS 5306 - M H M R S Dilhani 54
Algorithm:
IS 5306 - M H M R S Dilhani 55
Example 1:
Use the fixed point iterative method to determine a solution accurate
within 10−2 for 𝑥 5 − 3𝑥 3 − 3 = 0, on 1,2 .
𝑓 𝑥 = 𝑥 5 − 3𝑥 3 − 3 = 0
We can rewrite the function 𝑓 𝑥 as ;
𝑥 5 − 3𝑥 3 − 3 = 0
𝑥 5 = 3𝑥 3 + 3
𝑥 = 3𝑥 3 + 3 1/5 ∈ [1,2]
𝑔 𝑥
IS 5306 - M H M R S Dilhani 56
Example 2:
Find a root of 𝑥 4 − 2𝑥 − 5 = 0 by using fixed point iteration method.
Lets consider
5
𝑔 𝑥 = 3 and 𝑥0 = 2.0
(𝑥 − 2)
IS 5306 - M H M R S Dilhani 57
Graphical interpretation of Fixed point iteration procedure
IS 5306 - M H M R S Dilhani 58
IS 5306 - M H M R S Dilhani 59