[R] Non Linear Solver - Optim in R

Narendra Modi bjpmodi2016 at gmail.com
Fri Jun 17 15:51:59 CEST 2016


Hello,
Resending this message in "Plain-text".

Thank you for the add to the list.

I have written a R snippet to solve a non-linear problem using Optim solver.

The parameters to be solved are supposed to be in a matrix form as attached

such that summation of columns is <=1 except for the first column. ie,
P1.F1j + P2.F1j <=1 ,  P1.F2j + P2.F2j <=1 ,  P1.F3j + P2.F3j <=1 and so
on..

Since OPTIM solver considers "pars" only as vector, I defined the vector as

my.data.var <- vector("numeric",length = 12)

and in the OPTIM solver, I passed it as

optim(my.data.var, Error.func, method="L-BFGS-B",
upper=c(Inf,1,1,1,1,1,Inf,1,1,1,1,1))

Then in the error function, I stacked the vector into a matrix as :

my.data.var.mat <- matrix(my.data.var,nrow = 2, ncol = 6,byrow = TRUE)

So, my first question is how do I define the constraints for each column
except the first one in the OPTIM solver? As you can see, with the UPPER
limit in the OPTIM solver, I can fix the upper bound, but there is no way
for me set the summation constraint to <=1.

Do I need a different solver for this scenario which allows me to use
Matrix elements as parameters?

Thanks!
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Matrix.PNG
Type: image/png
Size: 3957 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20160617/ac99d55b/attachment.png>


More information about the R-help mailing list