I'm new to optimization in R and to R at all, Trying to implement the following set of equations - to find the Maximum, Minimum and intersections and maximum and minimum values for intersect points. a specific form of the function is:
P = 1.8X+2.55Y+3.2Z
where the constraints are:
X + Y + Z = 1
X, Y, Z =>0
1.8X = 2.55Y = 3.2Z
I'm using nlcoptim trying to implement it the following way: library(NlcOptim)
objective function
obj = function(x){
return(1.8 * x[1] + 2.55 * x[2] + 3.2 * x[3])
}
constraint function:
con = function(x){
f = NULL
f = rbind(f, x[1] + x[2] + x[3] - 1)
f = rbind(f, x[1] >= 0)
f = rbind(f, x[1] <= 1)
f = rbind(f, x[2] >= 0)
f = rbind(f, x[2] <= 1)
f = rbind(f, x[3] >= 0)
f = rbind(f, x[3] <= 1)
return(list(ceq = NULL, c = f))
}
setting initial value for x:
x0 = c(0, 0, 0)
solving using solnl:
solnl(x0, objfun = obj, confun = con)
I keep getting an error. What am I doing wrong?