Description Usage Arguments Details Value Examples
View source: R/newtons_method.R
Newtons's method is an iterative root-finding method with quadratic convergence that requires the first derivative.
1 | newtons_method(f, fp, x0, tol = 1e-08)
|
f |
Univariate function to find root of |
fp |
First derivative of |
x0 |
A point close to the root of |
tol |
Tolerance for convergence. |
Newtons's method finds the root of a univariate function f with first derivative f' given an initial guess x_0 by the iteration:
x_{n + 1} = x_n - \frac{f(x_n)}{f'(x_n)}
.
The algorithm terminates when:
the algorithm exceeds 1000 iterations,
the value of f or f' is non-finite for an iterate (x_n),
the iterate (x_n) becomes non-finite, or
the algorithm converges and |f(x_{n}) - f(x_{n + 1})| < tol.
A root of f
near x0
. If the algorithm does not
converge, NA
is returned.
1 2 3 4 5 6 | newtons_method(cos,
function(x) -sin(x),
0.5)
newtons_method(function(x) x ^ 3 - x - 2,
function(x) 3 * x ^ 2 - 1,
1)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.