V-Lab @ ANDC

Secant-Method for finding roots of polynomials

Aim

For finding the roots of linear, quadratic and third degree polynomial using Secant-Method

Theory

What is Secant Method ?

Secant method is also a recursive method for finding the roots of the polynomials by successive approximation. Similar to the Regular-falsi method but in this method we don't need to check for f(x1)*f(x2)< 0 after every approximation. In this method, the neighbourhood roots are approximated by secant line or chord to the function f(x). Advantage of this method is that we don't need to differentiate the given function f(x), as we do in Newton-raphson method.

We can derive the formula for Secant method here:

   As we know the line equation:

y-y1 = m(x-x1)
Here m is the slope.
Applying (x0, f(x0)) and (x1, f(x1))
Y - f(x1) = [f(x0)-f(x1)/(x0-x1)] (x-x1)    ...eq(1)

As we're finding root of function f(x) so, Y=f(x)=0 in Equation (1) and the point where the secant line cut the x-axis is,
x= x1 - [(x0 - x1)/ (f(x0) - f(x1)]f(x1)

We use the above result for successive approximation for the root of function f(x). Let's say the first approximation is x=x2:
x2= x1 - [(x0 - x1)/ (f(x0)-f(x1))]f(x1)

Similarly, the second approximation would be x =x3:
x3= x2 - [(x1-x2)/ (f(x1)-f(x2))]f(x2)

And so on, till nth iteration,
xn+1= xn - [(xn-1 - xn) / (f(xn-1) - f(xn))]f(xn)

Procedure

  1. Enter the coefficients of the polynomial.
  2. Enter the values of interval
  3. Compute f(a) and f(b). [..... Here a=x0 and b=x1 ]
  4. Calculate x2= (x0*f(x1) - x1*f(x0))/ (f(x1)-f(x0))
  5. Assign x0=x1 and x1=x2
  6. Process will run until the desired iteration is reached.
  7. Terminate.

Python Code

                        
                            # Python program for implementation of Secant Method for algebraic equations 
                            # Taking input of the intervals for the guess
                            a= int(input("Enter the interval a: "))
                            b= int(input("Enter the interval b: "))
                            
                            # Function is defined here:
                            def secant(x):
                                return x**3-2*x-5
                            
                            # Root of the function is calculated here..
                            for i in range(11):
                                x0,x1=a,b
                                fx0,fx1=secant(x0),secant(x1)
                                x2= (x0*secant(x1)-x1*secant(x0))/(secant(x1)-secant(x0))
                                a,b=x1,x2
                            
                            # Root is displayed here.
                            print("Root of the given function is ",x2)

                        
                    

Observations

Take Observations from the method and tabulate it for the given intervals.

Plot a graph also. (function vs root).

Result

Hence we findout the roots for the given polynomial.

Advantage of the Secant method is that the speed of convergence of is faster than that of Bisection and Regula falsi method.
It uses the two most recent approximations of root to find new approximations, instead of using only those approximations which bound the interval to enclose root.