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. > # Broyden banded > > library("nleqslv") > > brdban <- function(x,ml=5,mu=1) { + n <- length(x) + y <- numeric(n) + + for( k in 1:n ) { + + k1 <- max(1, k - ml) + k2 <- min(n, k + mu) + + temp <- 0.0 + for(j in k1:k2) { + if ( j != k ) { + temp <- temp + x[j] * (1.0 + x[j]) + } + } + + y[k] <- x[k] * (2.0 + 5.0 * x[k]**2) + 1.0 - temp + + } + y + } > > n <- 10 > xstart <- -rep(1,n) > ztol <- 1000*.Machine$double.eps > > z1 <- nleqslv(xstart,brdban, method="Newton") > z2 <- nleqslv(xstart,brdban, method="Newton", control=list(dsub=5,dsuper=1)) > > cat("z1 termcd=",z1$termcd, "jcnt,fcnt=",z1$njcnt,z1$nfcnt,"\n") z1 termcd= 1 jcnt,fcnt= 5 5 > cat("z2 termcd=",z2$termcd, "jcnt,fcnt=",z2$njcnt,z2$nfcnt,"\n") z2 termcd= 1 jcnt,fcnt= 5 5 > z1$message [1] "Function criterion near zero" > z2$message [1] "Function criterion near zero" > all.equal(z2$x,z1$x) [1] TRUE > all.equal(z2$x,z1$x, tolerance=ztol) [1] TRUE > > z1 <- nleqslv(xstart,brdban, ml=2,mu=2, method="Newton") > z2 <- nleqslv(xstart,brdban, ml=2,mu=2, method="Newton", control=list(dsub=2,dsuper=2)) > > cat("z1 termcd=",z1$termcd, "jcnt,fcnt=",z1$njcnt,z1$nfcnt,"\n") z1 termcd= 1 jcnt,fcnt= 5 5 > cat("z2 termcd=",z2$termcd, "jcnt,fcnt=",z2$njcnt,z2$nfcnt,"\n") z2 termcd= 1 jcnt,fcnt= 5 5 > z1$message [1] "Function criterion near zero" > z2$message [1] "Function criterion near zero" > all.equal(z2$x,z1$x, tolerance=ztol) [1] TRUE > > z3 <- nleqslv(xstart,brdban, ml=2,mu=2, method="Broyden") > z4 <- nleqslv(xstart,brdban, ml=2,mu=2, method="Broyden", control=list(dsub=2,dsuper=2)) > > cat("z3 termcd=",z1$termcd, "jcnt,fcnt=",z3$njcnt,z3$nfcnt,"\n") z3 termcd= 1 jcnt,fcnt= 1 20 > cat("z4 termcd=",z2$termcd, "jcnt,fcnt=",z4$njcnt,z4$nfcnt,"\n") z4 termcd= 1 jcnt,fcnt= 1 20 > z3$message [1] "Function criterion near zero" > z4$message [1] "Function criterion near zero" > all.equal(z3$x,z1$x) [1] TRUE > all.equal(z4$x,z1$x) [1] TRUE > all.equal(z4$x,z3$x, tolerance=ztol) [1] TRUE > > proc.time() user system elapsed 0.14 0.06 0.18