newtonRaphson: Rootfinding through Newton-Raphson or Secant.

Description Usage Arguments Details Value References See Also Examples

View source: R/newton.R

Description

Finding roots of univariate functions. (Newton never invented or used this method; it should be called more appropriately Simpson's method!)

Usage

1
2
newtonRaphson(fun, x0, dfun = NULL, maxiter = 500, tol = 1e-08, ...)
newton(fun, x0, dfun = NULL, maxiter = 500, tol = 1e-08, ...)

Arguments

fun

Function or its name as a string.

x0

starting value for newtonRaphson().

dfun

A function to compute the derivative of f. If NULL, a numeric derivative will be computed.

maxiter

maximum number of iterations; default 100.

tol

absolute tolerance; default eps^(1/2)

...

Additional arguments to be passed to f.

Details

Well known root finding algorithms for real, univariate, continuous functions.

Value

Return a list with components root, f.root, the function value at the found root, iter, the number of iterations done, and root, and the estimated precision estim.prec

The estimated precision is given as the difference to the last solution before stop; this may be misleading.

References

Quarteroni, A., R. Sacco, and F. Saleri (2007). Numerical Mathematics. Second Edition, Springer-Verlag, Berlin Heidelberg.

See Also

newtonHorner

Examples

1
2
3
4
# Legendre polynomial of degree 5
lp5 <- c(63, 0, -70, 0, 15, 0)/8
f <- function(x) polyval(lp5, x)
newton(f, 1.0)         # 0.9061798459 correct to 10 decimals in 5 iterations

Example output

$root
[1] 0.9061798

$f.root
[1] 6.661338e-16

$niter
[1] 6

$estim.prec
[1] 6.78706e-16

pracma documentation built on Dec. 11, 2021, 9:57 a.m.