MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Newbie question about the behavior of NMaximize

  • To: mathgroup at smc.vnet.net
  • Subject: [mg50984] Re: [mg50955] Newbie question about the behavior of NMaximize
  • From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
  • Date: Thu, 30 Sep 2004 04:52:53 -0400 (EDT)
  • References: <200409290715.DAA10645@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

On 29 Sep 2004, at 16:15, Roger Levy wrote:

> *This message was transferred with a trial version of CommuniGate(tm)
> Pro*
> Hi,
>
> I'm confused about the behavior of NMaximize.  It appears that some
> inequality constraints I am stipulating are not being obeyed; a
> stipulation that 0<p4<1 is still allowing a very small negative value
> of p4.  Is there something wrong with the way I'm stating inequality

> constraints below?  Any help much appreciated.
>
> Best,
>
> Roger Levy
>
> In[11]:= y =
> 5*Log[p1*q]+10*Log[p4*q]+25*Log[(p1+p2+p3)*(1-
> q)+p3*q]+20*Log[(p4+p5+p6)*(1-q)+p6*q]
>
> Out[11]= 5 Log[p1 q] + 10 Log[p4 q] + 25 Log[(p1 + p2 + p3) (1 - q) +
> p3 q] +
>
>>    20 Log[(p4 + p5 + p6) (1 - q) + p6 q]
>
> In[13]:=
> NMaximize[{y,0<p1<1,0<p2<1,0<p3<1,0<p4<1,0<p5<1,0<p6<1,p1+p2+p3+p4+p5+p
> 6==1,0<q<1},{p1,p2,p3,p4,p5,p6,q}]
>
> NMaximize::nnum:
>    The function value Indeterminate is not a number at
>                                                           -16
>     {p1, p2, p3, p4, p5, p6, q} = {0., 0., 0., -1.11022 10   , 0., 1.,
> 1.}.
>
> Out[13]= NMaximize[{5 Log[p1 q] + 10 Log[p4 q] +
>
>>      25 Log[(p1 + p2 + p3) (1 - q) + p3 q] +
>
>>      20 Log[(p4 + p5 + p6) (1 - q) + p6 q], 0 < p1 < 1, 0 < p2 < 1,
>
>>     0 < p3 < 1, 0 < p4 < 1, 0 < p5 < 1, 0 < p6 < 1,
>
>>     p1 + p2 + p3 + p4 + p5 + p6 == 1, 0 < q < 1},
>
>>    {p1, p2, p3, p4, p5, p6, q}]
>
I have my suspicion about the possible cause but would prefer someone
who knowns more about these things to explain what is goingon. in any
case, it seems one can get round this problem by combining the
following two steps, Since all your parameters are between 0 and 1 you
might as well repalce them by explicit squares, thus assuring that they
will never take negative values. Secondly, it seems you need t increase
WorkingPrecision. Then:

f[p1_,p2_,p3_,p4_,p5_,p6_,q_]:= 5*Log[p1*q]+10*Log[
     p4*q]+25*Log[(p1+p2+p3)*(1-q)+p3*q]+20*Log[(p4+p5+p6)*(1-q)+p6*q]


NMaximize[{f[p1^2, p2^2, p3^2, p4^2, p5^2, p6^2, q^2], p1^2 + p2^2 +
p3^2 + p4^2 + p5^2 + p6^2 == 1 && 0 < q < 1 && 0 < p1 < 1 &&
     0 < p2 < 1 && 0 < p3 < 1 && 0 < p4 < 1 && 0 < p5 < 1 && 0 < p6 <
1}, {p1, p2, p3, p4, p5, p6, q}, WorkingPrecision -> 20]


{-74.2010921476116985463429193651`20., {p1 ->
0.43797167298883572357694980837336507481`19.999999999999996,
    p2 ->
2.0462351921620306233913660004928380549`19.999999999999996*^-11,
    p3 -> 0.55514035492493601901102506428268332597`19.999999999999996,
    p4 -> 0.61938547987611876695775386428629851749`19.999999999999996,
    p5 -> 7.575238788353619130415904512292868668`19.999999999999996*^-12,
    p6 -> 0.341118201398648477688602987923263545`19.999999999999996,

    q -> 0.65911827727752233665620081340886270816`19.999999999999996}}

The values of the parameters where the maximum has been found are:

({p1, p2, p3, p4, p5, p6, q} /. Last[%])^2

{0.19181918634063965535444914468867449529`19.698970004336015,
4.18707846164238239155647692123806383`19.698970004336015*^-22,
   0.30818081366618393489776900744148647443`19.698970004336015,
0.38363837268136992603361959380571502513`19.698970004336015,
   5.7384242700577207649935827356646424`19.698970004336015*^-23,
0.1163616273254489042399703876506573673`19.698970004336015,
   0.43443690344128881780871669034321383114`19.698970004336015}

Andrzej Kozlowski
Chiba, Japan
http://www.akikoz.net/~andrzej/
http://www.mimuw.edu.pl/~akoz/


  • Prev by Date: Re: Re: text size in GUIKit
  • Next by Date: Re: Newbie question about the behavior of NMaximize
  • Previous by thread: Newbie question about the behavior of NMaximize
  • Next by thread: Re: Newbie question about the behavior of NMaximize