http://www.mathworks.com/matlabcentral/newsreader/view_thread/247783
MATLAB Central Newsreader  Problem regarding Maximizing a function
Feed for thread: Problem regarding Maximizing a function
enus
©19942015 by MathWorks, Inc.
webmaster@mathworks.com
MATLAB Central Newsreader
http://blogs.law.harvard.edu/tech/rss
60
MathWorks
http://www.mathworks.com/images/membrane_icon.gif

Mon, 30 Mar 2009 00:17:35 +0000
Problem regarding Maximizing a function
http://www.mathworks.com/matlabcentral/newsreader/view_thread/247783#638534
lovish
Hi guys,<br>
<br>
I am having problems with maximizing a function using optimization tool. I have to maximize<br>
<br>
max f(x)= log (x1) + log (x2) + log (x3)<br>
<br>
with the constraints that x1+x2 <=1 ; x1+x3<=1<br>
<br>
I'm solving it using optimization tool box using fmin solver. The function I have created is <br>
<br>
function f=objfun(x)<br>
f= log(x1)+log(x2)+ log (x3);<br>
f=z;<br>
<br>
I have used f=z in order to maximize the function as fmin minimizes the function f(x) But it isn't working. Please guide me as to how should I use the toolbox in order to maximize the function.<br>
<br>
Thanks

Mon, 30 Mar 2009 00:50:18 +0000
Re: Problem regarding Maximizing a function
http://www.mathworks.com/matlabcentral/newsreader/view_thread/247783#638539
John D'Errico
"lovish " <lovishagarwal@gmail.com> wrote in message <gqp32v$kum$1@fred.mathworks.com>...<br>
> Hi guys,<br>
> <br>
> I am having problems with maximizing a function using optimization tool. I have to maximize<br>
> <br>
> max f(x)= log (x1) + log (x2) + log (x3)<br>
> <br>
> with the constraints that x1+x2 <=1 ; x1+x3<=1<br>
> <br>
> I'm solving it using optimization tool box using fmin solver. The function I have created is <br>
<br>
There is no solver called fmin in the optimization<br>
toolbox. So it will be difficult to help you.<br>
<br>
<br>
> <br>
> function f=objfun(x)<br>
> f= log(x1)+log(x2)+ log (x3);<br>
> f=z;<br>
> <br>
> I have used f=z in order to maximize the function as fmin minimizes the function f(x) But it isn't working. Please guide me as to how should I use the toolbox in order to maximize the function.<br>
> <br>
<br>
What is not working? What is wrong? What has<br>
failed? In what way did it fail?<br>
<br>
The crystal ball is cloudy.<br>
<br>
John

Mon, 30 Mar 2009 01:18:01 +0000
Re: Problem regarding Maximizing a function
http://www.mathworks.com/matlabcentral/newsreader/view_thread/247783#638543
lovish
I'm working with optimization toolbox using the 'fmincon' solver . The fmincon solver works to minimze a function. There's no inbuilt function to maximize a function. <br>
<br>
The problem that I'm encountering is that for instance<br>
when I need to maximize f(x)= x1 + x2<br>
s.t x1+x2<=2 where x1 and x2>=0<br>
<br>
I ain't able to do that. I'm setting the function as <br>
<br>
> > function f=objfun(x)<br>
> > f= x1+x2;<br>
> > f=z;<br>
<br>
Instead of getting the values as x1=1 and x2=1 , it it displaying x1=x2=0 and f(x)=0 as it it minimizing the function. How should I modify the function or the conditions in the solver to maximize the function?? I would highly appreciate if someone could help me.<br>
<br>
Thanks and Regards,<br>
Lovish<br>
<br>
<br>
"John D'Errico" <woodchips@rochester.rr.com> wrote in message <gqp50a$i4s$1@fred.mathworks.com>...<br>
> "lovish " <lovishagarwal@gmail.com> wrote in message <gqp32v$kum$1@fred.mathworks.com>...<br>
> > Hi guys,<br>
> > <br>
> > I am having problems with maximizing a function using optimization tool. I have to maximize<br>
> > <br>
> > max f(x)= log (x1) + log (x2) + log (x3)<br>
> > <br>
> > with the constraints that x1+x2 <=1 ; x1+x3<=1<br>
> > <br>
> > I'm solving it using optimization tool box using fmin solver. The function I have created is <br>
> <br>
> There is no solver called fmin in the optimization<br>
> toolbox. So it will be difficult to help you.<br>
> <br>
> <br>
> > <br>
> > function f=objfun(x)<br>
> > f= log(x1)+log(x2)+ log (x3);<br>
> > f=z;<br>
> > <br>
> > I have used f=z in order to maximize the function as fmin minimizes the function f(x) But it isn't working. Please guide me as to how should I use the toolbox in order to maximize the function.<br>
> > <br>
> <br>
> What is not working? What is wrong? What has<br>
> failed? In what way did it fail?<br>
> <br>
> The crystal ball is cloudy.<br>
> <br>
> John

Mon, 30 Mar 2009 01:45:03 +0000
Re: Problem regarding Maximizing a function
http://www.mathworks.com/matlabcentral/newsreader/view_thread/247783#638548
Roger Stafford
"lovish " <lovishagarwal@gmail.com> wrote in message <gqp32v$kum$1@fred.mathworks.com>...<br>
> .......<br>
> I am having problems with maximizing a function using optimization tool. I have to maximize<br>
> <br>
> max f(x)= log (x1) + log (x2) + log (x3)<br>
> <br>
> with the constraints that x1+x2 <=1 ; x1+x3<=1<br>
> ......<br>
<br>
I assume that you also require that 0<x1, 0<x2, and 0<x3 in order to get finite, real values for the logarithms.<br>
<br>
I am puzzled that you need to use the brute force methods of the Optimization Toolbox for this simple problem. By elementary calculus the maximum value of your function is precisely: log(4/27).<br>
<br>
Roger Stafford

Mon, 30 Mar 2009 01:54:02 +0000
Re: Problem regarding Maximizing a function
http://www.mathworks.com/matlabcentral/newsreader/view_thread/247783#638551
Matt Fig
"lovish " <lovishagarwal@gmail.com> wrote in message <gqp6k9$q5p$1@fred.mathworks.com>...<br>
> I'm working with optimization toolbox using the 'fmincon' solver . The fmincon solver works to minimze a function. There's no inbuilt function to maximize a function. <br>
> <br>
> The problem that I'm encountering is that for instance<br>
> when I need to maximize f(x)= x1 + x2<br>
> s.t x1+x2<=2 where x1 and x2>=0<br>
> <br>
> I ain't able to do that. I'm setting the function as <br>
<br>
<br>
Ain't? Please!<br>
<br>
<br>
> > > function f=objfun(x)<br>
> > > f= x1+x2;<br>
> > > f=z;<br>
> <br>
<br>
<br>
As far as your function f, I am wondering why it doesn't error on the last line. Where is z defined in that function? How can you take the negative of an undefined quantity? Actually the same holds for x1 and x2. Where are they defined in that function? Do you mean:<br>
<br>
function f=objfun(x)<br>
% Takes a vector with at least two elements.<br>
f = x(1)+x(2);<br>
f = f;

Mon, 30 Mar 2009 01:59:01 +0000
Re: Problem regarding Maximizing a function
http://www.mathworks.com/matlabcentral/newsreader/view_thread/247783#638553
John D'Errico
"lovish " <lovishagarwal@gmail.com> wrote in message <gqp6k9$q5p$1@fred.mathworks.com>...<br>
> I'm working with optimization toolbox using the 'fmincon' solver . The fmincon solver works to minimze a function. There's no inbuilt function to maximize a function. <br>
> <br>
<br>
So? Minimizing the negative is sufficient.<br>
<br>
<br>
> The problem that I'm encountering is that for instance<br>
> when I need to maximize f(x)= x1 + x2<br>
> s.t x1+x2<=2 where x1 and x2>=0<br>
> <br>
> I ain't able to do that. I'm setting the function as <br>
> <br>
> > > function f=objfun(x)<br>
> > > f= x1+x2;<br>
> > > f=z;<br>
<br>
z is undefined. I doubt it will return anything (except<br>
an error) given the code you have shown.<br>
<br>
But, you did not say you got an error. So your code<br>
is apparently not what you have shown.<br>
<br>
> <br>
> Instead of getting the values as x1=1 and x2=1 , it it displaying x1=x2=0 and f(x)=0 as it it minimizing the function. How should I modify the function or the conditions in the solver to maximize the function?? I would highly appreciate if someone could help me.<br>
> <br>
<br>
You have not yet shown us correctly what you<br>
have tried. So how will I know what you have<br>
done wrong? <br>
<br>
How for example, did you try to set the<br>
inequality constraint? Did you try? <br>
<br>
Did you read the help or the doc for fmincon?<br>
It gives some clear examples of how to use<br>
fmincon.<br>
<br>
John