You are on page 1of 18

Numerical method of solving algebraic and non-

algebraic equations

Consider the function: 𝑓(𝑥) = 𝑎 𝑥 2 + 𝑏𝑥 + 𝑐 = 0

Roots of this function represent the values of 𝑥 that make 𝑓(𝑥) equal to zero.

𝑓(𝑥) = 0

−𝑏±√𝑏2 −4𝑎𝑐
Roots of 𝑓(𝑥): 𝑥1,2 =
2𝑎

There are many cases where roots can not be determined easily. In some cases,
roots can not be determined analytically. e.g.,

𝑓(𝑥) = 𝑒 −𝑥 − 𝑥 − 5

We can use numerical methods to find the roots approximately.

If a function 𝑓(𝑥 ) is continuous on the interval [𝑎, 𝑏]


and sign of 𝑓 (𝑎) ≠ sign of 𝑓(𝑏), then

There is a value 𝑐 ∈ [𝑎, 𝑏] such that: 𝑓 (𝑐 ) = 0

i.e., there is a root c in the interval [𝑎, 𝑏]

- 133 -
1- Graphical Methods

A simple method for obtaining an estimate of the root of the equation 𝑓(𝑥) = 0
is to make a plot of the function and observe where it crosses the 𝑥 axis. This
point, which represents the 𝑥 value for which 𝑓(𝑥) = 0, provides a rough
approximation of the root.

Finding real roots graphically:

The real number 𝑥 = 𝑎 is a root of the polynomial 𝑓(𝑥) if and only if

𝑓(𝑎) = 0

When we see a graph of a polynomial, real roots are 𝑥 -intercepts of the graph
of 𝑓(𝑥).

- 134 -
The graph of the polynomial above intersects the 𝑥 -axis at (or close to) 𝑥 = −2,
at (or close to) 𝑥 = 0 and at (or close to) 𝑥 = 1.

Example 1.1

Find approximations to the real roots of the polynomial 2𝑥 3 − 𝑥 2 + 2𝑥 − 1 = 0.

Solution

∵ 𝑓(0) = 0 − 1 = −1 < 0

𝑓(1) = 2 − 1 + 2 − 1 = 2 > 0

∴ The root is between [0,1]

𝑥 𝑓(𝑥) = 2𝑥 3 − 𝑥 2 + 2𝑥 − 1
0 −1
0.2 −0.624
0.4 −0.232
0.6 0.272
0.8 0.984
1 2

- 135 -
2.0

1.5

1.0

0.5

0.0
0.5

0.5

1.0
0.0 0.2 0.4 0.6 0.8 1.0

∴ The root is 0.5

Example 1.2

Find the root of 𝑥 − 𝑒 −𝑥 = 0

Solution

Exact = 0.5671432904

∵ 𝑓(0) = 0 − 1 = −1 < 0

𝑓(1) = 1 − 𝑒 −1 = 0.63212 > 0

∴ The root is between [0,1]

𝑥 𝑓(𝑥) = 𝑥 − 𝑒 −𝑥
0 −1
0.2 −0.61873
0.4 −0.27032
0.6 0.05119
0.8 0.35067
1 0.63212

- 136 -
0.5

0.0

0.56

0.5

1.0
0.0 0.2 0.4 0.6 0.8 1.0

∴ 𝑥 = 0.56

Example 1.3

Find the root of 𝑓(𝑥) = 3𝑥 + sin 𝑥 − 𝑒 𝑥 = 0

Solution
Exact = 0.360421703

∵ 𝑓(0) = 0 − 1 = −1 < 0

𝑓(1) = 1.1232 > 0

∴ The root is between [0,1]

𝑥 𝑓(𝑥) = 𝑥 − 𝑒 −𝑥
0 −1
0.2 −0.4227
0.4 −0.0976
0.6 0.5425
0.8 0.8918
1 1.1232

- 137 -
1.0

0.5

0.0

0.36

0.5

1.0
0.0 0.2 0.4 0.6 0.8 1.0

∴ 𝑥 = 0.36

2- Two-Curve Graphical Methods

Another alternative is to devide the function into parts, e.g.

𝑓(𝑥) = 𝑒 𝑥 − 𝑥 − 5

𝑓1 (𝑥) = 𝑒 𝑥 , 𝑓2 (𝑥) = 𝑥 + 5

𝑓1 (𝑥) = 𝑓2 (𝑥)

Example 2.1
Find approximations to the real roots of the polynomial 2𝑥 3 − 𝑥 2 + 2𝑥 − 1 = 0.

Solution

∵ 𝑓(𝑥) = 2𝑥 3 − 𝑥 2 + 2𝑥 − 1

∴ 𝑓1 (𝑥) = 2𝑥 3 − 𝑥 2 , 𝑓2 (𝑥) = 1 − 2𝑥
- 138 -
𝑥 𝑓1 (𝑥) = 2𝑥 3 − 𝑥 2 𝑓2 (𝑥) = 1 − 2𝑥
0 0 0
0.2 −0.024 0.6
0.4 −0.032 0.2
0.6 0.072 −0.2
0.8 0.384 −0.6
1 1 −1

1.0

0.5

0.5
0.0

0.5

1.0
0.0 0.2 0.4 0.6 0.8 1.0

Example 2.2

Find the root of 𝑥 − 𝑒 −𝑥 = 0

Solution

∵ 𝑓(𝑥) = 𝑥 − 𝑒 −𝑥

∴ 𝑓1 (𝑥) = 𝑒 −𝑥 , 𝑓2 (𝑥) = 𝑥

- 139 -
𝑥 𝑓1 (𝑥) = 𝑒 −𝑥 𝑓2 (𝑥) = 𝑥
0 1 0
0.2 0.8197 0.2
0.4 0.6703 0.4
0.6 0.5488 0.6
0.8 0.4493 0.8
1 0.3679 1

1.0

0.8

0.6
0.56

0.4

0.2

0.0
0.0 0.2 0.4 0.6 0.8 1.0

Example 2.3
Find the root of 𝑓(𝑥) = 3𝑥 + sin 𝑥 − 𝑒 𝑥 = 0

Solution

∵ 𝑓(𝑥) = 3𝑥 + sin 𝑥 − 𝑒 𝑥

∴ 𝑓1 (𝑥) = sin 𝑥 , 𝑓2 (𝑥) = 𝑒 𝑥 − 3𝑥

- 140 -
𝑥 𝑓1 (𝑥) = sin 𝑥 𝑓2 (𝑥) = 𝑒 𝑥 − 3𝑥
0 0 1
0.2 0.1987 0.6214
0.4 0.3894 0.2918
0.6 0.5646 0.0221
0.8 0.7174 −0.1745
1 0.8415 −0.2817

1.0

0.8

0.6

0.4 0.36

0.2

0.0

0.2

0.0 0.2 0.4 0.6 0.8 1.0

3- Bisection Methods

Step 1: Choose lower 𝑥𝑙 and upper 𝑥𝑢 guesses for the root such that the function
changes sign over the interval. This can be checked by ensuring that
𝑓(𝑥𝑙 ) 𝑓(𝑥𝑢 ) < 0.

Step 2: An estimate of the root 𝑥𝑟 is determined by

𝑥𝑙 +𝑥𝑢
𝑥𝑟 =
2

Step 3: Make the following evaluations to determine in which subinterval the


root lies:

- 141 -
i. If 𝑓(𝑥𝑙 ) 𝑓(𝑥𝑟 ) < 0, the root lies in the lower subinterval. Therefore, set
𝑥𝑢 = 𝑥𝑙 and return to step 2.
ii. If 𝑓(𝑥𝑙 ) 𝑓(𝑥𝑟 ) > 0, the root lies in the upper subinterval. Therefore, set
𝑥𝑙 = 𝑥𝑟 and return to step 2.
iii. If 𝑓(𝑥𝑙 ) 𝑓(𝑥𝑟 ) = 0, the root equals 𝑥𝑟 , terminate the computation.

Example 3.1

Use bisection to solve 2𝑥 3 − 𝑥 2 + 2𝑥 − 1 = 0.

Solution

∵ 𝑓(0) = 0 − 1 = −1 < 0

𝑓(1) = 2 − 1 + 2 − 1 = 2 > 0

∴ The root is between [0,1]

Iteration 1

Let

𝑥𝑙 = 0 𝑥𝑢 = 1

𝑓(𝑥𝑙 ) = −1 𝑓(𝑥𝑢 ) = 2
𝑥𝑙 +𝑥𝑢 0+1
∴ 𝑥𝑟 = = = 0.5
2 2

- 142 -
∵ 𝑓(𝑥𝑟 ) = 2(0.5)3 − (0.5)2 + 2(0.5) − 1 = 0

∵ 𝑓(𝑥𝑙 ) 𝑓(𝑥𝑟 ) = (−1)(0) = 0

∴ The root is 𝑥𝑟 = 0.5

Example 3.2
Use bisection to solve 𝑥 − 𝑒 −𝑥 = 0.

Solution

∵ 𝑓(0) = 0 − 1 = −1 < 0

𝑓(1) = 1 − 𝑒 −1 = 0.63212 > 0

∴ The root is between [0,1]

Iteration 1

𝑥𝑙 = 0 𝑥𝑢 = 1

𝑓(𝑥𝑙 ) = −1 𝑓(𝑥𝑢 ) = 0.63212


𝑥𝑙 +𝑥𝑢 0+1
∴ 𝑥𝑟 = = = 0.5
2 2

∵ 𝑓(𝑥𝑟 ) = 0.5 − 𝑒 −0.5 = −0.10653

∵ 𝑓(𝑥𝑙 ) 𝑓(𝑥𝑟 ) = (−1)(−0.10653) = 0.10653 > 0

∴ Set 𝑥𝑙 = 𝑥𝑟

Iteration 2

𝑥𝑙 = 𝑥𝑟 = 0.5 𝑥𝑢 = 1

𝑓(𝑥𝑙 ) = −0.10653 𝑓(𝑥𝑢 ) = 0.63212


𝑥𝑙 +𝑥𝑢 0.5+1
∴ 𝑥𝑟 = = = 0.75
2 2

- 143 -
Iteration 𝑥𝐿 𝑥U 𝑥𝑟 𝑓(𝑥𝑟 )
1 0 1 0.5 −0.10653
2 0.5 1 0.75 0.27763
3 0.5 0.75 0.625 0.08974
4 0.5 0.625 0.5625 −0.00728
5 0.5625 0.625 0.59375 0.0415
6 0.5625 0.59375 0.578125 0.01718

Example 3.3

Use bisection to solve 3𝑥 + sin 𝑥 − 𝑒 𝑥 = 0.

Solution

∵ 𝑓(0) = 0 − 1 = −1 < 0

𝑓(1) = 1.1232 > 0

∴ The root is between [0,1]

∴ 𝑥𝑙 = 0 𝑥𝑢 = 1

𝑓(𝑥𝑙 ) = −1 𝑓(𝑥𝑢 ) = 1.1232


𝑥𝑙 +𝑥𝑢 0+1
∴ 𝑥𝑟 = = = 0.5
2 2

Iteration 𝑥𝐿 𝑥U 𝑥𝑟 𝑓(𝑥𝑟 )
1 0 1 0.5 0.3307
2 0 0.5 0.25 −0.2866
3 0.25 0. 5 0.375 0.0363
4 0.25 0.375 0.4375 0.1873
5 0.25 0.4375 0.46875 0.2600

- 144 -
4- Simple Fixed Point Iteration

Step 1: Rearrange the function 𝑓(𝑥) = 0 so that 𝑥 is on the left-hand side of the
equation: 𝑥 = 𝑔(𝑥).

Step 2: Use the new function 𝑔(𝑥) to predict a new value of 𝑥 - that is

𝑥𝑖+1 = 𝑔(𝑥𝑖 )

Step 3: The approximate error is given by:

𝑥𝑟𝑛𝑒𝑤 −𝑥𝑟𝑜𝑙𝑑
𝜀𝑎 = | | × 100
𝑥𝑟𝑛𝑒𝑤

Or

𝑥𝑖+1 −𝑥𝑖
𝜀𝑎 = | | × 100
𝑥𝑖+1

Example 4.1

Use simple fixed-point iteration to locate the root of 𝑓(𝑥) = 2𝑥 3 − 𝑥 2 + 2𝑥 −


1.

Solution
−2𝑥 3 +𝑥 2 +1
∵ 2𝑥 3 − 𝑥 2 + 2𝑥 − 1 = 0 𝑥=
2

−2𝑥𝑖 3 +𝑥𝑖 2 +1
∴ 𝑥𝑖 =
2

𝑖 𝑥𝑖
0 0
1 0.5

- 145 -
Example 4.2

Use simple fixed-point iteration to locate the root of 𝑓(𝑥) = 𝑥 − 𝑒 −𝑥 .

Solution

∵ 𝑥 − 𝑒 −𝑥 = 0 𝑥 = 𝑒 −𝑥

∴ 𝑥𝑖+1 = 𝑒 −𝑥𝑖

Starting with an initial guess of 𝑥0 = 0

𝑖 𝑥𝑖
0 0
1 1
2 0.36788
3 0.69220
4 0.50047
5 0.60624
6 0.54540
7 0.57961
8 0.56012
9 0.57114
10 0.56488

∴ 𝑥 = 0.56488

Example 4.3
Use simple fixed-point iteration to locate the root of 𝑓(𝑥) = 3𝑥 + sin 𝑥 − 𝑒 𝑥 .

Solution

- 146 -
𝑒 𝑥 −sin 𝑥
∵ 3𝑥 + sin 𝑥 − 𝑒 𝑥 = 0 𝑥=
3

𝑒 𝑥𝑖 −sin 𝑥𝑖
∴ 𝑥𝑖+1 =
3

Starting with an initial guess of 𝑥0 = 0

𝑖 𝑥𝑖
0 0
1 0.33333
2 0.35614
3 0.35972
4 0.36030
5 0.36040
6 0.360418

∴ 𝑥 = 0.360418

5- The Newton-Raphson Method

- 147 -
Figure 1: Graphical depiction of the Newton-Raphson method. A tangent to the
function of 𝑥𝑖 [that is 𝑓 ′ (𝑥𝑖 ) ] is extrapolated down to the x axis to provide an
estimate of the root at 𝑥𝑖+1 .

Perhaps the most widely used of all root-locating formulas is the Newton-
Raphson equation (Fig. 1). If the initial guess at the root is xi, a tangent can be
extended from the point [𝑥𝑖 , 𝑓(𝑥𝑖 )]. The point where this tangent crosses the 𝑥
axis usually represents an improved estimate of the root.

The Newton-Raphson method can be derived on the basis of this geometrical


interpretation (an alternative method based on the Taylor series is described in
Box 6.2). As in Fig. 1, the first derivative at x is equivalent to the slope:

𝑓(𝑥𝑖 )−0
𝑓 ′ (𝑥𝑖 ) =
𝑥𝑖 −𝑥𝑖+1

which can be rearranged to yield

𝑓(𝑥 )
𝑥𝑖+1 = 𝑥𝑖 − 𝑓′ (𝑥𝑖 )
𝑖

which is called the Newton-Raphson formula.

Example 5.1

Use the Newton-Raphson method to estimate the root of 𝑓(𝑥) = 2𝑥 3 − 𝑥 2 +


2𝑥 − 1 = 0, employing an initial guess of 𝑥0 = 0.

Solution

∵ 𝑓(𝑥) = 2𝑥 3 − 𝑥 2 + 2𝑥 − 1

∴ 𝑓 ′ (𝑥) = 6𝑥 2 − 2𝑥 + 2

- 148 -
𝑓(𝑥𝑖 )
∵ 𝑥𝑖+1 = 𝑥𝑖 −
𝑓′ (𝑥𝑖 )

2 𝑥𝑖3 −𝑥𝑖2 +2𝑥𝑖 −1


= 𝑥𝑖 −
6𝑥𝑖2 −2𝑥𝑖 +2

Starting with an initial guess of 𝑥0 = 0, this iterative equation can be applied to


compute
𝑖 𝑥𝑖
0 0
1 0.5

Example 5.2

Use the Newton-Raphson method to estimate the root of 𝑓(𝑥) = 𝑥 − 𝑒 −𝑥 = 0,


employing an initial guess of 𝑥0 = 0.

Solution

∵ 𝑓(𝑥) = 𝑥 − 𝑒 −𝑥

∴ 𝑓 ′ (𝑥) = 1 + 𝑒 −𝑥

𝑓(𝑥𝑖 ) 𝑥𝑖 − 𝑒 −𝑥𝑖
∵ 𝑥𝑖+1 = 𝑥𝑖 − = 𝑥𝑖 −
𝑓′ (𝑥𝑖 ) 1+𝑒 −𝑥𝑖

Starting with an initial guess of 𝑥0 = 0, this iterative equation can be applied to


compute

- 149 -
Where,

Thus, the approach rapidly converges on the true root. Notice that the true
percent relative error at each iteration decreases much faster than it does in
simple fixed-point iteration.

Example 5.3
Use the Newton-Raphson method to estimate the root of 𝑓(𝑥) = 3𝑥 + sin 𝑥 −
𝑒 𝑥 = 0, employing an initial guess of 𝑥0 = 0.

Solution

∵ 𝑓(𝑥) = 3𝑥 + sin 𝑥 − 𝑒 𝑥

∴ 𝑓 ′ (𝑥) = 3 + cos 𝑥 − 𝑒 𝑥

𝑓(𝑥𝑖 ) 3𝑥𝑖 +sin 𝑥𝑖 − 𝑒 𝑥𝑖


∵ 𝑥𝑖+1 = 𝑥𝑖 − = 𝑥𝑖 −
𝑓′ (𝑥𝑖 ) 3+cos 𝑥𝑖 −𝑒 𝑥𝑖

- 150 -

You might also like