View source: R/newton-raphson.R
newton_raphson | R Documentation |
The Newton-Raphson Method is an iterative algorithm for calculating the root
(x-intercept) of an arbitrary function f(x)
.
newton_raphson(init, tol = 1e-04)
init |
The initial |
tol |
The tolerance for the error in the root. Used to stop the
algorithm once the root estimate no longer changes by this much in |
The idea is to start with an initial guess which is reasonably close to the true root, then to approximate the function by its tangent line using calculus, and finally to compute the x-intercept of this tangent line by elementary algebra. This x-intercept will typically be a better approximation to the original function's root than the first guess, and the method can be iterated until some threshold tolerance is crossed.
Newton-Raphson Method for calculating next x1
has the equation:
x1 = x0 - f(x0) / f'(x0)
The function generates a ggplot2 of the algorithm, as well as a list containing:
x_traj |
The iterative "guesses" for the function root. |
niter |
The number of iterations required to find the root. |
root |
The estimate of the root (x-intercept). |
https://en.wikipedia.org/wiki/Newton%27s_method
newton_raphson(3) newton_raphson(-3)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.