My initial question can be found here:Optimization in R with arbitrary constraints
It led to another question how to pass arguments into nloptr
.
I need to minimize a function F(x,y,A)
where x
and y are vectors and A
is a matrix, while having constrains that sum(x * y) >= sum(y/3)
and sum(x)=1
.
I have tried to use nloptr
:
F <- function(x,y,A){
...
}
Gc <- function(x,y){
return(sum(y/3) - sum(x*y))
}
Hc <- function(x){
retunr(1-sum(x))
}
nloptr(x0=rep(1/3,3), eval_f=F, lb = 0.05, ub = 1, eval_g_ineq = Gc, eval_g_eq = Hc, opts = list(), y=y, A=A)
And I receive an error:
'A' passed to (...) in 'nloptr' but this is not required in the eval_g_ineq function.
If I say nloptr( ... , y, A)
I get:eval_f requires argument 'cov.mat' but this has not been passed to the 'nloptr' function.
Any advice would be great. Thanks
sum((A[1]*x-A[2]*y))
), why we get different optimal parameter solution for different runnings? – Equerry