Learn R Programming

elliptic (version 0.4-13)

newton.rapheson: Newton Rapheson iteration to find roots of equations

Description

Newton Rapheson iteration to find roots of equations with the emphasis on complex functions

Usage

newton.rapheson(initial, f, fdash, maxiter, tol = .Machine$double.eps)

Arguments

initial
Starting guess
f
Function for which $f(z)=0$ is to be solved for $z$
fdash
Derivative of function (note: Cauchy-Riemann conditions assumed)
maxiter
Maximum number of iterations attempted
tol
Tolerance: iteration stops if $|f(z)|

Value

  • Returns $z$ with $|f(z)|

Details

Bog-standard

Examples

Run this code
#Find the two square roots of 2+i:
f <- function(z){z^2-(2+1i)}
fdash <- function(z){2*z}
newton.rapheson( 1.4+0.3i,f,fdash,maxiter=10)
newton.rapheson(-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.rapheson(-0.5+1i,g,gdash,maxiter=10)
newton.rapheson(-0.5-1i,g,gdash,maxiter=10)
newton.rapheson(+0.5+0i,g,gdash,maxiter=10)

Run the code above in your browser using DataLab