-
-
Notifications
You must be signed in to change notification settings - Fork 21
Plotting Newton's Method and Halley's Method
The video for finding and Convergence for Newton-type methods can be found here https://youtu.be/zyXRo8Qjj0A. The video for Halley's Method can be found here https://youtu.be/3WiVGSy_084. Example code is given in the PlotNewtonHalley.r file, written in R. It computes and plots iterations of Newton's and Halley's Method and finds the convergence interval.
You can run the program online via CodingGround. To run the program locally have R installed (R Project) then type Rscript PlotNewtonHalley.r
in the terminal in the directory where PlotNewtonHalley.r is saved. The plots will be saved into external files in the same directory. If you'd rather not use the terminal use an IDE like Geany to open and run the program (you might need to change the build tools execute command to Rscript %f"
). You can also use RGui to load the code. The easiest way is to save PlotNewtonHalley.r in the working directory of RGui which you can see by typing getwd()
or you can change with setwd("path to folder")
or by going to 'File' > 'Change dir...' and using the dialog options to change it. Then type load("PlotNewtonHalley.r")
which will run the program and load the functions into the current session. You'll be able to then call plotNewton()
and computeInterval()
with whatever parameter values you want.
To plot a different function edit the following variables and functions:
name <- "arctan(x)"
f <- function(x) atan(x)
fp <- function(x) 1.0 / (x^2 + 1)
fp2 <- function(x) (-2*x) / ((x^2+1)^2)
name <- "x^2-x-1"
f <- function(x) x^2-x-1
fp <- function(x) 2*x-1
fp2 <- function(x) 2
name <- "x^3-x^2-x-1"
f <- function(x) x^3-x^2-x-1
fp <- function(x) 3*x^2-2*x-1
fp2 <- function(x) 6*x-2
There was an error in one example used in the Halley's Method video. This has been fixed.