R Under development (unstable) (2023-11-25 r85635 ucrt) -- "Unsuffered Consequences" Copyright (C) 2023 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > > library(nleqslv) > > # Dennis & Schnabel,1996,"Numerical methods for unconstrained optimization and nonlinear equations", SIAM > # example 6.5.1 page 149 > > dslnex <- function(x) { + y <- numeric(2) + y[1] <- x[1]^2 + x[2]^2 - 2 + y[2] <- exp(x[1]-1) + x[2]^3 - 2 + y + } > > > do.print.xf <- FALSE > do.trace <- 0 > print.result <- function(z) { + if( do.print.xf ) { + print(z$x) + print(z$fvec) + } + print(z$message) + print(all(abs(z$fvec)<=1e-8)) + } > > xcmp.result <- function(z1,z2) all(abs(z1$x-z2$x) <= 1e-8) > > xstart <- c(2,0.5) > hnlq1 <- nleqslv(xstart, dslnex, global="hook", control=list(btol=.01,delta="cauchy", trace=do.trace)) > hnlq2 <- nleqslv(xstart, dslnex, global="hook", control=list(btol=.01,delta="newton", trace=do.trace)) > print.result(hnlq1) [1] "Function criterion near zero" [1] TRUE > print.result(hnlq2) [1] "Function criterion near zero" [1] TRUE > xcmp.result(hnlq1,hnlq2) [1] TRUE > > dnlq1 <- nleqslv(xstart, dslnex, global="dbldog", control=list(btol=.01,delta="cauchy", trace=do.trace)) > dnlq2 <- nleqslv(xstart, dslnex, global="dbldog", control=list(btol=.01,delta="newton", trace=do.trace)) > print.result(dnlq1) [1] "Function criterion near zero" [1] TRUE > print.result(dnlq2) [1] "Function criterion near zero" [1] TRUE > xcmp.result(dnlq1,dnlq2) [1] TRUE > xcmp.result(hnlq1,dnlq1) [1] TRUE > > xstart <- c(1.1,1.1) > hnlq1 <- nleqslv(xstart, dslnex, global="hook", control=list(btol=.01,delta="cauchy", trace=do.trace)) > hnlq2 <- nleqslv(xstart, dslnex, global="hook", control=list(btol=.01,delta="newton", trace=do.trace)) > print.result(hnlq1) [1] "Function criterion near zero" [1] TRUE > print.result(hnlq2) [1] "Function criterion near zero" [1] TRUE > xcmp.result(hnlq1,hnlq2) [1] TRUE > > dnlq1 <- nleqslv(xstart, dslnex, global="dbldog", control=list(btol=.01,delta="cauchy", trace=do.trace)) > dnlq2 <- nleqslv(xstart, dslnex, global="dbldog", control=list(btol=.01,delta="newton", trace=do.trace)) > print.result(dnlq1) [1] "Function criterion near zero" [1] TRUE > print.result(dnlq2) [1] "Function criterion near zero" [1] TRUE > xcmp.result(dnlq1,dnlq2) [1] TRUE > xcmp.result(hnlq1,dnlq1) [1] TRUE > > proc.time() user system elapsed 0.14 0.06 0.18