Dear R users, I want to find the maximum value of v, subject to the constrain that the sum of x is equal to 1. So, I want to maximize: v<-t(x)%*%distance%*%x Subject to: sum(x)=1 Where: "x" is a vector n X 1 "distance" is a matrix n*n and it is given. (In practive, the number of n can go up to hundreds.) I have a bit of experience using R but not much on optimization techniques or on R optimization packages. I have taken a look at optim and nlminb, but I am confused. Do you have any suggestion on how to do it? Thank you very much, Leo Monasterio.
?constrOptim -- View this message in context: http://r.789695.n4.nabble.com/constrained-optimization-which-package-tp2717677p2717719.html Sent from the R help mailing list archive at Nabble.com.
Dear R users, In the function bellow I want to find the maximum value of v, subject to the constrain that the sum of x is equal to 1. I want to maximize: v<-t(x)%*%distance%*%x Subject to: sum(x)=1 Where: "x" is a vector n X 1 "distance" is a matrix n*n and it is given. (In practice, the number of n can go up to hundreds.) I have a bit of experience using R but not much on optimization techniques or on R optimization packages. I have taken a look at optim and nlminb, but I am quite confused. Do you have any suggestion on how to do it? Thank you very much, Leo Monasterio.
On Tue, Sep 28, 2010 at 9:47 PM, Leonardo Monasterio <leonardo.monasterio at gmail.com> wrote:> In the function bellow I ?want to find the maximum value of v, > subject to the constrain that the sum of x is equal to 1. > ?I want to maximize: > v<-t(x)%*%distance%*%x > > Subject to: > sum(x)=1 > > Where: > "x" is a vector n X 1 > "distance" is a matrix n*n and it is given. > (In practice, the number of n can go up to hundreds.) > > I have a bit of experience using R but not much on optimization > techniques or on R optimization packages. ?I have taken a look at > optim and nlminb, but I am quite confused. > ?Do you have any suggestion on how to do it?Your optimization problem corresponds to a quadratic programming problem. So, you can use, e.g., the package quadprog. Hope this helps you, Paul
Leonardo Monasterio <leonardo.monasterio <at> gmail.com> writes:> > Dear R users, > > In the function bellow I want to find the maximum value of v, > subject to the constrain that the sum of x is equal to 1. > I want to maximize: > v<-t(x)%*%distance%*%x > > Subject to: > sum(x)=1I do not see why you would take the trouble to use constraint optimization here. Use x_n as a dependent variable, x_n <- 1 - sum(x), x an (n-1)-dim. vector, define another function f1(x) <- f(c(x, 1-sum(x))) appropriately, and apply optim() without constraints. Hans Werner> Where: > "x" is a vector n X 1 > "distance" is a matrix n*n and it is given. > (In practice, the number of n can go up to hundreds.) > > I have a bit of experience using R but not much on optimization > techniques or on R optimization packages. I have taken a look at > optim and nlminb, but I am quite confused. > Do you have any suggestion on how to do it? > Thank you very much, > Leo Monasterio. > >