You are on page 1of 62

Lecture 2: ROOTS OF EQUATION

Dr. Nor Alafiza Yunus


Faculty of Chemical and Energy Engineering
Universiti Teknologi Malaysia, 81310 UTM
Johor Bahru, Malaysia
4
Students will be able to:

 Recognize what is the root of equation

 Use bracketing and open methods for root


location

 Clarify the concept of convergence and


divergence

5
 Bisection method
 False-position method
 Newton-Raphson Method
 Secant Method
 Simple Fixed-Point Iteration

6
 Root of an equation can be defined as “ the
value of x that makes f(x) = 0 or can be called
as the zeros of the equation.

 Example of Roots problem

2𝑥 2 = 9 + 𝑥
ln 𝑦 = 𝑦𝑥 + 3𝑦
𝑣 = 𝑚𝑥 + 3𝑡

11
 The quadratic formula normally used to
calculate the roots of equation analytically,
f(x) = ax2 + bx +c = 0
−𝑏± 𝑏2 −4𝑎𝑐
𝑥=
2𝑎

 However, it cannot solve the root for many other


equations, such as,
𝑓 𝑥 = 𝑒 −𝑥 − 𝑥
𝑐
𝑔𝑚 − 𝑚 𝑡
𝑓 𝑐 = 1 −𝑒 −𝑣
𝑐 12
ANALYTICAL METHOD GRAPHICAL METHOD

• Use calculator
• Use formula

BRACKETING METHOD OPEN METHOD

1. Bisection 1. Simple Fixed-Point Iteration


2. False Position 2. Newton-Raphson
3. Secant
13
 Called bracketing method because two initial
guesses for the root are required

 The name “implies” that the guesses bracketing


the root

 There are two types of bracketing method


 Bisection Method
 False Position Algorithm

 The difference of both method lies through their


strategies to systematically reduce the width of
the bracket
14
 2 initial guess, Xl and Xu

f(xl ) and f(xu ) having same sign f(xl ) and f(xu ) having different sign

15
 Requirements:
 f(x) is real and continuous in the interval of xl
and xu
 f(xl ) and f(xu ) having opposite sign that is
f(xl) f(xu) < 0 (- ve)

 Characteristic
 incremental search method in which the interval
is divided in half
 if a function changes sign over an interval, the
function value at midpoint is evaluated

16
17
1. Rearrange the equation to be equal to zero, f(x)=0
2. Choose the lower xl and upper xu guesses for the root, such
that f(xl ) f(xu ) < 0
𝒙𝒍 + 𝒙𝒖
3. Estimate the roots, xr 𝒙𝒓 =
𝟐
… 𝐄𝐪. (𝟏. 𝟏)

4. Make the following evaluations


i. If f(xl ) f(xr ) < 0, the roots lies in the first subinterval. Set xu = xr
Return to step 3
ii. If f(xl ) f(xr ) > 0, the roots lies in the second subinterval. Set xl =
xr Return to step 3
iii. If f(xl ) f(xr ) = 0, the roots equals xr : Terminate the computations

5. Calculate εa , if less than εs then, terminate the computation


6. Root is the xr value of the last iteration

18
 Determine the real root of
𝑓 𝑥 = 𝑥 3 − 13𝑥 − 12 = 0
using
a) Analytically
b) The bisection method, with initial guesses of xl = 2 and
xu = 5, and εs=0.05%,

Solution
a) Analytical method
𝑓 𝑥 = 𝑥 3 − 13𝑥 − 12 = 0
 Using calculator, x= 4, -3, -1

19
b) Bisection method
Iteration 1
𝑥 3 − 13𝑥 − 12 = 0
𝑥𝑙 = 2, 𝑓 2 = 23 − 13 2 − 12 = −30
𝑥𝑢 = 5, 𝑓 5 = 53 − 13 5 − 12 = 48
2+5
𝑥𝑟 = = 3.500 𝑓 3.5 = 3.5003 − 13 3.500 − 12 = −14.6250
2
𝑓(𝑥𝑙 )𝑓(𝑥𝑟 ) > 0, ∴ 𝑥𝑙 = 𝑥𝑟
𝜀𝑎 = −

20
b) Bisection method
Iteration 2
𝑥𝑙 = 3.5, 𝑓 3.5 = −14.6250
𝑥𝑢 = 5, 𝑓 5 = 48
3.5 + 5
𝑥𝑟 = = 4.2500 𝑓 4.2500 = 4.25003 − 13 4.2500 − 12 = 9.5156
2
𝑓(𝑥𝑙 )𝑓(𝑥𝑟 ) < 0, ∴ 𝑥𝑢 = 𝑥𝑟

𝑥𝑟,𝑛𝑒𝑤 − 𝑥𝑟,𝑜𝑙𝑑 4.2500 − 3.500


𝜀𝑎 = 100 = 100 = 0.1765
𝑥𝑟,𝑛𝑒𝑤 4.2500

21
f(xl)f(xr)
iter xl xr xu f(xl) f(xr) 𝜀𝑎
sign

1 2 3.500 5 -30.000 +ve -

2 3.500 4.2500 5 -ve 0.1765

3 3.500 3.8750 4.2500 -4.1895 +ve 0.0968

4 3.8750 4.0625 4.2500 -4.1895 2.2346 -ve 0.0462

∴ 𝑥𝑟 = 4.0625

22
 Similar to bisection method
 Use different strategy to
estimate root
 Locate root by joining f(xl) and
f(xu) with a straight line.
 The intersection of this line
with the x-axis is the estimated
root

𝑓 𝑥𝑢 𝑥𝑙 − 𝑥𝑢
𝑥𝑟 = 𝑥𝑢 − … 𝐸𝑞. (1.2)
𝑓 𝑥𝑙 − 𝑓 𝑥𝑢
24
 Determine the positive real root of
𝑓 𝑥 = 𝑥 3 − 13𝑥 − 12 = 0

a) Analytically,
b) the bisection method, with initial guesses of xl
= 2 and xu = 5, and εs=0.05%,
c) the false-position method, with the same initial
guesses and condition as in (b).

25
 Determine the positive real root of
ln(x2) = 0.7 using

a) Analytically,
b) the bisection method, with initial guesses of xl
= 0.5 and xu = 2, and εs=0.5%,
c) the false-position method, with the same initial
guesses and condition as in (b).

26
 Bisection method
 False-position method
 Newton-Raphson method
 Secant Method
 Simple Fixed-Point Iteration
 MATLAB

27
BRACKETING
METHOD

1. Bisection
2. False Position OPEN METHOD

1. Newton-Raphson
2. Secant
3. Simple Fixed-Point Iteration
GRAPHICAL
METHOD

28
 Open methods differ from bracketing
methods, in that open methods require only
a single starting value or two starting values
that do not necessarily bracket a root.

 Open methods may diverge as the


computation progresses, but when they do
converge, they usually do so much faster
than bracketing methods.
Open method-diverging Open method-converging

Bracketing method
 Based on forming the tangent line to the f(x)
curve at some guess x, then following the
tangent line to where it crosses the x-axis.

f ( xi )  0
f ( xi ) 
'
xi  xi 1

f ( xi )
xi 1  xi  '
 Eq.(1.3)
f ( xi )
1. Rearrange the equation to be equal to zero,
f(x)=0
2. Differentiate f(x) equation, f ’(x)
3. Guess the initial value for the root, xo
4. Estimate the new roots, xi+1 using Eq. (1.3)
5. Estimate the relative error, εa or εT .
6. Repeat steps 4-5 until |εa| < εs or meet the
stopping criterion

32
Use the Newton-Raphson Method to
estimate the root of the equation below
employing the initial guess of yo=0. Perform
iteration until the approximate relative error
falls below 0.05%

𝑒 −𝑦 = 2𝑦

Answer: Xr = 0.3517 33
1. f(y) = 𝑒 −𝑦 − 2𝑦 = 0
2. f‘(y) = −𝑒 −𝑦 − 2
3. Let yo=0 𝑓(𝑦𝑖 )
4. Estimate 𝑦𝑖+1 = 𝑦𝑖 − ′
𝑓 (𝑦𝑖 )
Iteration, 1 5. Estimate relative error
𝑒 −𝑦𝑜 − 2𝑦𝑜 𝑦1 − 𝑦0
𝑦1 = 𝑦𝑜 − 𝜀𝑎 = × 100
−𝑒 −𝑦𝑜 − 2 𝑦1
𝑒 −0 − 2 0 0.3333 − 0
𝑦1 = 0 − −0
= 0.3333 𝜀𝑎 = × 100
−𝑒 − 2 0.3333
= 100%
34
Repeat step 4. Iteration 2
𝑒 −𝑦1 − 2𝑦1
𝑦2 = 𝑦1 −
−𝑒 −𝑦1 − 2
𝑒 −0.3333 − 2 0.3333
𝑦2 = 0.3333 −
−𝑒 −0.3333 − 2
𝑦2 = 0.3517
5. Estimate relative error
𝑦2 − 𝑦1
𝜀𝑎 = × 100
𝑦2
0.3517 − 0.3333
𝜀𝑎 = × 100 = 5.2317%
0.3517
35
6. Continue the calculation until |εa |< εs
iteration yi εa (%)

0 0 -

1 0.3333 100

2 0.3517 5.2317

3 0.3517 0.0000

7. Therefore Xr = 0.3517

36
Determine the root of the following easily
differentiable function
𝑒 0.5𝑥 = 5 − 5𝑥
Using Newton-Raphson with initial guess of
xo=0. Perform iterations until approximative
relative error falls below 1%.
Answer: iteration x εa (%)
0 0 -
1 0.7273 100
2 0.7142 1.8341
3 0.7142 0.0008
37
Advantage Disadvantage
Difficulty in
Simple differentiation

Quick and easy to Slow converging


converge Easy to diverge

38
Four cases where Newton-Raphson method shows
slow and poor convergence
Determine the root of the following easily differentiable
function
𝑒 0.5𝑥 = 5 − 5𝑥
Using Newton-Raphson with initial guess of xo=0. Perform
iterations until approximative relative error falls below 2%.
Answer: 10

0
-1 -0.5 0 0.5 1 1.5 2 2.5
-2

-4

-6

-8

40
Find the first root above x=0 for the following function with
an accuracy of 4 digits
𝑒 𝑥 = 4𝑥 2 + 3
Graphical Method

300

250

200

150

100

50

0
0 1 2 3 4 5 6 7
-50
41
iteration xi εa (%) iteration xi εa (%)
0 0.0000 0 3.0000
1 2.0000 100 1 -1.8319 263.7605
2 0.6516 206.9339 2 -0.7342 149.5198
3 -0.1922 438.9975 3 0.0018 40151.12
4 0.7908 124.3073 4 2.0260 99.9095
5 -0.0091 8826.069 5 0.6537 209.919

iteration xi εa (%)
0 4.000
1 4.5488 12.0647
2 4.3982 3.4235
3 4.3781 0.4601
4 4.3778 0.0076
5 4.3778 2E-06 42
 Bisection method
 False-position method
 Newton-Raphson method
 Secant Method
 Simple Fixed-Point Iteration

43
 A potential problem in implementing the
Newton-Raphson method is the evaluation of
the derivative - there are certain functions
whose derivatives may be difficult or
inconvenient to evaluate.
 For these cases, the derivative can be
approximated by a backward finite divided
difference:

f (x i1 )  f (x i )
f (x i ) 
'

x i1  x i
 Substitution of this approximation for the
derivative to the Newton-Raphson method
equation gives:
f ( xi ) xi 1  xi 
xi 1  xi   Eq.(1.4)
f ( xi 1 )  f ( xi )
 Note - this method requires two initial estimates
of x but does not require an analytical
expression of the derivative.
1. Rearrange the equation to be equal to zero,
f(x)=0
2. Guess two initial values, xi and xi-1
4. Estimate the new roots, xi+1 using Eq.(1.4)
5. Estimate the relative error, εa or εT .
6. Repeat steps 4-5 until |εa| < εs or meet the
stopping criterion

47
Use the Secant Method to estimate the root
of the equation below employing the initial
guess of yo=0. Perform iteration until the
approximate relative error falls below 0.05%

𝑒 0.5𝑥 (4 − 𝑥) = 5

Answer: Xr = 1.0664 48
0.5𝑥
1. f(x) = 𝑒 4 − 𝑥 − 5=0
2. Let xo=0, x1=1,
f ( xi ) xi 1  xi 
3. Estimate xi 1  xi   Eq.(1.4)
f ( xi 1 )  f ( xi )
Iteration 1
𝑓 𝑥𝑜 = 𝑒 0.5 0 4 − 0 − 5 = −1 5. Estimate relative error

𝑓 𝑥1 = 𝑒 0.5 1 4 − 1 − 5 = −0.0538 𝑥2 − 𝑥1
𝜀𝑎 = × 100
𝑥2
𝑓(𝑥1 )(𝑥𝑜 − 𝑥1 )
𝑥2 = 𝑥1 − 1.0569 − 1
𝑓 𝑥𝑜 − 𝑓(𝑥1 ) 𝜀𝑎 = × 100
1.0569
0.0538(0 − 1)
𝑥2 = 1 + = 1.0569 = 100%
−1 + 0.0538 49
Repeat step 4. Iteration 2
𝑓 𝑥2 = 𝑒 0.5 1.0569 4 − 1.0569 − 5 = −7.6165 × 10−3
𝑓(𝑥2 )(𝑥1 − 𝑥2 )
𝑥3 = 𝑥2 −
𝑓 𝑥1 − 𝑓(𝑥2 )

−7.6165 × 10−3 (0 − 1.0569)


𝑥3 = 1.0569 − −3
= 1.0663
−0.0538 + 7.6165 × 10

5. Estimate relative error


𝑥3 − 𝑥2
𝜀𝑎 = × 100
𝑥3
1.0663 − 1.0569
𝜀𝑎 = × 100 = 0.8794%
1.0663
50
6. Continue the calculation until |εa |< εs

iteration xi f(xi) εa (%)

0 0 -1 -

1 1.0000 -0.05384 100

2 1.0569 -0.00762 5.3836

3 1.0663 -0.00014 0.8794

4 1.0664 -3.7E-07 0.0160

7. Therefore Xr = 1.0664
51
Repeat exercise 2 with Secant method.
Determine the root of the following easily
differentiable function
𝑒 0.5𝑥 = 5 − 5𝑥
Using Secant with initial guess of xo=0 and
x1=0.5. Perform iterations until approximative
relative error falls below 0.005%.
iteration xi f(xi) εa (%)
Answer:
0 0.0000 -4.0000
1 0.5000 -1.2160 100
2 0.7184 0.0241 30.3994
3 0.7141 -0.0002 0.5941
4 0.7142 -2.067E-08 0.0038 52
 Determine the positive real root of
ln(x2) = 0.7 using

a) the Newton Raphson method with εs=0.5%,


b) the Secant method with εs=0.5%

53
 Bisection method
 False-position method
 Newton-Raphson method
 Secant Method
 Simple Fixed-Point Iteration

55
 Rearrange the function f(x)=0 so that x is on
the left-hand side of the equation:
x=g(x)
 Use the new function g to predict a new
value of x - that is,
xi+1=g(xi)

 Calculate the approximate error, given by:


x i1  x i
a  100%
x i1
 Solve f(x)=e-x - x
 Re-write , x=g(x) by isolating x
x=e-x
 Start with an initial guess, xo= 0
xi+1=e-xi
x1=exp(-0)=1
i xi |a| %
0 0.0000
1 1.0000 100.000

 Continue until some tolerance


is reached

Answer: Xr = 0.5671
iteration xi εa (%)
0 0.0000
1 1.0000 100
2 0.3679 171.8282
3 0.6922 46.8536
4 0.5005 38.3091
5 0.6062 17.4468
6 0.5454 11.1566
7 0.5796 5.9034
8 0.5601 3.4809
9 0.5711 1.9308
10 0.5649 1.1089
11 0.5684 0.6244
12 0.5664 0.3556
58
Use the Simple Fixed-point Method to
estimate the root of the equation below by
employing the initial guess of xo=0.5.
Perform iteration until the approximate
relative error falls below 0.05%

𝑓 𝑥 = sin( x) − 𝑥

Answer: 0.7686 59
 Convergence of the simple
fixed-point iteration method
requires that the derivative
of g(x) near the root has a
magnitude less than 1.
a) Convergent, 0≤g’<1
b) Convergent, -1<g’≤0
c) Divergent, g’>1
d) Divergent, g’<-1
 Medical studies established that bungee jumper can
cause significant vertebrae injury if the free-fall velocity
exceeds 36 m/s after 4s of free fall. Given g=9.81 m/s2
cd=0.25 kg/m. Determine the mass at this criterion is
exceeded using different numerical method approach

𝑔𝑚 𝑔𝑐𝑑
𝑣 𝑡 = 𝑡𝑎𝑛ℎ 𝑡
𝑐𝑑 𝑚

i) Bisection method
ii) False-position method
iii) Newton Raphson method
iv) Secant method

61
 For fluid flow in pipes, friction is describe by a dimensionless
number, the Fanning friction factor f. The Fanning friction factor
is dependent on a number of parameters related to the size of
the pipe and the fluid, which can all be represented by another
dimensionless quantity, the Reynolds number Re. A formula that
predicts f given Re is the von Karman equation:
1
= 4𝑙𝑜𝑔10 𝑅𝑒 𝑓 − 0.4
𝑓

 Typical values for the Reynolds number for turbulent flow are
10,000 to 500,000 and for the Fanning friction factor are 0.001
to 0.01. Solve for f given a user-supplied value of Re between
2,500 and 1,000,000.
i) Bisection method
ii) False-position method
iii) Newton Raphson method
iv) Secant method
62
MATLAB FUNCTION:
 fzero
 roots (polynomials)

63
 MATLAB’s fzero provides the best qualities of
both bracketing methods and open methods.

i) Using an initial guess:


x = fzero(function, x0)
[x, fx] = fzero(function, x0)
▪ function is a function handle to the function being evaluated
▪ x0 is the initial guess
▪ x is the location of the root
▪ fx is the function evaluated at that root

ii) Using an initial bracket:


x = fzero(function, [x0 x1])
[x, fx] = fzero(function, [x0 x1])
▪ As above, except x0 and x1 are guesses that must bracket a
sign change
Uses fzero to find roots of f(x)=x10-1 starting with an initial
guess of x=0.5.

Command window
fun= @(x) x^10-1;
[x, fx] = fzero(fun, 0.5)

Answer:
Command window
x= 1
fx =0
 Determine the positive real root of
ln(x2) = 0.7 using

a) Solve using fzero with initial guesses of xl = 0.5


and xu = 2

66
 Options may be passed to fzero as a third input
argument - the options are a data structure created by
the optimset command

 options = optimset(‘par1’, val1, ‘par2’,


val2,…)
 parn is the name of the parameter to be set
 valn is the value to which to set that parameter
 The parameters commonly used with fzero are:
▪ display: when set to ‘iter’ displays a detailed
record of all the iterations
▪ tolx: A positive scalar that sets a termination
tolerance on x.
Uses fzero to find roots of f(x)=x10-1 starting with an initial
guess of x=0.5. Sets options to display each iteration of
root finding process
Command window

function= @(x) x^10-1;


options = optimset(‘display’, ‘iter’);
[x, fx] = fzero(function, 0.5, options)
RESULTS : x=1, fx=0 after 35 function counts
 Determine the positive real root of
ln(x2) = 0.7

a) Using fzero with initial guesses of xl = 0.5 and


xu = 2
b) Sets options to display each iteration of root
finding process

70
 MATLAB has a built in program called roots to
determine all the roots of a polynomial - including
imaginary and complex ones.
 x = roots(c)
 x is a column vector containing the roots
 c is a row vector containing the polynomial coefficients
 Example: Find the roots of

f(x)=x5-3.5x4+2.75x3+2.125x2-3.875x+1.25

Command window

x = roots([1 -3.5 2.75 2.125 -3.875 1.25])


 MATLAB’s poly function can be used to determine
polynomial coefficients if roots are given:
 b = poly([0.5 -1])
▪ Finds f(x) where f(x) =0 for x=0.5 and x=-1
▪ MATLAB reports b = [1.000 0.5000 -0.5000]
▪ This corresponds to f(x)=x2+0.5x-0.5

 MATLAB’s polyval function can evaluate a polynomial at


one or more points:
 a = [1 -3.5 2.75 2.125 -3.875 1.25];
▪ If used as coefficients of a polynomial, this corresponds
to f(x)=x5-3.5x4+2.75x3+2.125x2-3.875x+1.25
 polyval(a, 1)
▪ This calculates f(1), which MATLAB reports as -0.2500

You might also like