问题
I have this function to maximize:
funcToOpt <- function (theta1,theta2,theta3)
{
inner <- rowSums((wb + (theta1*X1+theta2*X2+theta3*X3) / Nt) * r)
innerU <- u(inner, gamma) # u() is another function
return (sum(innerU) / T)
}
fbb <- function(x) funcToOpt(x[1],x[2],x[3])
max <- optim(c(0,0,0),fbb,control=list(fnscale=-1))
Where: wb,X1,X2,X3,r
are TxN
matrices and Nt
a vector with length of N
I wanna just that
(wb + (theta1*X1+theta2*X2+theta3*X3) / Nt)
can't assume negative
values.
Is there someone who can help me? Thanks!
来源:https://stackoverflow.com/questions/38935453/how-to-bound-a-value-in-a-function-in-r