Re: Plot vs NMaximize
- To: mathgroup at smc.vnet.net
- Subject: [mg94324] Re: Plot vs NMaximize
- From: Bill Rowe <readnews at sbcglobal.net>
- Date: Wed, 10 Dec 2008 04:49:10 -0500 (EST)
On 12/9/08 at 6:55 AM, Nikolaus at rath.org (Nikolaus Rath) wrote:
>"David Park" <djmpark at comcast.net> writes:
>>How about a specific example where NMaximize gets stuck but you can
>>easily see the maximum from a plot?
>Try this one:
>f[x_] := Sin[2 \[Pi] x] + 10 Sin[(2 \[Pi] x)/30]
>Plot[f[x], {x, 0, 50}]
>NMaximize[{f[x], x >= 0 && x < 50}, x]
>this gives me a maximum at {0.988032, {x -> 29.8451}}.
What version of Mathematica are you using? I get
In[1]:= f[x_] := Sin[2 \[Pi] x] + 10 Sin[(2 \[Pi] x)/30]
NMaximize[{f[x], x >= 0 && x < 50}, x]
Out[2]= {10.9864,{x->37.2527}}
In[3]:= $Version
Out[3]= 7.0 for Mac OS X x86 (64-bit) (November 11, 2008)
Note, this is not to imply you cannot create a function that
gets NMaximize trapped at something other than the global maximum.