Hi Greg,
The problem is that I also have restrictions for each variable (they must be higher than -.07 and smaller than .2) and I'm dealing with a lot of them. I've already tried the second approach but, as far as it seems, the function doesn't satisfy my objective. That's what I'm doing: ..................... faum = function(aum) { (...) ifelse(colMeans(prob) >.65, totm <- (sum(marg)), totm <- -1e10) #prob is a transformation of 'aum' and sum(marg) (always positive) is what I want to maximize (...) return(-totm) } optim(rep(0,nrow), faum, method="L-BFGS-B", control=list(trace=12), lower=rep(-.07,nrow), upper=rep(.2,nrow) ) ..................... The function gives me 1e10 if my initial values for the parameters doesn't satisfy mean>.65 and doesn't improve my initial conditions if they satisfy mean<=.65. I know that a solution with mean>.65 exists, I can find it by hand. -- View this message in context: http://r.789695.n4.nabble.com/Optimization-problem-tp4630278p4630419.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.