MathGroup Archive 2008

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

Search the Archive

Re: Plot vs NMaximize

  • To: mathgroup at smc.vnet.net
  • Subject: [mg94281] Re: [mg94221] Plot vs NMaximize
  • From: DrMajorBob <btreat1 at austin.rr.com>
  • Date: Tue, 9 Dec 2008 07:02:51 -0500 (EST)
  • References: <200812081122.GAA15842@smc.vnet.net>
  • Reply-to: drmajorbob at longhorns.com

Here's an example of using Plot to help FindMaximum:

pts =.;
f = Sin[2 x] Cos[3 x];
p1 = Plot[f, {x, 0, 2 Pi}];
xpts = First@Cases[p1, Line[pts : _] :> pts, Infinity];
p2 = ListPlot[xpts];
Show[p1, p2]

(graphic omitted)

max = SortBy[xpts, Last][[-1, 1]]
FindMaximum[f, {x, max}]

5.31784

{0.907858, {x -> 5.31789}}

Plot got very close to the max in that interval, and FindMaximum uses the  
result as an advanced start.

FindMaximum doesn't do it this way automatically, because it wouldn't  
always be best. You can never be certain, in fact, that Plot finds the  
global maximum.

Bobby

On Mon, 08 Dec 2008 05:22:32 -0600, Nikolaus Rath <Nikolaus at rath.org>  
wrote:

> Hello,
>
> It seems to me that it is significantly faster *and* more accurate to
> determine global maxima by plotting the function and looking for the
> positions on the plot than to use NMaximize: in all the cases that
> I've encountered recently, NMaximize got stuck in local extrema (which
> was very easy to see when looking at the plot).
>
> I know that global optimization is a very difficult problem, but I do
> not understand why Plot[] does not suffer from the same problem. If
> Plot[] is able to generate a plot where I can see the position of the
> global maximum in a second, why does NMaximize need several seconds to
> get stuck in some local maxima? Shouldn't it be able to make use of
> the same algorithms that Plot[] uses?
>
>
> Best,
>
>    -Nikolaus
>
> --
>  =C2=BBIt is not worth an intelligent man's time to be in the majority.
>   By definition, there are already enough people to do that.=C2=AB
>                                                          -J.H. Hardy
>
>   PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6  02CF A9AD B7F8 AE4E 425C
>



-- 
DrMajorBob at longhorns.com


  • Prev by Date: proxy / firewall problem
  • Next by Date: RE: Plot vs NMaximize
  • Previous by thread: Re: Plot vs NMaximize
  • Next by thread: Re: Plot vs NMaximize