You are on page 1of 9

Ministry of Higher Education

and Scientific Research


University of Halabja
College of Science
Computer Science Department
Second stage-First semester

Secant Method

A report in

Numerical Analysis

Prepared by
Mhamad Jabar Amez Amanj
Mhamad Talib Shvan Fuad
Akar Najmadin

Supervised by
Bawar Mohammed Faraj
10 December 2021Table of Contents
Table of Contents.........................................................................................................................................i
Introduction.................................................................................................................................................1
Algorithm of the method.............................................................................................................................2
Example.......................................................................................................................................................3
MATLAB Code of Secant Method................................................................................................................4
Advantages of secant method:....................................................................................................................5
Disadvantages of secant method:...............................................................................................................5
Conclusion...................................................................................................................................................6
References...................................................................................................................................................7

i
Introduction
Secant method is also a recursive method for finding the root for the
polynomials by successive approximation. It’s similar to the Regular-
falsi method but here we don’t need to check f(x1)f(x2)<0 again and
again after every approximation. In this method, the neighbourhoods
roots are approximated by secant line or chord to the function f(x). It’s
also advantageous of this method that we don’t need to differentiate
the given function f(x), as we do in Newton-raphson method. 

1
Algorithm of the method
Step 1: Choose two starting points x0 and x1.
Step 2: Let  

                   

Step 3: if |x2-x1|<e  then let root = x2, else x0 = x1 ; x1 = x2 ; go to step 2.

Step 4: End.

2
Example : 
A real root of the equation f(x) = x3 – 5x + 1 = 0 lies in the interval (0, 1). Perform
four iterations of the secant method. 

Solution – 
We have, x0 = 0, x1 = 1, f(x0) = 1, f(x1) = – 3 
x2 = x1 – [( x0 – x1) / (f(x0) – f(x1))]f(x1) 
= 1 – [ (0 – 1) / ((1-(-3))](-3) 
= 0.25.
 
f(x2) = – 0.234375 
The second approximation is, 
x3 = x2 – [( x1 – x2) / (f(x1) – f(x2))]f(x2) 
=(– 0.234375) – [(1 – 0.25)/(–3 – (– 0.234375))](– 0.234375) 
= 0.186441 
 
f(x3)= 0.074276
The third approximation is, 
x4 = x3 – [( x2 – x3) / (f(x2) – f(x3))]f(x3) 
= 0.186441 – [( 0.25 – 0.186441) / ( – 0.234375) – (0.074276) ](– 0.234375) 
= 0.201736.
 
f(x4) = – 0.000470 
The fourth approximation is, 
x5 = x4 – [( x3 – x4) / (f(x3) – f(x4))]f(x4) 
= 0.201736 – [( 0.186441 – 0.201736) / (0.074276 – (– 0.000470)](– 0.000470) 
= 0.201640

3
MATLAB Code of Secant Method
clc;
f=inline('x^2-2');
x0=input('Enter x0=');
x1=input('Enter x1=');
tol=input('Enter tolarance=');
itr=input('Enter number of iteration=');
p=0;
for i=1:itr
x2=(x0*f(x1)-x1*f(x0))/(f(x1)-f(x0));
if abs(x2-x1)<tol
p=1;
k=i;
break;
else
x0=x1;
x1=x2;
end
end
if p==1
fprintf('Solution is %f at iterations %i',x2,k)
else
fprintf('No convergent solution exist in the given number iteration')
end

4
Advantages of secant method:
1. It converges at faster than a linear rate, so that it is more rapidly
convergent than the bisection method.

2. It does not require use of the derivative of the function,


something that is not available in a number of applications.

3. It requires only one function evaluation per iteration, as


compared with Newton’s method which requires two.

Disadvantages of secant method:


1. It may not converge.

2. There is no guaranteed error bound for the computed iterates.

3. It is likely to have difficulty if f 0 (α) = 0. This means the x-axis


is tangent to the graph of y = f (x) at x = α. 4. Newton’s method
generalizes more easily to new methods for solving simultaneous
systems of nonlinear equations

5
Conclusion

The secant method is a popular and powerful algorithm for


finding the root of an equation. The method has several
advantages over the Newton-Raphson approach as the secant
method does not require the function derivative and is less prone
to erratic swings between iterations. However, the secant method
struggles compared to Newton-Raphson regarding iterations
required. Most implementations of root-finding algorithms in the
most commonly used statistical packages use a combination of
Newton-Raphson and the secant method to find the root of an
equation.

6
References

https://www.codesansar.com/numerical-methods/secant-method-algorithm.htm
http://hplgit.github.io/Programming-for-Computations/pub/p4c/._p4c-bootstrap-
Matlab027.html
Secant Method of Numerical analysis - GeeksforGeeks
Secant Method - Numeric Method (google.com)

You might also like