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

CSU 07320: COMPUTING MATHEMATICS

Lecture 2: Roots of Functions Using Numerical Methods

December 6, 2022

December 6, 2022 1 / 17
Zeros of a Function

The zeros of a function are the solutions to the equation you get when you set the
polynomial equal to zero.
For example, the function
f (x) = x 2 + 2x − 15, (1)
has two factors,
(x + 5) and (x − 3).
Hence, the roots (solutions or zeros) of f are x = −5 and 3.

December 6, 2022 2 / 17
A wide range of problems can be translated into an equation (algebraic or non-algebraic or
combination of both), and by solving the equation we solve the problem. Algebraic functions
of the form
f (x) = a0 x n + a1 x n−1 + a2 x n−2 + · · · + an−1 x + an (2)
are called polynomials. A non-algebraic function is called a transcendental function, e.g.

f (x) = ln x 3 , φ(x) = e −0.5x − 5x, ψ(x) = sin2 x − x 2 − 2, etc.

Most equations cannot be solved by traditional pencil-and paper methods. And even for
equations that can be solved in this way, the expressions may become so complicated that they
are almost useless for many purposes.

In this lecture, we are going to approach the problem of solving equations in a completely
different way. Instead of looking for exact solutions, we are going to derive and use numerical
methods that can compute approximations to the roots, with whatever accuracy is desired.

December 6, 2022 3 / 17
We have several methods of determining roots of a function. Here we discuss few of them:

1 Secant and falsi methods-slope-based methods;


2 Newton-Raphson method-an iterative method.

December 6, 2022 4 / 17
Newton-Raphson method
Let x0 be an approximate root of the equation f (x) = 0.
Let x1 = x0 + h be the correct root so that f (x1 ) = 0.
By Taylor’s series,

h2 00
f (x0 + h) = f (x0 ) + hf 0 (x0 ) + f (x0 ) + . . . = f (x1 ) = 0. (3)
2!
Neglecting the second and higher order derivatives we find that f (x0 ) + hf 0 (x0 ) = 0,
from which
f (x0 )
h=− 0 . (4)
f (x0 )
But x1 = x0 + h, which means that
f (x0 )
x1 = x0 − . (5)
f 0 (x0 )

December 6, 2022 5 / 17
Again, x2 = x1 + h that implies

h2 00
f (x2 ) = f (x1 + h) = f (x1 ) + hf 0 (x1 ) + f (x1 ) + . . . = 0. (6)
2!
Neglecting higher order derivatives than the first we have f (x1 ) + hf 0 (x1 ) = 0, which
implies that
f (x1 )
h=− 0 . (7)
f (x1 )
Hence, since x2 = x1 + h,
f (x1 )
x2 = x1 − . (8)
f 0 (x1 )
Following this trend, the successive approximations x3 , x4 , . . . , xn+1 take the forms,

December 6, 2022 6 / 17
f (x2 )
x3 = x2 −
f 0 (x2 )
f (x3
x4 = x3 − 0
f (x3 )
..
.
f (xn )
xn+1 = xn − (9)
f 0 (xn )

The equation given by (9) is called the Newton-Raphson formula.

December 6, 2022 7 / 17
Example (1)
Find the real root of the equation x = e −x by using the Newton-Raphson method correct to
six decimal places.
Solution:
After multiplying both sides by e x , the equation x = e −x can be written in the form

f (x) = xe x − 1.

It follows that f 0 (x) = (1 + x)e x .


Let x0 = 1 be the initial approximation.
This implies that f (x0 ) = e − 1 and f 0 (x0 ) = 2e.
Thus,
f (x0 ) e −1
x1 = x0 − 0
=1− = 0.6839387.
f (x0 ) 2e
Using the same procedure, we summarize other iterations in the table below.

December 6, 2022 8 / 17
Example (1)
n xn f (xn ) xn+1
0 1 1.7182818 0.6839397
1 0.6839397 0.3553424 0.5774545
2 0.5774545 0.0287340 0.5672297
3 0.5672297 0.0002388 0.5671433

Here we go until |xn+1 − xn | < ε, ε = 0.0001 and f (xn ) < 0.001.

December 6, 2022 8 / 17
Limitation of Newton-Raphson Method

If f 0 (xn ) vanishes or is very small, the Newton-Raphson method will not converge.
Thus from
f (xn )
xn+1 = xn − ,
f 0 (xn )
if f 0 (xn ) is very small, the quantity

f (xn )
∆xn = xn+1 − xn = −
f 0 (xn )

becomes very large. This has the effect of throwing us away from the root we are trying
to approximate.

December 6, 2022 9 / 17
The Secant Method

Figure 1: The first two iterations of the secant method. The red curve shows the function f , and the
blue lines are the secants.

December 6, 2022 10 / 17
Starting with initial values x0 and x1 , we construct a line through the points (x0 , f (x0 ))
and (x1 , f (x1 )), as shown in Figure 1 above.
In slope-intercept form, the equation of this line is

f (x1 ) − f (x0 )
y= (x − x1 ) + f (x1 ). (10)
x1 − x0
The root of this linear function, that is the value of x such that y = 0, is
x1 − x0
x = x1 − f (x1 ) . (11)
f (x1 ) − f (x0 )

We then use this new value of x as x2 and repeat the process using x1 and x2 instead of
x0 and x1 .
We continue this process, solving for x3 , x4 , etc., until we reach a sufficiently high level of
precision (a sufficiently small difference between xn and xn−1 ):

December 6, 2022 11 / 17
x1 − x0
x2 = x1 − f (x1 ) ,
f (x1 ) − f (x0 )
x2 − x1
x3 = x2 − f (x2 ) ,
f (x2 ) − f (x1 )
..
.
xn−1 − xn−2
xn = xn−1 − f (xn−1 ) . (12)
f (xn−1 ) − f (xn−2 )

Equation (12) is the secant method formula.

Convergence: The iterates xn of the secant method converge to a root of f if the initial
values x0 and x1 are sufficiently close to the root.

December 6, 2022 12 / 17
Example (2)
Use secant method to find the root near 2 of the equation x 3 − 2x − 5 = 0. Start the
iterations with x0 = 1.9 and x1 = 2.0.
Solution:
The equation can be written in the form of iterations as f (xn ) = xn3 − 2xn − 5.
It follows that, with x0 = 1.9 and x1 = 2.0, we have f (x0 ) = −1.941 and f (x1 ) = −1.000.
Using the secant formula (12), we have
x1 − x0
x2 = x1 − f (x1 ) = 2.1063,
f (x1 ) − f (x0 )

which implies that f (x2 ) = 0.1320.


We proceed on with other iterations and summarize the results in table below.

December 6, 2022 13 / 17
Example (2)
n xn f (xn )
0 1.9 −1.941
1 2.0 −1.000
2 2.1063 0.1320
3 2.0939 0.0073
4 2.09455 −0.00002
5 2.09455

Note that, the secant method is the slowest converging iteration method.

December 6, 2022 14 / 17
The False position (Regular Falsi) Method
This is the same as secant rule but you have to choose two xn and xn+1 such that
f (xn ) · f (xn+1 ) < 0.

Example (3)
Find the real root of the equation x 3 − 2x − 5 = 0.
Solution:
Choose x0 = 2 and x1 = 3 since f (x0 ) · f (x1 ) = −16 < 0. This implies that the root lies
between 2 and 3.
Using the secant formula (12), we have
x1 − x0
x2 = x1 − f (x1 ) = 2.059,
f (x1 ) − f (x0 )

which implies that f (x2 ) = −0.386.


December 6, 2022 15 / 17
Example (3)
Since f (x1 ) = 16, we find that f (x1 ) · f (x2 ) < 0. This signifies that there is a root
between 2.059 and 3. Using the secant formula (12), we have
x2 − x1
x3 = x2 − f (x2 ) = 2.0812.
f (x2 ) − f (x1 )

which implies that f (x3 ) = −0.1479.


Since f (x1 ) · f (x3 ) < 0, the fourth iteration is given by
x3 − x1
x4 = x3 − f (x3 ) = 2.0896,
f (x3 ) − f (x1 )

and f (x4 ) = −0.5494. This signifies that f (x1 ) · f (x4 ) < 0 giving the fifth iteration as
x4 − x1
x5 = x4 − f (x4 ) = 2.0927
f (x4 ) − f (x1 )

with f (x5 ) = −0.2030.


December 6, 2022 16 / 17
Example (3)
Repeating the same process successively, we find that
x5 − x1
x6 = x5 − f (x5 ) = 2.0939,
f (x5 ) − f (x1 )
x6 − x1
x7 = x6 − f (x6 ) = 2.0943,
f (x6 ) − f (x1 )
x7 − x1
x8 = x7 − f (x7 ) = 2.0945,
f (x7 ) − f (x1 )
x8 − x1
x9 = x8 − f (x8 ) = 2.0945.
f (x8 ) − f (x1 )

The correct root is x = 2.0945, correct to four decimal places.

We notice that this method is also slow in converging.

December 6, 2022 17 / 17

You might also like