op = par(pch = 19)
# default example
xx = newton.method()
xx$root # solution
# another function
xx = newton.method(function(x) exp(-x) * x, rg = c(0,
10), init = 2)
# not converge!
xx = newton.method(function(x) atan(x), rg = c(-5,
5), init = 1.5)
xx$root # Inf
# interaction: use your mouse to select the starting point
xx = newton.method(function(x) atan(x), rg = c(-2,
2), interact = TRUE)
# HTML animation pages
ani.start()
newton.method(function(x) exp(-x) * x, rg = c(0, 10),
init = 2, saveANI = TRUE, width = 600, height = 500)
ani.stop()
par(op)
Run the code above in your browser using DataLab