https://github.com/cran/nleqslv
Revision 0ba40138158632b25db6a0caf704d5eea338fe09 authored by Berend Hasselman on 04 March 2017, 16:12:30 UTC, committed by cran-robot on 04 March 2017, 16:12:30 UTC
1 parent 1c36787
Raw File
Tip revision: 0ba40138158632b25db6a0caf704d5eea338fe09 authored by Berend Hasselman on 04 March 2017, 16:12:30 UTC
version 3.2
Tip revision: 0ba4013
dslnexHook.Rout

R version 3.1.1 (2014-07-10) -- "Sock it to Me"
Copyright (C) 2014 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin10.8.0 (64-bit)

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.

  Natural language support but running in an English locale

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.319   0.048   0.353 
back to top