[R] Bad optimization solution

Paul Smith phhs80 at gmail.com
Mon May 7 23:30:32 CEST 2007


Dear All

I am trying to perform the below optimization problem, but getting
(0.5,0.5) as optimal solution, which is wrong; the correct solution
should be (1,0) or (0,1).

Am I doing something wrong? I am using R 2.5.0 on Fedora Core 6 (Linux).

Thanks in advance,

Paul

------------------------------------------------------
myfunc <- function(x) {
  x1 <- x[1]
  x2 <- x[2]
  abs(x1-x2)
}

optim(c(0.5,0.5),myfunc,lower=c(0,0),upper=c(1,1),method="L-BFGS-B",control=list(fnscale=-1))



More information about the R-help mailing list