[Rd] optim: problem with additional arguments (PR#493)

dirk@surfer.sbm.temple.edu dirk@surfer.sbm.temple.edu
Fri, 17 Mar 2000 18:02:48 +0100 (MET)


The R function "optim" fails when a function requires additional
arguments, if the option "hessian=T" is specified.  I am using R Version
1.0.0 on Windows 98.

Here is an example of the Rosenbrock Banana function from the optim help
example, with the function and gradient modified to take an additonal
argument.  Note that the call to optim works fine unless a hessian is
requested.


     ## Rosenbrock Banana function, modified to take an additional
argument
     fra <- function(x,a) {
         x1 <- x[1]
         x2 <- x[2]
         a * (x2 - x1 * x1)^2 + (1 - x1)^2
     }

     grra <- function(x,a) {
         x1 <- x[1]
         x2 <- x[2]
         c(-4*a * x1 * (x2 - x1 * x1) - 2 * (1 - x1), 2*a * (x2 - x1 *
x1))
     }
a <- 100
xx <- c(-2.1,1)
optim(c(-1.2,1), fra, grra, method = "BFGS",a=100)             # this
works
optim(c(-1.2,1), fra, grra, method = "BFGS",hessian=T,a=100)   # this
doesn't



Dirk Moore
Dept. of Statistics
Temple University
dirk@sbm.temple.edu




-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._