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:
Optimization problem

Subject: Optimization problem

From: lovish

Date: 12 Apr, 2009 00:51:01

Message: 1 of 4

I am having problems with plotting the graph of function using optimization tool. Suppose I have to maximize
 max f(x)= log (x1) + log (x2) + log (x3)
with the constraints that x1+x2 <=1 ; x1+x3<=1
 
I'm using the optimization tool and in that tool there is a option of plotting the function value at each iteration. The problem is that the plot is discrete as the value is being plotted at each iteration. I want the plot of function which is continuous. The other problem is that I want the plot of values of each 'x' for each iteration. How can I incorporate these two functionalities such that I get a continuous function f(x) and plot of x1 , x2 and x3? I would highly appreciate if someone could help me in this case.

Subject: Optimization problem

From: Roger Stafford

Date: 12 Apr, 2009 04:00:03

Message: 2 of 4

"lovish " <lovishagarwal@gmail.com> wrote in message <grrdtl$b6f$1@fred.mathworks.com>...
> I am having problems with plotting the graph of function using optimization tool. Suppose I have to maximize
> max f(x)= log (x1) + log (x2) + log (x3)
> with the constraints that x1+x2 <=1 ; x1+x3<=1
> .....

  I believe most of us in this newsgroup find it annoying when someone begins a brand new thread which only repeats a question they already asked in a prior thread. It wastes a lot of peoples' time this way. Instead you should return to the earlier thread and just present whatever additional questions or elucidations you have arrived at in the meantime.

  Here you have posed the very same question as you did in the "Problem regarding Maximizing a function" thread of March 30. This gives those of us who responded to that earlier thread the impression that you are ignoring what we have suggested to you.

  In particular I suggested to you that you could avoid using matlab entirely and find the answer, log(4/27), using simple calculus (assuming x1, x2, & x3 are all positive.) You have not even asked about the reasoning used in finding the maximum this way.

Roger Stafford

Subject: Optimization problem

From: lovish

Date: 12 Apr, 2009 19:04:01

Message: 3 of 4

I apologize for the same. Being new to the community I wasn't aware of this fact of continuing with the old post.

Secondly for using simple calculus method in this problem, Please guide me as to how you used simple calculus to find maxf(x).

Other than that,this is just a sample of a extremely complex problem which I;m working on and I wonder whether calculus can work for equations which involves 20 variables. If it can work , please let me know the methodology that you are using.

I apologize once again for the inconvenience caused to you and other members. I have to apologize that without reading your this post,I posted another questions which has the same flavor as a new thread. I sincerely apologize for that too. I will take care of such things in future.



"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <grrp03$6m3$1@fred.mathworks.com>...
> "lovish " <lovishagarwal@gmail.com> wrote in message <grrdtl$b6f$1@fred.mathworks.com>...
> > I am having problems with plotting the graph of function using optimization tool. Suppose I have to maximize
> > max f(x)= log (x1) + log (x2) + log (x3)
> > with the constraints that x1+x2 <=1 ; x1+x3<=1
> > .....
>
> I believe most of us in this newsgroup find it annoying when someone begins a brand new thread which only repeats a question they already asked in a prior thread. It wastes a lot of peoples' time this way. Instead you should return to the earlier thread and just present whatever additional questions or elucidations you have arrived at in the meantime.
>
> Here you have posed the very same question as you did in the "Problem regarding Maximizing a function" thread of March 30. This gives those of us who responded to that earlier thread the impression that you are ignoring what we have suggested to you.
>
> In particular I suggested to you that you could avoid using matlab entirely and find the answer, log(4/27), using simple calculus (assuming x1, x2, & x3 are all positive.) You have not even asked about the reasoning used in finding the maximum this way.
>
> Roger Stafford

Subject: Optimization problem

From: Roger Stafford

Date: 12 Apr, 2009 20:30:04

Message: 4 of 4

"lovish " <lovishagarwal@gmail.com> wrote in message <grtdv1$ou$1@fred.mathworks.com>...
> I apologize for the same. Being new to the community I wasn't aware of this fact of continuing with the old post.
>
> Secondly for using simple calculus method in this problem, Please guide me as to how you used simple calculus to find maxf(x).
>
> Other than that,this is just a sample of a extremely complex problem which I;m working on and I wonder whether calculus can work for equations which involves 20 variables. If it can work , please let me know the methodology that you are using.
>
> I apologize once again for the inconvenience caused to you and other members. I have to apologize that without reading your this post,I posted another questions which has the same flavor as a new thread. I sincerely apologize for that too. I will take care of such things in future.

  As to the use of simple calculus in your original problem, the reasoning goes this way. Presumably you wish to restrict x1, x2, and x3 to positive values to avoid complex results for the logarithm function. That, along with the further restrictions x1+x2<=1 and x1+x3<=1, limits you to a bounded tetrahedral region in the x1, x2, x3 space.

  Also f(x1,x2,x3) = log(x1)+log(x2)+log(x3) = log(x1*x2*x3), and since the logarithm is monotonically increasing, we have

 max(f(x1,x2,x3)) = log(max(x1*x2*x3))

  If you take a cross section of this region orthogonal to the x1 axis with the value x1 = x, it would be a square with its four corners at:

 (x,0,0), (x,1-x,0), (x,0,1-x), and (x,1-x,1-x)

The product x1*x2*x3 will be increasing as x2 and x3 increase in the square, so the maximum value within the square will occur at the corner (x,1-x,1-x). This shows that the maximum in the region will occur somewhere along the line segment connecting (0,1,1) and (1,0,0). This is a problem in calculus: find the maximum value of g(x) = x*(1-x)*(1-x) = x^3-2*x^2+x for 0<=x<=1. Taking the derivative gives

 g'(x) = 3*x^2-4*x+1 = (1-x)*(1-3*x)

which is zero at x = 1 and x = 1/3. Clearly the maximum of g(x) is at x=1/3 where g(1/3) = 1/3*(1-1/3)*(1-1/3) = 4/27. This gives the answer of

 max(f(x1,x2,x3)) = log(4/27).

  For the "extremely complex problem ... which involves 20 variables" I agree that it is doubtful that you could use such simple methods to solve it. So you will probably have to follow John D'Errico's advice and use 'fmincon' of the Optimization Toolbox. You should be forewarned that with as many as 20 variables this function can encounter great difficulties. For it to explore even such a simple thing as every possible combination of two discrete values of each of the twenty variables takes over a million evaluations! You may find it expedient to effectively eliminate many of your twenty variables in some clever manner.

Roger Stafford

Tags for this Thread

No tags are associated with 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