newtonHorner(p, x0, maxiter = 50, tol = .Machine$double.eps^0.5)
eps^(1/2)
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.
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.newtonRaphson
## 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, "")
p <- N$deflate
} else {
break
}
}
## Try: p <- Poly(c(1:20))
Run the code above in your browser using DataLab