Download as pdf or txt
Download as pdf or txt
You are on page 1of 35

Chapter 2: Solutions of Equations of One

Variable

2022

1/31
(UNIMAS) Chapter 2 2022 1 / 31
Outline

1 Bisection Method

2 Newton-Raphson Method

3 Secant Method

2/31
(UNIMAS) Chapter 2 2022 2 / 31
Bisection Method

One of the first numerical methods developed to find the root of


a nonlinear equation f (x) = 0 was the bisection method (also
called binary-search method). The method is based on the
following theorem.

Theorem
An equation f (x) = 0 , where
f (x) is a real continuous function,
has at least one root between xl
and xu if f (xl )f (xu ) < 0.

3/31
(UNIMAS) Chapter 2 2022 3 / 31
Bisection Method

If f (xl )f (xu ) > 0,


there may or may not
be any root between xl
and xu .
If f (xl )f (xu ) < 0, then
there may be more
than one root between
xl and xu .

So the theorem only guarantees one root between xl and xu .


Since the method is based on finding the root between two
points, the method falls under the category of bracketing
methods
4/31
(UNIMAS) Chapter 2 2022 4 / 31
Algorithm for the Bisection Method
1 Choose xl and xu as two guesses for the root such that
f (xl )f (xu ) < 0, or in other words, f (x) changes sign between xl and
xu .
2 Estimate the root, xm of the equation f (x) = 0 as the mid-point
between xl and xu .
xl + xu
xm = .
2
3 Check the following
(a) If f (xl )f (xm ) < 0 then the root lies between xl and xm ; then
xl = xl and xu = xm .
(b) If f (xl )f (xm ) > 0 then the root lies between xm and xu ; then
xl = xm and xu = xu .
(c) If f (xm ) = 0, then the root is xm . Stop the algorithm if this is
true.
5/31
(UNIMAS) Chapter 2 2022 5 / 31
Algorithm for the Bisection Method
4 Find the new estimate of the root
xl + xu
xm = .
2
Find the absolute relative approximate error as
xmnew xmold
|"a | = ⇥ 100%
xmnew
where xmnew = estimated root from present iteration and xmold =
estimated root from previous iteration
5 Compare the absolute relative approximate error |"a | with the
pre-specified relative error tolerance "s . If |"a | > "s , then go to
Step 3, else stop the algorithm.
6 Note one should also check whether the number of iterations is
more than the maximum number of iterations allowed. If so, one
needs to terminate the algorithm. 6/31
(UNIMAS) Chapter 2 2022 6 / 31
Algorithm for the Bisection Method
Example
Show that f (x) = x 3 7.5x 2 + 17.75x 13.125 = 0 has a root in
[1.2, 2]. Use 3 iterations of the bisection method to determine the
root.
Solution:
f (xl ) = f (1.2) = 0.897, f (xu ) = 0.171 ) f (xl )f (xm ) < 0
So there is at least one root in [1.2, 2].
Iteration 1: Estimate the root
xl + xu 1.2 + 2
xm = = = 1.6
2 2
f (xm ) = f (1.6) = 0.171
Since f (xl )f (xm ) < 0, the new bracket is xl = 1.2, xu = 1.6. 7/31
(UNIMAS) Chapter 2 2022 7 / 31
Algorithm for the Bisection Method
Iteration 2: Estimate the root
xl + xu 1.2 + 1.6
xm = = = 1.4
2 2
f (xm ) = f (1.4) = 0.231
Since f (xl )f (xm ) > 0, the new bracket is xl = 1.4, xu = 1.6.
Iteration 3: Estimate the root
xl + xu 1.4 + 1.6
xm = = = 1.5
2 2
f (xm ) = f (1.5) = 0.
) the root is x = 1.5. In Table form:
n xl xu xm f (xl ) f (xm ) flxu )
1 1.2 2 1.6 0.897 0.171
2 1.2 1.6 1.4 0.897 0.231
3 1.4 1.6 1.5 0.231 0
8/31
(UNIMAS) Chapter 2 2022 8 / 31
Algorithm for the Bisection Method

Example
The mass for a jumper with a given drag coefficient to attain a
prescribed velocity in a set time period is described by
r ✓r ◆
gm gcd
f (m) = tanh t v.
cd m

Use the bisection method to determine the mass, m of the bungee


jumper with a drag coefficient, cd of 0.25 kg/m to have a velocity, v
of 36 m/s after 4 s of free fall. Continue until |"a |% < "s = 0.5%.
Note: The acceleration of gravity, g is 9.81 m/s 2 .

9/31
(UNIMAS) Chapter 2 2022 9 / 31
Algorithm for the Bisection Method

Plot the graph of the function to get the initial guesses/bracket.


From graphical solution, we can see that the function changes sign
between 50 and 200.

10/31
(UNIMAS) Chapter 2 2022 10 / 31
Algorithm for the Bisection Method

n xl
MM BAM
xu xr
BAM |"a |%
1 50 200 125
2 125 200 162.5 23.08
3 125 162.5 143.75 13.04
4 125 143.75 134.375 6.98
5 134.375 143.75 139.0625 3.37
6 139.0625 143.75 141.4063 1.66
7 141.4063 143.75 142.5781 0.82
8 142.5781 143.75 143.1641 0.41

Thus after eight iterations |"a |% finally falls below "s = 0.5%, and
the computation can be terminated.

11/31
(UNIMAS) Chapter 2 2022 11 / 31
Algorithm for the Bisection Method

12/31
(UNIMAS) Chapter 2 2022 12 / 31
Algorithm for the Bisection Method
Example
Find the root of the function f (x) = sin 2x + x 3 3 using bisection.
Iterate until |"a | < 0.5%
✗ 1=0 Xu -2
-

Solution: f- 1111 =
gin 271+713-3
Xi Xm
Xu

-1,2
Xm = 0 0 2 I
= ,

flxm ) =
f- (1) =
9in 211 ) + (1)
3- 3
=
-1.0907 ✗ 1=1 ,
Xu =
2

✗ m=
I + I 2 ) =
1.5
2

3- 3
f/ ✗m ) 21-0.04535 ) 1-0.04535 )
fl -0.04535 ) +
-

=
sin
=

-3.04133
=

/ Eat
-01%5,345,3-1--23.0307
=

× ,=

"

✗, ✗ n= 1.5
=
1.25

Xm =
1.25 + 1.5 =
1.375
2

flxm / =
9in 211.3751 t 11.37573 -3

13/31
(UNIMAS) Chapter 2 2022 13 / 31
f- 111 ) =
sin 211-1713 -3

×,
__ 0 ,
Xn=2

Xi Xu Xin 1-1×7 flxu ) flxm ) Error ,Ea

I
0 2 1 -3 4.2432 -

1. 0907

2 1 2 1.5 -1.0907 4.2432 0.5161 33.33%


3 I 1,5 1.25 -

1.0907 0,5161 -0.4484 20%


4 1.25 1.5 1.375 -

0.4484 0.5161 -0.0187 9.09%

⑤ 1.375 1.5 1.4375 -

0.0187 0.5161 0.2339 4.35%

6 1.375 1.4375 1.40625 -0.0187 0.2339 0.1041 2.22%

7 1.375 1.40625 1.3906 -0.0187 0.1041 0.04174 1.13%

⑧ 1.375 1.3906 1.3828 -0.0187 0.04174 0.0113 0.56%


9 1.375 1.3828 I. 3789 -0.0187 0.0113 0.00377 0.2870

-1,2 / Ea /
I ✗m = 0 2 Xm =
I -12 =
1.5 =
1.5 -

I =
33.33%
= ,
2 1.5
I

3 Xm = I -11.5 =
1.25 / Ea =
1.25-1.5 =
-20%
,

2 1.25

4 Xm = 1.251-1.5 =
1,375 ,
/ Ea / =
1.375-1.25=0.0909
2 1.375 =
9.09%

5 Xm =
1.375+1.5
=
1.4375 { a
=
1.4375
-

1.375 = 4.35%
,

2 1.4375

⑥ Xm =
1.4375+1.375=1.40625 ,
/ Ea / =
1.40625 -
1.4375 =
2.2270
2 1.40625

7 ✗m =
1.375-11.40625=1.3906 ,
/ Ea / =
1.3906-1.40625
=
1.1370
2 1.3906

8 Xm = 1.375-11.3906--1.3828 ,
/ Ea / =
1.3828 -

1.3906 =
0.56%
2 1.3828

9 Xm =
1.3751-1.3828=1.3789 / Eat =
1.3789 -
1.3828 =
0.28%
,

2 1.3789
Advantages and Drawbacks of Bisection Method

Advantages of Bisection Method:


The bisection method is always convergent. Since the method
brackets the root, the method is guaranteed to converge.
Errors can be managed.
Drawbacks of Bisection Method
The convergence of the bisection method is slow as it is simply
based on halving the interval.
If one of the initial guesses is closer to the root, it will take a
larger number of iterations to reach the root.

14/31
(UNIMAS) Chapter 2 2022 14 / 31
Drawbacks of Bisection Method
If a function f (x) is such that it just touches the x axis, it will
be unable to find the lower guess, xl , and upper guess, xu , such
that f (xl )f (xu ) < 0.

Figure: The equation f (x) = x 2 = 0 has a single root at x = 0 that


cannot be bracketed.
15/31
(UNIMAS) Chapter 2 2022 15 / 31
Drawbacks of Bisection Method
For functions f (x) where there is a singularity and it reverses
sign at the singularity, the bisection method may converge on
the singularity, e.g. f (x) = 1/x where xl = 2, xu = 3 are valid
initial guesses which satisfy f (xl )f (xu ) < 0. However the
function is not continuous.

Figure: The equation f (x) = 1/x = 0 has no root but changes sign.
16/31
(UNIMAS) Chapter 2 2022 16 / 31
Newton-Raphson Method

Methods such as the bisection method of finding roots of a


nonlinear equation require bracketing of the root by two guesses.
Such methods are called bracketing methods.
These methods are always convergent since they are based on
reducing the interval between the two guesses so as to zero in on
the root of the equation.
In the Newton-Raphson method, the root is not bracketed. In
fact, only one initial guess of the root is needed to get the
iterative process started to find the root of an equation. The
method hence falls in the category of open methods.
Convergence in open methods is not guaranteed but if the
method does converge, it does so much faster than the
bracketing methods.
17/31
(UNIMAS) Chapter 2 2022 17 / 31
Derivation of Newton-Raphson Method

The Newton-Raphson method can


be derived on the basis of this
geometrical interpretation (see
Figure). The first derivative at x is
equivalent to the slope:

f (xi ) 0
f 0 (xi ) =
xi xi+1

which can be rearranged to yield

f (xi )
xi+1 = xi (1)
f 0 (xi )

which is called the


Newton-Raphson formula.
18/31
(UNIMAS) Chapter 2 2022 18 / 31
Algorithm of the Newton-Raphson Method
1 Evaluate f 0 (x) symbolically.
2 Use the initial guess, xi to estimate the new value of the root,
xi+1 as
f (xi )
xi+1 = xi
f 0 (xi )
3 Find the absolute relative approximate error, |"a | as
xi+1 xi
|"a | = ⇥ 100%
xi+1
4 Compare the absolute relative approximate error with the
pre-specified relative error tolerance, "s . If |"a | > "s , then go to
step 2, else stop the algorithm. Also, check if the number of
iterations has exceeded the maximum number of iterations
allowed. If so, one needs to terminate the algorithm and notify
the user. 19/31
(UNIMAS) Chapter 2 2022 19 / 31
Algorithm of the Newton-Raphson Method

Example
Use the Newton-Raphson method to estimate the root of
f (x) = e x x employing an initial guess of x0 = 0.
flail f- 171,7
'

/
Solution: f 0 (x) = e x 1 i xi |"a |%
which can be substituted into the 0 0
formula to give 1 0.500000000 100
f (xi ) e xi
xi 2 0.566311003 11.70929
xi+1 = xi = xi . 3 0.567143165 0.14673
f 0 (xi ) e x1i 1 5
4 0.567143290 2.204 ⇥ 10
Starting with an initial guess of
The root is x ⇡ 0.567143290 if "s
x0 = 0, this iterative equation can
is set at 0.005%. Note that the
be applied to compute
approach rapidly converges.
20/31
(UNIMAS) Chapter 2 2022 20 / 31
Algorithm of the Newton-Raphson Method
Example
Find the root of the function f (x) = sin 2x + x 3 3 using
Newton-Raphson method. Iterate until |"a | < 0.5%. Let the initial
guess to be x0 = 1.
Solution:

21/31
(UNIMAS) Chapter 2 2022 21 / 31
1-1717=9111271-1713-3

ix
/ 111=21052111-3712i-f. it
"
f- Iki ) '
Error

{a 1.50316 I 33.473%
= -

0 I -1.0907 2.16771 1.50316

I 1.50316 0.53123 4.79674 33.473% 1.39241 -1.50316 -7.954%


Ea=
=

✗it , =
X; -

ginzx +713 -
3 2 1.39241 0.04886 3.94236 7.954% 1.39241

2,092×+3712 3 1.38002 0.000548 3.85719 0.898% Eg =


1.38002-1.39241 =
0.898%

4 1.37988 0.010% 1.38002

Ea =
1.37988 -
1.38002

I. 37988

= -

0.000101

=
0.0101 Yo
Algorithm of the Newton-Raphson Method
Example
Use the Newton-Raphson method to estimate the root of
f (x) = 0.9x 2 + 1.7x 5 employing an initial guess of x0 = 1 accurate
to within "s = 0.001.
Solution:
f- 1711=0.9712+1.711-5
f /x )
'
=
1.811 + 1.7

✗ it / 0.9712-11.711-5
=
✗i -

1.871 -11.7

22/31
(UNIMAS) Chapter 2 2022 22 / 31
f- 1111=0.9712-11.711-5
f- 1711=1.871+1.7
Xiflxilfltxilt-rror-i.is
'

1. 685714 0.42318 4.734285 0.40677

1. 59633 0.007204 4. 57339 0.05599

✗ it , = Xi -
0.9712+1.721-5 1.59475 / 0.0009907
1. 821+1.7
I

① Es =
1.685714 -
I =
0.40677

1.685714

2
Es =
1.59633 -
1.685714 = -0.05599
-

1.59633

3 Es =
1.591475-1.59633=-0.0009907
1.59475
Drawbacks of the Newton-Raphson Method
Although the Newton-Raphson method is often very efficient, there
are situations where it performs poorly.

Example
Determine the positive root of
f (x) = x 10 1 using the Newton-
Raphson method and an initial
guess of x = 0.5.

Solution: The Newton-Raphson


formula for this case is
xi10 1
xi+1 = xi
10xi9
The technique is converging but at
which can be used to compute a very slow rate. 23/31
(UNIMAS) Chapter 2 2022 23 / 31
Drawbacks of the Newton-Raphson Method
Why does this happen? A simple
plot of the first few iterations is
helpful in providing insight.
Notice how the first guess is in a
region where the slope is near
zero. Thus, the first iteration
flings the solution far away from
the initial guess to a new value
(x = 51.65) where f (x) has an
extremely high value.
The solution then plods along for
over 40 iterations until
converging on the root with
adequate accuracy.
24/31
(UNIMAS) Chapter 2 2022 24 / 31
Drawbacks of the Newton-Raphson Method

Aside from slow convergence due to the nature of the function,


other difficulties can arise.
Divergence at inflection points: If the selection of the initial
guess x0 of the root turns out to be close to the inflection point
of the function f (x) in the equation f (x) = 0, the iterations
beginning at x0 progressively diverge from the root.

25/31
(UNIMAS) Chapter 2 2022 25 / 31
Drawbacks of the Newton-Raphson Method

Root jumping: Figure below shows how an initial guess that is


close to one root can jump to a location several roots away.
This tendency to move away from the area of interest is due to
the fact that near-zero slopes are encountered. Obviously, a zero
slope [f 0 (x) = 0] is a real disaster because it causes division by
zero in the Newton-Raphson formula.

26/31
(UNIMAS) Chapter 2 2022 26 / 31
Drawbacks of the Newton-Raphson Method

Oscillations near local maximum and minimum : Figure


below illustrates the tendency of the Newton-Raphson technique
to oscillate around a local maximum or minimum. Such
oscillations may persist, or, a near-zero slope is reached
whereupon the solution is sent far from the area of interest.

27/31
(UNIMAS) Chapter 2 2022 27 / 31
Drawbacks of the Newton-Raphson Method

Division by zero : it means that the solution shoots o↵


horizontally and never hits the x-axis.

28/31
(UNIMAS) Chapter 2 2022 28 / 31
Secant Method
A potential problem in implementing the Newton-Raphson
method is the evaluation of the derivative. Although this is not
inconvenient for polynomials and many other functions, 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 di↵erence:
f (xi 1 ) f (xi )
f 0 (x) ⇡
xi 1 xi
This approximation can be substituted into (1) to yield the
following iterative equation:
f (xi )(xi 1 xi )
xi+1 = xi . (2)
f (xi 1 ) f (xi )
(2) is the formula for the secant method. 29/31
(UNIMAS) Chapter 2 2022 29 / 31
Secant Method
Notice that the approach requires two initial estimates of x.
However, because f (x) is not required to change signs between the
estimates, it is not classified as a bracketing method.

Example
Use the Secant method to find a solution to x = cos x where the two
initial guesses are x0 = 0.5 and x1 = ⇡/4. Continue until |"a |% < 0.005%

Solution: x = cos x ) f (x) = cos x x.


i xi |"a |% FIX ,

0 0.5
1 0.785398163 36.3380
2 0.736384138 6.6560
3 0.739058139 0.361812
4 0.739085149 0.003249
30/31
(UNIMAS) Chapter 2 2022 30 / 31
Secant Method
Example
Find the root of the function f (x) = sin 2x + x 3 3 using secant
method. Iterate until |"a | < 0.5%
X- Xi
Solution: f 1(1) =
sin2e) 113-3
+
=0.2

Xo 0
=

x =2

Allres
Xi f (Xi-1) Error

2 4.2432 141.44%
0.82836-1.43328
3 0.32284-2,36461-1.43528

31/31
(UNIMAS) Chapter 2 2022 31 / 31
f lil) =
sin 271 193-3
+

(( f I(i) Error

O
-

3 Present Past
A
-

I 44. 2432 Present

8. 82836 1.43528 141.44%

1. 124 -0.79936 2 6,333%


1.49 675 0.50066 2 4.871 To
1.39339 -0.0998 10.593%
1,3772] -

0.010225 1. 730 %

1.37994 0.00023963 0.197%


1. 37988 0.000000 241 0.00435%

You might also like