Learn R Programming

pracma (version 1.9.9)

newtonHorner: Newton's Root Finding Method for Polynomials.

Description

Finding roots of univariate polynomials.

Usage

newtonHorner(p, x0, maxiter = 50, tol = .Machine$double.eps^0.5)

Arguments

p
Numeric vector representing a polynomial.
x0
starting value for newtonHorner().
maxiter
maximum number of iterations; default 100.
tol
absolute tolerance; default eps^(1/2)

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.precThe estimated precision is given as the difference to the last solution before stop.

Details

Similar to newtonRahson, except that the computation of the derivative is done through the Horner scheme in parallel with computing the value of the polynomial. This makes the algorithm significantly faster.

References

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

See Also

newtonRaphson

Examples

Run this code
##  Example: x^3 - 6 x^2 + 11 x - 6  with roots 1, 2, 3
p <- c(1, -6, 11, -6)
x0 <- 0
while (length(p) > 1) {
    N <- newtonHorner(p, x0)
    if (!is.null(N$root)) {
        cat("x0 =", N$root, "\n")
        p <- N$deflate
    } else {
        break
    }
}
##  Try: p <- Poly(c(1:20))

Run the code above in your browser using DataLab