Root-Finding — Secant Method
March 4, 2014
1 Examples
Example-1: Use Secant method to find the root of the function
f (x) = cos x + 2 sin x + x2 to 5 decimal places. Don’t forget to ad-
just your calculator for “radians”.
Solution
A closed form solution for x does not exist so we must use a nu-
merical technique. The Secant method is given using the iterative
equation:
xn − xn−1
xn+1 = xn − f (xn ) , (1)
f (xn ) − f (xn−1 )
We will use x0 = 0 and x1 = −0.1 as our initial approximations
−0.1 and
substituting in (1), we have xn+1 = −0.1 − 0.80533 ∗ 0.80533−1 =
−0.51369. The continued iterations can be computed as shown in
Table 1 which shows a stop at iteration no. 5 since the error is x5 −x4 <
10−5 resulting in a root of x∗ = −0.65926, see Figure 1.
1
Table 1: Iterations for Example-1
Iteration no. xn−1 xn xn+1 using (1) f (xn+1 ) xn+1 − xn
1 x0 = 0 x1 = −0.1 -0.51369 0.15203 -0.41369
2 -0.1 -0.51369 -0.60996 0.04605 -0.09627
3 -0.51369 -0.60996 -0.65179 6.60859 × 10−3 -0.04183
4 -0.60996 -0.65179 -0.65880 4.08003 × 10−4 -0.00701
5 -0.65179 -0.65880 -0.65926 5.28942 × 10−6 < 10−5
1.2
1
f(x) = cos(x) + 2*sin(x) + x2
0.8
0.6
0.4
0.2 x∗ = −0.6593
−0.2
−1 −0.8 −0.6 −0.4 −0.2 0
x
Figure 1: A plot of f (x) = cos x + 2 sin x + x2 using MATLAB.
Example-2: Use Secant method to find the root of the function
f (x) = x3 − 4 to 5 decimal places.
Solution
Since the Secant method is given using the iterative equation in (1).
Starting with an initial value x0 = 1 and x1 = 1.5, using (1) we can
2
h i
1.5−1
compute x2 = 1.5 − (−0.625) = 1.63158. The continued
−0.625−(−3)
iterations can be computed as shown in Table 2 which shows a stop at
iteration no. 5 since the error is x5 − x4 < 10−5 resulting in a root of
x∗ = 1.58740, see Figure 2.
Table 2: Iterations for Example-2
Iteration no. xn−1 xn xn+1 using (1) f (xn+1 ) xn+1 − xn
1 x0 = 1 x1 = 1.5 1.63158 0.34335 0.13158
2 1.5 1.63158 1.58493 -0.01865 -0.04665
3 1.63158 1.58493 1.58733 -0.00054 0.0024
4 1.58493 1.58733 1.58740 −7.95238 × 10−6 0.00007
5 1.58733 1.58740 1.58740 −7.95238 × 10−6 < 10−5
60
50
40
f(x) = x3 − 4
30
20
10
x∗= 1.5874
−10
0 0.5 1 1.5 2 2.5 3 3.5 4
x
Figure 2: A plot of f (x) = x3 − 4 using MATLAB.
Example-3: Use Secant method to find the root of the function
f (x) = 3x + sin x − ex to 5 decimal places. Use x0 = 0 and x1 = 1.
3
Solution
h i
1−0
Using (1) we can compute x2 = 1−(1.12319) = 0.47099. 1.12319−(−1)
The continued iterations can be computed as shown in Table 3 which
shows a stop at iteration no. 6 since the error is x6 −x5 < 10−5 resulting
in a root of x∗ = 0.36042, see Figure 3.
Table 3: Iterations for Example-3
Iteration no. xn−1 xn xn+1 using (1) f (xn+1 ) xn+1 − xn
1 x0 = 0 x1 = 1 0.47099 0.26516 -0.52901
2 1 0.47099 0.30751 -0.13482 -0.16348
3 0.47099 0.30751 0.36261 5.47043 × 10−3 0.0551
4 0.30751 0.36261 0.36046 9.58108 × 100−5 -0.00215
5 0.36261 0.36046 0.36042 −4.26049 × 10−6 -0.00004
6 0.36046 0.36042 0.36042 −4.26049 × 10−6 < 10−5
1
∗
x = 0.3604
f(x) = 3x + sin(x) − ex
−1
−2
−3
−4
−5
−1 −0.5 0 0.5 1 1.5 2
x
Figure 3: A plot of f (x) = 3x + sin x − ex using MATLAB.
4
Example-4: Solve the equation exp(−x) = 3 log(x) to 5 decimal
places using secant method, assuming initial guess x0 = 1 and x1 = 2.
Solution
Let f (x) = exp(−x) − 3 log(x), to solve the given, it is now equiv-
alent to findh the root of f (x).
i Using (1) we can compute x2 = 2 −
2−1
(−0.76775) −0.76775−(0.36788) = 1.32394. The continued iterations can
be computed as shown in Table 4 which shows a stop at iteration no.
5 since the error is x5 − x4 < 10−5 resulting in a root of x∗ = 1.24682,
see Figure 4.
Table 4: Iterations for Example-4
Iteration no. xn−1 xn xn+1 using (1) f (xn+1 ) xn+1 − xn
1 x0 = 1 x1 = 2 1.32394 -0.09952 -0.67606
2 2 1.32394 1.22325 0.03173 -0.10069
−3
3 1.32394 1.22325 1.24759 −1.01955 × 10 0.02434
−6
4 1.22325 1.24759 1.24683 −7.27178 × 10 -0.00076
−6
5 1.24759 1.24683 1.24682 6.05199 × 10 < 10−5
5
0.6
0.4
f(x) = exp(−x) − 3log(x)
0.2 x∗ = 1.24682
−0.2
−0.4
−0.6
−0.8
1 1.2 1.4 1.6 1.8 2
x
Figure 4: A plot of f (x) = exp(−x) − 3 log(x) using MATLAB.
2 Algorithm
Secant Method Algorithm
Given equation f (x) = 0, a predefined error , and a maximum no. of iterations N
Let the initial guesses be x0 and x1
Do
xn − xn−1
xn+1 = xn − f (xn ) , n = 1, 2, · · ·
f (xn ) − f (xn−1 )
while the error xn+1 − xn < or n = N
3 Exercises
e−2x −1
1. Find the root of x2 = x . [x0 = 1, x1 = 2]
6
2. Solve the equation e(x −1) + 10 sin 2x − 5 = 0. [x0 = 0, x1 = 1]
2
3. Find the root of f (x) = ex − 3x2 . [x0 = 0, x1 = 1]
4. Find the root of f (x) = tan x − x − 1. [x0 = 0, x1 = 1]
5. Solve the equation sin 2x = exp(x − 1). [x0 = 0, x1 = 1]