# Secant Method – Numerical Root Finding Method in MATLAB

Secant Method is also root finding method of non-linear equation in numerical method. This is an open method, therefore, it does not guaranteed for the convergence of the root. This method is also faster than bisection method and slower than Newton Raphson method. Like Regula Falsi method, Secant method is also require two initial guesses to start the solution and there is no need to find the derivative of the function. But only difference between the secant method and Regula Falsi method is that:

• Secant method is open and Regula Falsi method is closed.
• Secant method does not guaranteed to the convergence of the root while Regula Falsi method does.
• Regula Falsi method is bracketing method but Secant method is not.
• In method of False position, check the sign of the function at each iteration but in secant method is not.

The formula of Secant method is same as False position such that:

$x=\frac{af(b)-bf(a)}{b-a}$

At here, we write the code of Secant Method in MATLAB step by step. MATLAB is easy way to solve complicated problems that are not solve by hand or impossible to solve at page. MATLAB is develop for mathematics, therefore MATLAB is the abbreviation of MATrix LABoratory.

At here, we find the root of the function f(x) = x2-2 = 0 by using Secant Method with the help of MATLAB.

## MATLAB Code of Secant Method

clear all;
close all;
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


Scroll to Top