## Example from Quarteroni & Saleri
F1 <- function(x) c(x[1]^2 + x[2]^2 - 1, sin(pi*x[1]/2) + x[2]^3)
newtonsys(F1, x0 = c(1, 1)) # zero: 0.4760958 -0.8793934
## Find the roots of the complex function sin(z)^2 + sqrt(z) - log(z)
F2 <- function(x) {
z <- x[1] + x[2]*1i
fz <- sin(z)^2 + sqrt(z) - log(z)
c(Re(fz), Im(fz))
}
newtonsys(F2, c(1, 1))
# $zero 0.2555197 0.8948303 , i.e. z0 = 0.2555 + 0.8948i
# $fnorm 2.220446e-16
# $niter 8
Run the code above in your browser using DataLab