Newton–Raphson method, named after Isaac Newton and Joseph Raphson, is a method for finding successively better approximations to the roots (or zeroes) of a real-valued function.
The idea of the method is as follows: one starts with an initial guess which is reasonably close to the true root, then the function is approximated by its tangent line (which can be computed using the tools of calculus), and one computes the x-intercept of this tangent line (which is easily done with elementary algebra). This x-intercept will typically be a better approximation to the function’s root than the original guess, and the method can be iterated.
Newton’s method is an iterative method for root finding. That is, starting from some guess at the root, x0; one iteration of the algorithm produces a number x1; which is supposed to be closer to a root; guesses x2, x3, . . . xn follow identically. Newton’s method uses “linearization” to find an approximate root. The equation of the tangent line to the curve y = f (x) at the point x = xn is:
where f′ denotes the derivative of the function f.
The x-intercept of this line (the value of x such that y = 0) is then used as the next approximation to the root, xn + 1. In other words, setting y to zero and x to xn + 1 gives:
Solving for xn + 1 gives:
The example solved in this code is:
The code solve the given equation and show the answer with the number of iterations and accuracy (residual), and chart the root-value-convergence with the # of iterations.