7
Suppose I want to minimize the following function:
-(5-(x1-2)^2-2*(x2-1)^2)
s.a. x1+4*x2 < 3
For optimization problems without restriction I can use the following code.
fr <- function(x){
x1 <- x[1]
x2 <- x[2]
-(5-(x1-2)^2-2*(x2-1)^2)
}
optim(c(1,1),fr)
How to do optimization with restriction?