Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
problem regarding maximizing a function

Subject: problem regarding maximizing a function

From: lovish

Date: 12 Apr, 2009 19:00:03

Message: 1 of 4

Hi,

I have a problem with regard to maximizing a function. I'm using optimization tool and using fmincon command in that.

Suppose I have to optimize f(x)= log [x(1)+ x(6)] + log x(2) + log x(3) + log x(4) + log x(5)
subject to x1<=1, x2+x3+x5<=1. x1+x5<=1 , x4<=1; x6<=1

all values are greater than 0.

I'm able to formulate the problem using optimtool. My problem is that while calculating the value of function f(x) , it is taking mod of f(x) and the values shown are positive. The graph that I need to plot should be concave and it is not coming out to be so .

The values I'm getting are
      7.1309
      5.30837
      4.43032
      3.30974
      2.78305
      2.77553
      2.77319
      2.77259
      2.77259

for each iteration . The values in reality should be negative. Please guide me as to where I;'m going wrong.

Subject: problem regarding maximizing a function

From: Roger Stafford

Date: 12 Apr, 2009 21:38:01

Message: 2 of 4

"lovish " <lovishagarwal@gmail.com> wrote in message <grtdnj$fr7$1@fred.mathworks.com>...
> .......
> I have a problem with regard to maximizing a function. I'm using optimization tool and using fmincon command in that.
>
> Suppose I have to optimize f(x)= log [x(1)+ x(6)] + log x(2) + log x(3) + log x(4) + log x(5)
> subject to x1<=1, x2+x3+x5<=1. x1+x5<=1 , x4<=1; x6<=1
>
> all values are greater than 0.
> .......

  The problem you pose here is an example of what I referred to in the "Optimization problem" thread when I said "eliminate many of your ... variables in some clever manner". The variables x4 and x6 appear in your restrictions just once each in x4<=1 and x6<=1. Clearly the maximum occurs with x4=1 and x6=1 and these variables can immediately be eliminated. Similarly x2 and x3 appear only once in x2+x3+x5<=1. The maximum of x2*x3 for a given sum, x2+x3, will occur when x2=x3, so we can replace x3 by x2 everywhere. Now you are down to three variables and again it can easily be solved by calculus. It would pay you to make use of such opportunities with your twenty-variable problem before you subject it to the tender mercies of the Optimization Toolbox.

  By the way, if you allow x1 to sink as low as x1 = -1/2, (which it can without encountering complex logarithms) I get a maximum value of: log(27/64) for your function, just using simple calculus.

Roger Stafford

Subject: problem regarding maximizing a function

From: Roger Stafford

Date: 12 Apr, 2009 23:28:01

Message: 3 of 4

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <grtmvp$rmo$1@fred.mathworks.com>...
> ......
> By the way, if you allow x1 to sink as low as x1 = -1/2, (which it can without encountering complex logarithms) I get a maximum value of: log(27/64) for your function, just using simple calculus.
>
> Roger Stafford

  My apologies. I made an error in reading the inequalities. The maximum of f would be log(1/16), still a problem in calculus. It occurs with all x values positive.

Roger Stafford

Subject: problem regarding maximizing a function

From: lovish

Date: 13 Apr, 2009 12:36:01

Message: 4 of 4

Thanks for your response. The maximum values I'm getting is log(0.063). I guess there might be some approximations taken in my case. Thanks again for the help. However, the problem is that I need to plot the function value at each iteration and need to show how this function attains the shape of a concave function. This is possible, I guess, only if we iterate it and that can be done only through optimtool or using any iterative method. Correct me , if I'm wrong. Secondly, I'm given this constraint of using optimization tool which brings me back again to my question. The problem is not with regard to solving the question, my problem is with regard to certain functionality of optim user interface which is not working. So I would appreciate if someone could address my problem!


"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <grtmvp$rmo$1@fred.mathworks.com>...
> "lovish " <lovishagarwal@gmail.com> wrote in message <grtdnj$fr7$1@fred.mathworks.com>...
> > .......
> > I have a problem with regard to maximizing a function. I'm using optimization tool and using fmincon command in that.
> >
> > Suppose I have to optimize f(x)= log [x(1)+ x(6)] + log x(2) + log x(3) + log x(4) + log x(5)
> > subject to x1<=1, x2+x3+x5<=1. x1+x5<=1 , x4<=1; x6<=1
> >
> > all values are greater than 0.
> > .......
>
> The problem you pose here is an example of what I referred to in the "Optimization problem" thread when I said "eliminate many of your ... variables in some clever manner". The variables x4 and x6 appear in your restrictions just once each in x4<=1 and x6<=1. Clearly the maximum occurs with x4=1 and x6=1 and these variables can immediately be eliminated. Similarly x2 and x3 appear only once in x2+x3+x5<=1. The maximum of x2*x3 for a given sum, x2+x3, will occur when x2=x3, so we can replace x3 by x2 everywhere. Now you are down to three variables and again it can easily be solved by calculus. It would pay you to make use of such opportunities with your twenty-variable problem before you subject it to the tender mercies of the Optimization Toolbox.
>
> By the way, if you allow x1 to sink as low as x1 = -1/2, (which it can without encountering complex logarithms) I get a maximum value of: log(27/64) for your function, just using simple calculus.
>
> Roger Stafford

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us