Re: [R] linear constrained optimization in R

From: Hans W Borchers <hwborchers_at_googlemail.com>
Date: Sat, 26 Mar 2011 10:07:26 +0000

sammyny <sjain <at> caa.columbia.edu> writes:
>
> I am trying to use
> http://rss.acs.unt.edu/Rdoc/library/stats/html/constrOptim.html in R to do
> optimization in R with some given linear constraints but not able to figure
> out how to set up the problem.
>
> For example, I need to maximize $f(x,y) = log(x) + \frac{x^2}{y^2}$ subject
> to constraints $g_1(x,y) = x+y < 1$, $g_2(x,y) = x > 0$ and $g_3(x,y) = y >
> 0$. How do I do this in R? This is just a hypothetical example. Do not worry
> about its structure, instead I am interested to know how to set this up in
> R.
>
> thanks!
>

To get a reasonable solution, avoid coming near to x=0 and y=0. With x >= 0.0001 and y >= 0.0001 constrOptim() can be called as follows:

    constrOptim(c(0.25, 0.25), function(x) -log(x[1])-x[1]^2/x[2]^2, NULL,

                matrix(c(-1,1,0, -1,0,1), 3, 2), c(-1, 0.0001, 0.0001))

--Hans Werner



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. Received on Sat 26 Mar 2011 - 10:13:23 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 26 Mar 2011 - 11:40:24 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive