This function provides an illustration of the iterations in Newton's method.
newton.method(
FUN = function(x) x^2 - 4,
init = 10,
rg = c(-1, 10),
tol = 0.001,
interact = FALSE,
col.lp = c("blue", "red", "red"),
main,
xlab,
ylab,
...
)
the function in the equation to solve (univariate), which has to be defined without braces like the default one (otherwise the derivative cannot be computed)
the starting point
the range for plotting the curve
the desired accuracy (convergence tolerance)
logical; whether choose the starting point by cliking on the curve (for 1 time) directly?
a vector of length 3 specifying the colors of: vertical lines, tangent lines and points
titles of the plot; there are default values for them
(depending on the form of the function FUN
)
other arguments passed to curve
A list containing
the root found by the algorithm
the value of FUN(root)
number of
iterations; if it is equal to ani.options('nmax')
, it's quite likely
that the root is not reliable because the maximum number of iterations has
been reached
Newton's method (also known as the Newton-Raphson method or the Newton-Fourier method) is an efficient algorithm for finding approximations to the zeros (or roots) of a real-valued function f(x).
The iteration goes on in this way:
$$x_{k + 1} = x_{k} - \frac{FUN(x_{k})}{FUN'(x_{k})}$$
From the starting value \(x_0\), vertical lines and points are plotted to show the location of the sequence of iteration values \(x_1, x_2, \ldots\); tangent lines are drawn to illustrate the relationship between successive iterations; the iteration values are in the right margin of the plot.
Examples at https://yihui.org/animation/example/newton-method/
For more information about Newton's method, please see https://en.wikipedia.org/wiki/Newton's_method