[R] Optimization problem

Greg Snow 538280 at gmail.com
Wed May 16 23:29:14 CEST 2012


There are a couple of options.

First if you want the mean to equal 7, then that means the sum must
equal 21 and therefore you can let optim only play with 2 of the
variables, then set the 3rd to be 21-s1-s2.

If you want the mean to be greater than 7 then just put in a test, if
the mean is less than 7 then return -Inf or another really small
number, if the mean is large enough then go on to compute the function
that you want to maximize.

Also note that you don't need the loop, it can be replaced with "sum(s^3)".

On Wed, May 16, 2012 at 10:44 AM, Pacin Al <jokloq at gmail.com> wrote:
> Hi,
>
> I'm dealing with an optimization problem. I'm using 'optim' to maximize the
> output of a function, given some restrictions on the input. I would like to
> know if there is a way to impose some restrictions on 'intermediate
> variables' of the function. An example..
>
> fx = function (x)
> {
> s <- 0
> for (i in 1:3)
> {
> s <- x[i]^3 + s
> }
> s
> }
>
> optim(rep(4,3), method="L-BFGS-B", lower=rep(-10,nlin), upper=rep(10,nlin))
>
> It would return '-10' for all variables. I want, however, a solution
> satisfying mean(x)>7.
> Please, don't analyse this specific example, but the logic of satisfying a
> criterium for the mean of the input (with thousands of variables). My real
> problem involves price elasticity and I want to find the price increase for
> each individual that would give me maximum total profit margin, but
> respecting a minimum retention of clients.
>
> Thank you very much,
> John Mayer
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Optimization-problem-tp4630278.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



-- 
Gregory (Greg) L. Snow Ph.D.
538280 at gmail.com



More information about the R-help mailing list