The Newton-Raphson method is an iterative technique to find the root of a function. The formula for the algorithm is:
main.m33 chars2 lines
Where x(i)
is the current guess for the root, f(x(i))
is the value of the function at that guess and f'(x(i))
is the first derivative of the function at that guess. This process is repeated until a sufficiently accurate estimate of the root is obtained.
Here is an example implementation of the Newton-Raphson method in MATLAB:
main.m764 chars30 lines
In this example, we define the function f
and its first derivative df
, set an initial guess for the root x0
, and a tolerance level for convergence tol
. We then loop through the Newton-Raphson formula until the error between the current and previous estimates of the root is less than the tolerance level. Lastly, we output the final estimate of the root.
gistlibby LogSnag