What is the Newton-Raphson method?

There are several graphical methods to approximate the roots of an equation. We can use these methods when finding the solution to an equation is difficult. Hence, we try to get as close to the actual root as we can.
The two most common types are:

  1. Bracketing methods

  2. Open methods

Bracketing methods

Bracketing methods are a type of graphical method where an interval is selected in which the root of the equation might lie.

These methods decrease the size of the interval until the actual root is found or the interval becomes very small.

The Bisection method and False-Position method fall under the category of Bracketing Methods.

Open methods

Open methods are a type of graphical method where a formula is used to project the current approximate to the real root in an iterative fashion.

These methods might converge or diverge depending on the initial guess.

Newton-Raphson method and Secant method fall under the category of Open methods.

Newton-Raphson methods

Newton-Raphson method uses the tangent to estimate a better root. We use an iterative method to get closer to the actual root. However, this sometimes diverges instead of converging. This means that the algorithm might take us away from the actual root with each iteration.

The Newton Raphson method can be derived from the equation of a derivative.

This equation can be rearranged to form the following equation known as the Newton-Raphson method:

xi: The initial guess or the starting point

x(i+1): The next point or the improved guess is found when the tangent to the curve f(x) at point xi meets the x-axis.

f’(x): The derivative of the curve f(x)

A tangent is drawn at the point xi. The point where the tangent crosses the x-axis is regarded as the point x(i+1). x(i+1) is the better guess. The next tangent will now be drawn at the point x(i+1).

Code

import math
def func(x):
func = 0.95*(pow(x,3))-5.9*(pow(x,2))+10.9*x-6 #Example equation
return func
def dydx(x):
dydx = 2.85*(pow(x,2)) - (11.8*x) + 10.9 #Equation of the derivative= f'(x)
return dydx
def newton_raphson():
ea = 100 #Absolute Error
xi = 3 #Initial Guess
i=1
while ea > 0.1: #This loop will run until the absolute error becomes less than 0.1
xr = xi - (func(xi) / dydx(xi)) #This is the Newton Raphson method which is mentioned above.
ea = abs((xr - xi) / xr) * 100 #Absolute error
xi = xr #The guess is updated with every iteration
print("Iteration",i)
print("Absolute Error", ea)
print("Root",xr)
i=i+1
def main():
newton_raphson()
main()

Free Resources