https://github.com/cran/nleqslv
Tip revision: 478c8a71b5dfd695ac7a6b13510c5e458dfa61f7 authored by Berend Hasselman on 05 February 2013, 00:00:00 UTC
version 2.0
version 2.0
Tip revision: 478c8a7
brdban.Rout.save
R version 2.15.2 Patched (2013-01-21 r61728) -- "Trick or Treat"
Copyright (C) 2013 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: x86_64-apple-darwin9.8.0/x86_64 (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.
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", method="Newton",
+ 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] 1
> all(abs(znlq$fvec)<=1e-7) # may not have achieved ftol
[1] TRUE
>
> xstart <- -2*rep(1,n)
> znlq <- nleqslv(xstart, brdban, global="dbldog", method="Newton",
+ 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
>
> 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] 1
> 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
>
> proc.time()
user system elapsed
0.310 0.045 0.340