newton_raphson {elliptic} | R Documentation |
Newton Raphson iteration to find roots of equations
Description
Newton-Raphson iteration to find roots of equations with the emphasis on complex functions
Usage
newton_raphson(initial, f, fdash, maxiter, give=TRUE, tol = .Machine$double.eps)
Arguments
initial |
Starting guess |
f |
Function for which |
fdash |
Derivative of function (note: Cauchy-Riemann conditions assumed) |
maxiter |
Maximum number of iterations attempted |
give |
Boolean, with default |
tol |
Tolerance: iteration stops if |
Details
Bog-standard implementation of the Newton-Raphson algorithm
Value
If give
is FALSE
,
returns z
with |f(z)|<tol
; if TRUE
, returns a list
with elements root
(the estimated root), f.root
(the
function evaluated at the estimated root; should have small modulus),
and iter
, the number of iterations required.
Note
Previous versions of this function used the misspelling “Rapheson”.
Author(s)
Robin K. S. Hankin
Examples
# Find the two square roots of 2+i:
f <- function(z){z^2-(2+1i)}
fdash <- function(z){2*z}
newton_raphson( 1.4+0.3i,f,fdash,maxiter=10)
newton_raphson(-1.4-0.3i,f,fdash,maxiter=10)
# Now find the three cube roots of unity:
g <- function(z){z^3-1}
gdash <- function(z){3*z^2}
newton_raphson(-0.5+1i,g,gdash,maxiter=10)
newton_raphson(-0.5-1i,g,gdash,maxiter=10)
newton_raphson(+0.5+0i,g,gdash,maxiter=10)