Message Boards Message Boards

0
|
5274 Views
|
8 Replies
|
6 Total Likes
View groups...
Share
Share this post:

NMaximize gets different results on different runs; must Quit and restart

Posted 11 years ago
Hi, hola and Hallo!

I have to optimize some contrained functions and I am trying to use NMaximize.

I have the following problem (see code below). I use NMaximize for the first function f1 (constraints c1 and variables with start intervals vs1) and get what I want to get. After that I use NMaximize for the function f2 (with c2 and vs2). After this second numerical optimization I run again the very same optimization for f1 again and get a different result although I have not changed the start intervals.

Could you please explain this? The only way I have found to solve this, is to restart everything with Quit[] but maybe you know a easier way to restart only the command NMaximize. I have also tried to set the Method for all optimizations but it does not make any difference, the results still vary.

Thank you very much, muchas gracias, Dankeschön!

 f1 = 1445250/(13229 - 4223 Sqrt[30] (v1 + v2));
 c1 = Sqrt[30] + 30 v1 >= 0 && Sqrt[30] + 30 v2 >= 0 &&
    Sqrt[30] + 30 v3 >= 0 &&
    2 + 45 v2 v3 + 45 v1 (v2 + v3) >= 2 Sqrt[30] (v1 + v2 + v3) &&
    v1 + v2 + v3 <= Sqrt[(2/15)];
 vs1 = {{v1, 0, 0.01}, {v2, 0, 0.01}, {v3, 0, 0.01}};
 
 f2 = 1445250/(13229 - 8446 Sqrt[30] v1);
 c2 = 45 v1 <= Sqrt[30] && Sqrt[30] + 30 v1 >= 0;
vs2 = {{v1, 0, 0.01}};

NMaximize[{f1, c1}, vs1]
NMaximize[{f2, c2}, vs2]
NMaximize[{f1, c1}, vs1]
Out[8]= {190.206, {v1 -> 0.121716, v2 -> 0.121716, v3 -> -0.0111781}}
Out[9]= {190.206, {v1 -> 0.121716}}
During evaluation of In[1]:= NMaximize::cvmit: Failed to converge to the requested accuracy or precision within 100 iterations. >>
Out[10]= {190.253, {v1 -> 0.121759, v2 -> 0.121754, v3 -> -0.0111782}}
I also tried
SeedRandom[0]
NMaximize[{f1, c1}, vs1]
SeedRandom[0]
NMaximize[{f2, c2}, vs2]
SeedRandom[0]
NMaximize[{f1, c1}, vs1]
and
BlockRandom[NMaximize[{f1, c1}, vs1]]
BlockRandom[NMaximize[{f2, c2}, vs2]]
BlockRandom[NMaximize[{f1, c1}, vs1]]
but sadly with NO improvement
POSTED BY: Mauricio Lobos
8 Replies
Posted 11 years ago
Hey Ilian,

thank you veeeeeeery much!! This was really driving me nuts! Could you please give a breve explanation of what you changed or of what was wrong (if there is a more or less short version of an explanation).
POSTED BY: Mauricio Lobos
These specify the initial search region, see the documentation.
POSTED BY: Ilian Gachevski
Aah sorry I misread the question. Also it is undocumented the option to supply additional commands to the variables, are they bounds? {{v1, 0, 0.01}, {v2, 0, 0.01}, {v3, 0, 0.01}} ?
POSTED BY: Sander Huisman
The point is that Out[8] and Out[10] should be consistent, because they are the same NMaximize call, and computing Out[9] in-between should not change anything.
POSTED BY: Ilian Gachevski
Running NMaximize does not change the actual values of v1 v2 and v3, it only give you back the solution back as rules, but the values of v1 v2 and v3 are still value-less, they are symbolic.
POSTED BY: Sander Huisman
This shouldn't happen, thank you for bringing this to our attention. For the time being, please try evaluating the following first
Optimization`NonlinearInteriorPoint; Optimization`NonlinearInteriorPointDump`norm[x_] :=
If[x === {}, 0, Norm[Normal[x], Infinity]]
Then the example should give consistent results:
 In[2]:= f1 = 1445250/(13229 - 4223 Sqrt[30] (v1 + v2));
 c1 = Sqrt[30] + 30 v1 >= 0 && Sqrt[30] + 30 v2 >= 0 &&
    Sqrt[30] + 30 v3 >= 0 &&
    2 + 45 v2 v3 + 45 v1 (v2 + v3) >= 2 Sqrt[30] (v1 + v2 + v3) &&
    v1 + v2 + v3 <= Sqrt[(2/15)];
 vs1 = {{v1, 0, 0.01}, {v2, 0, 0.01}, {v3, 0, 0.01}};
 
 f2 = 1445250/(13229 - 8446 Sqrt[30] v1);
 c2 = 45 v1 <= Sqrt[30] && Sqrt[30] + 30 v1 >= 0;
vs2 = {{v1, 0, 0.01}};

NMaximize[{f1, c1}, vs1]
NMaximize[{f2, c2}, vs2]
NMaximize[{f1, c1}, vs1]

Out[8]= {190.206, {v1 -> 0.121716, v2 -> 0.121716, v3 -> -0.0111781}}

Out[9]= {190.206, {v1 -> 0.121716}}

Out[10]= {190.206, {v1 -> 0.121716, v2 -> 0.121716, v3 -> -0.0111781}}
POSTED BY: Ilian Gachevski
Posted 11 years ago
Jepp, it is correct, that function is only a special case of a more general one with all 3 variables v1,v2,v3
POSTED BY: Mauricio Lobos
Are you sure that the first part is correct? You only have 2 variabled in f1 but there are 3 variables in the constraints. 
POSTED BY: Shenghui Yang
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract