https://github.com/cran/nleqslv
Raw File
Tip revision: e881fc8a6d3dd7dc7e2787e219afb5bb914ee360 authored by Berend Hasselman on 04 May 2011, 15:31:55 UTC
version 1.8.4
Tip revision: e881fc8
brdban.Rout.save

R version 2.13.0 Patched (2011-04-26 r55655)
Copyright (C) 2011 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: i386-apple-darwin9.8.0/i386 (32-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.

> # Broyden banded function
> 
> 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)
> 
> xsol <- c( -0.42830,  -0.47660,  -0.51965,  -0.55810,  -0.59251,
+            -0.62450,  -0.62324,  -0.62139,  -0.62045,  -0.58647  )
> 
> fsol <- brdban(xsol)
> 
> znlq <- nleqslv(xstart, brdban, global="dbldog",
+                   control=list(trace=0,ftol=1e-8,xtol=1e-8,btol=1e-2,delta=-1.0))
> znlq$termcd                 # should be 2 for x values within tolerance                  
[1] 2
> all(abs(znlq$fvec)<=1e-7)   # may not have achieved ftol
[1] TRUE
>     
> xstart <- -2*rep(1,n)
> znlq <- nleqslv(xstart, brdban, global="dbldog",
+                   control=list(trace=0,ftol=1e-8,xtol=1e-8,btol=1e-2,delta=-1.0))
> znlq$termcd
[1] 1
> all(abs(znlq$fvec)<=1e-8)
[1] TRUE
> 
back to top