# [R] Optimization

Moshe Olshansky m_olshansky at yahoo.com
Wed Jul 18 02:32:52 CEST 2007

```This is partially true since both the function to be
maximized and the constraint are non-linear.  One may
substitute 1-x1-x2 for x3 and use (let say) Lagrange
multipliers to get two non-linear equations with 2
unknowns for which there should be a function solving
them. Then you must find the points where the
constraint function intersects with the triangle
{x1>=0,x2>=0,x1+x2<=1}, which is easier (for each of
the 3 edges you get a non-linear equation in one
variable).
So even though an (almost) analytical solution can be
found it would be much more convenient to use an
optimization function which (hopefully) does all this
for you.

Moshe.

> Hi,
>
> Your problem can be solved analytically.  Eliminate
> one of the variables,
> say x3, from the problem by using the equality x1 +
> x2 + x3 = 1. Then solve
> for the intersection of the circle (in x1 and x2)
> constraint, with the straight line defined by the
> objective function.  There
> will be, at most, two intersection points. The
> extremum has to be one of
> these two points, provided they also satisfy the
> other inequalities (To me,
> this sounds an awful lot like a homework problem).
>
>
> Ravi.
>
>
----------------------------------------------------------------------------
> -------
>
>
> Assistant Professor, The Center on Aging and Health
>
> Division of Geriatric Medicine and Gerontology
>
> Johns Hopkins University
>
> Ph: (410) 502-2619
>
> Fax: (410) 614-9625
>
>
> Webpage:
>
>
>
>
>
----------------------------------------------------------------------------
> --------
>
> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf
> Of massimiliano.talarico
> Sent: Monday, July 16, 2007 4:50 PM
> To: r-help
> Subject: [R] Optimization
>
> Dear all,
> I need a suggest to obtain the max of this function:
>
> Max x1*0.021986+x2*0.000964+x3*0.02913
>
> with these conditions:
>
> x1+x2+x3=1;
>
> x1>=0;
> x1<=1;
> x2>=0;
> x2<=1;
> x3>=0;
> x3<=1;
>
> Any suggests ?
>
> Massimiliano
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained,
> reproducible code.
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help