Numerical Methods: King Saud University
Numerical Methods: King Saud University
x2 + 5x + 6 = 0; x3 = 2x + 1; x200 − 2x + 1 = 0.
2. The power of the unknown variable (not a positive integer number). For
example, the following non-polynomial equations are nonlinear
√ 2
x−1 + 2x = 1; x + x = 2; x2/3 + + 4 = 0.
x
3. The equation which involves the trigonometric functions, exponential
functions and logarithmic functions. For example, all the following
transcendental equations are nonlinear
x = cos(x); ex + x − 10 = 0; x + ln x = 10.
Roots of nonlinear equations
One of the most basic problems that numerical techniques are used for is finding
roots of nonlinear equations. This process involves finding a root, or solution, of
an equation of the form
f (x) = 0. (1)
A root of this equation is also called a zero of the function f . Here, we are going
to look at some common numerical methods for finding roots of equations.
Important Points
I. Nonlinear equations may have many roots but we will seek the approximation
of only one of its real root α lies in the given interval [a, b], that is
II. If f (x) is continuous function in in a interval [a, b] and f (x) has opposite signs
at the end points of the interval, then there must be a root of nonlinear equation
f (x) = 0 in [a, b].
III. Root of a nonlinear equation may be simple (not repeating) or multiple
(repeating). Simple root means
For example, α1 = −3 and α2 = −2 are the simple roots of the nonlinear equation
x2 + 5x + 6 = 0. For the multiple root, we mean
V. Remember that the best method for the approximation of the simple root of
nonlinear equation is Newton’s method (called quadratic convergent method) and
for multiple root of nonlinear equation is modified Newton’s method (called
quadratic convergent method). Newton’s method for multiple root of nonlinear
root is called a linear convergent method.
The Bisection Method
The Bisection method is used to determine, to any specified accuracy that your
computer will permit, a solution to f (x) = 0 on an interval [a, b], provided:
I f (x) is continuous on [a, b];
The concept of the Bisection method is simple, and is based on utilizing the
Intermediate Value Theorem. Essentially, due the continuity of f on [a, b], and
since f (a)f (b) < 0, then there must be a point a < α < b such that f (α) = 0. The
implication is that one of the values is negative and the other is positive. These
conditions can be easily satisfied by sketching the function, see Figure 1.
y=f(x)
a c c
1 2 3
0
c b1
1
a+b
c= ,
2
and, in general
an + bn
cn = , n ≥ 1. (2)
2
The iterative formula (2) is known as the bisection method.
If f (c) ≈ 0, then c ≈ α is the desired root, and, if not, then there are two
possibilities.
I Firstly, if f (a)f (c) < 0, then f (x) has a zero between point a and point c.
The process can then be repeated on the new interval [a, c].
I Secondly, if f (a)f (c) > 0 it follows that f (b)f (c) < 0 since it is known that
f (b) and f (c) have opposite signs. Hence, f (x) has zero between point c and
point b and the process can be repeated with [c, b]. We see that after one step
of the process, we have found either a zero or a new bracketing interval which
is precisely half the length of the original one.
I The process continue until the desired accuracy is achieved.
Example 0.1
Use the bisection method to find the approximation to the root of the equation
x3 = 2x + 1,
and since f (1.5)f (2.0) < 0, so that a root of f (x) = 0 lies in the interval [1.5, 2.0].
Using formula (2) (when n = 1), we get:
a1 + b1
c1 = = 1.75; f (c1 ) = 0.859375.
2
Hence the function changes sign on [a1 , c1 ] = [1.5, 1.75]. To continue, we squeeze
from right and set a2 = a1 and b2 = c1 . Then the midpoint is:
a2 + b2
c2 = = 1.625; f (c2 ) = 0.041056.
2
Continue in this way we obtain a sequence {ck } of approximation shown by
Table 1.
Table: Solution of x3 = 2x + 1 by bisection method
2 2.5
1
y(x) = x3 − 2x − 1 2
3
0 1.5 y(x) = x − 2x − 1
y
y
−1 1
−2 0.5
−3 0
−4 −0.5
root 1 root 2 root 3
−5 −1
−2 −1.5 −1 −0.5 0 0.5 1 1.5 2 1.5 1.55 1.6 1.65 1.7 1.75 1.8 1.85 1.9 1.95 2
x x
We can easily find the roots (1.61803399, −1.00, −0.61803399) of the equation
x3 = 2x + 1 by defining the coefficients of the polynomial equation using
MATLAB commands as:
Since f (x) is continuous on [0.5, 1.0] and f (0.5).f (1.0) < 0, so that a root of
f (x) = 0 lies in the interval [0.5, 1.0]. Using formula (2) (when n = 1), we get:
a1 + b1
c1 = = 0.75; f (c1 ) = 0.240236.
2
Hence the function changes sign on [a1 , c1 ] = [0.5, 0.75]. To continue, we squeeze
from right and set a2 = a1 and b2 = c1 . Then the midpoint is:
a2 + b2
c2 = = 0.625; f (c2 ) = −0.090957.
2
2 1.2
1.8
1
1.6
0.8
1.4 y = x3 + 2x − 1
y = x3 + 2x − sin x − 1
0.6
1.2
y
y
1 0.4
0.8
0.2
0.6
α
y = sin x
0
0.4
−0.2
0.2
0 −0.4
0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 0.95 1 0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 0.95 1
x x
We see that the functional values are approaching zero as the number of iterations
is increase. We got the desired approximation to the root of the given equation is
c8 = 0.662109 ≈ α after 8 iterations with accuracy = 10−3 . •
Program 2.1
MATLAB m-file for the Bisection Method
function sol=bisect(fn,a,b,tol)
f a = f eval(f n, a); f b = f eval(f n, b);
if f a ∗ f b > 0; fprintf(’Endpoints have same sign’) return end
while abs (b − a) > tol c = (a + b)/2; f c = f eval(f n, c);
if f a ∗ f c < 0; b = c; else a = c; end; end; sol=(a + b)/2;
Theorem 1
(Bisection Convergence and Error Theorem)
Let f (x) be continuous function defined on the given initial interval
[a0 , b0 ] = [a, b] and suppose that f (a)f (b) < 0. Then bisection method (2)
generates a sequence {cn }∞ n=1 approximating α ∈ (a, b) with the property
b−a
|α − cn | ≤ , n ≥ 1. (3)
2n
Moreover, to obtain accuracy of
|α − cn | ≤ ,
ln 10k (b − a)
n≥ , (4)
ln 2
where k is nonnegative integer.
Note:
The above Theorem 1 gives us information about bounds for errors in
approximation and the number of bisections needed to obtain any given accuracy.
Example 0.3
Show that number of iterations of bisection will require to attain an accuracy of
10−4 using the starting interval [a, b] is
ln(b − a) + 4 ln 5
n≥ + 4.
ln 2
Determine the number of iterations needed to achieve the an approximation with
same above given accuracy to the solution of x3 − 2x − 1 = 0 lying in the interval
[1.5, 2].
Solution. By using the inequality (4), we get
ln 10k (b − a)
ln(b − a) + ln[(5)(2)]4
n≥ = ,
ln 2 ln 2
or
ln(b − a) + 4[ln 5 + ln 2] ln(b − a) + 4 ln 5
n≥ = + 4.
ln 2 ln 2
Now by taking a = 1.5 and b = 2 in the above inequality, we get
ln(2 − 1.5) + 4 ln 5
n≥ + 4 = 8.2877 + 4 = 12.2877.
ln 2
So no more than thirteen iterations are required to obtain an approximation
accurate to within the given accuracy 10−4 . •
Example 0.4
Find a bound for the number of iterations needed to achieve an approximation
with accuracy 10−1 to the solution of xex = 1 lying in the interval [0.5, 1] using the
bisection method. Find an approximation to the root with this degree of accuracy.
Solution. Here a = 0.5, b = 1 and k = 1, then by using inequality (4), we get
ln[101 (1 − 0.5)]
n≥ ≈ 2.3219.
ln 2
So no more than three iterations are required to obtain an approximation accurate
to within 10−1 .
The given function f (x) = xex − 1 is continuous on [0.5, 1.0], so starting with
a1 = 0.5 and b1 = 1, we compute:
since f (0.5)f (1) < 0, so that a root of f (x) = 0 lies in the interval [0.5, 1]. Using
formula (2) (when n = 1), we get:
a1 + b1
c1 = = 0.75; f (c1 ) = 0.5878.
2
Hence the function changes sign on [a1 , c1 ] = [0.5, 0.75]. To continue, we squeeze
from right and set a2 = a1 and b2 = c1 . Then the bisection formula gives
a2 + b2
c2 = = 0.625; f (c2 ) = 0.1677.
2
Finally, we have in the similar manner as
a3 + b3
c3 = = 0.5625,
2
the value of the third approximation which is accurate to within 10−1 . •
1.5
1
y
0.5
α
0
−0.5
−1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
x
Choose the interval [2, 2.5] on which the function f (x) = x4 − 18 is continuous and
the function f (x) satisfies the sign property, that is
2.0 + 2.5
c1 = = 2.2500 and f (2.25) = 7.6289.
2
Since the function f (x) changes sign on [2.0, 2.25]. To continue, we squeeze from
right and use formula (2) again to get the following second approximate value of
the root α as:
2.0 + 2.25
c2 = = 2.1250 and f (2.1250) = 2.3909.
2
Then continue in the similar way, the third approximate value of the root α is
c3 = 2.0625 with f (2.0625) = 0.0957.
Note that the value of the function at each new approximate value is decreasing
which shows that the approximate values are coming closer to the root α. Now to
compute the error bound for the approximation we use the formula (3) and get
2.5 − 2.0
|α − c3 | ≤ = 0.0625,
23
which is the possible maximum error in our approximation and
1. Establish an interval a ≤ x ≤ b such that f (a) and f (b) are of opposite sign,
that is, f (a).f (b) < 0.
2. Choose an error tolerance ( > 0) value for the function.
3. Compute a new approximation for the root:
(an + bn )
cn = ; n = 1, 2, 3, . . . .
2
4. Check tolerance. If |f (cn )| ≤ , use cn , n ≥ 1 for desired root; otherwise
continue.
5. Check, if f (an )f (cn ) < 0, then set bn = cn ; otherwise set an = cn .
6. Go back to step 3, and repeat the process.
Summary