Re: Plot vs NMaximize
- To: mathgroup at smc.vnet.net
- Subject: [mg94339] Re: Plot vs NMaximize
- From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
- Date: Wed, 10 Dec 2008 04:51:51 -0500 (EST)
- Organization: The Open University, Milton Keynes, UK
- References: <13842004.1228737086065.JavaMail.root@m02> <ghlmaa$jk2$1@smc.vnet.net>
Nikolaus Rath wrote: > "David Park" <djmpark at comcast.net> writes: <snip> >> 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}}. <snip> FWIW, It seems that I do not get the same answer than yours, though the answer is consistent on two different versions and platforms (6.0.3 and 7.0 on 64-bit Mac OS X and 32-bit Windows XP). In[1]:= 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] {$Version, $ReleaseNumber} Out[3]= {10.9864, {x -> 37.2527}} Out[4]= {"6.0 for Mac OS X x86 (64-bit) (May 21, 2008)", 3} In[1]:= 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] {$Version, $ReleaseNumber} Out[3]= {10.9864, {x -> 37.2527}} Out[4]= {"7.0 for Microsoft Windows (32-bit) (November 10, 2008)", 0} Regards, -- Jean-Marc