I'm trying to solve a non-linear optimization problem in R using package alabama. After defining the objective function like this:
fn <- function(x)
{
-(database4[1,1] * x[1] + database4[1,2] * x[1] * x[1] +
database4[2,1] * x[2] + database4[2,2] * x[2] * x[2]+database4[3,1] * x[3] + database4[3,2] * x[3]* x[3]
database4[4,1] * x[4] + database4[4,2] * x[4] * x[4])
}
I've defined the inequality like this :
hin <- function(x) {
h <- rep(NA, 1)
h[0] <- (database4[1,3]+database4[2,3] +database4[3,3] +database4[4,3]+ 1) -
(x[1] + x[2] + x[3] + x[4])
h[1] <- x[1] - database4[1,5]
h[2] <- database4[1,6] - x[1]
h[3] <- x[2] - database4[2,5]
h[4] <- database4[2,6] - x[2]
h[5] < x[3] - database4[3,5]
h[6] <- database4[3,6] - x[3]
h[4] <- x[4] - database4[4,5]
h[6] <- database4[4,6] - x[4]
h
}
Then the objective function is called with hin function like this:
constrOptim.nl(par=c(database4[1,3], database4[2,3], database4[3,3], database4[4,3]), fn=fn, heq=NULL, hin= hin, control.outer = list(itmax= 3000))
The values used are to be automated, so cell references are used. And this is the given database4
The error that i get is...
"Error in if (any(hin(theta, ...) <= 0)) stop("initial value not feasible") :
missing value where TRUE/FALSE needed"
traceback() - "2: adpbar(par, fn, gr, hin = hin, hin.jac = hin.jac, control.outer = outer.ctrl,
control.optim = optim.ctrl, ...)
1: constrOptim.nl(par = c(database4[1, 3], database4[2, 3], database4[3,
3], database4[4, 3]), fn = fn, heq = NULL, hin = hin, control.outer = list(itmax = 3000))"
Please help!