Re: Problem finding maximum
- To: mathgroup at smc.vnet.net
- Subject: [mg127614] Re: Problem finding maximum
- From: Bob Hanlon <hanlonr357 at gmail.com>
- Date: Tue, 7 Aug 2012 03:03:27 -0400 (EDT)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- Delivered-to: l-mathgroup@wolfram.com
- Delivered-to: mathgroup-newout@smc.vnet.net
- Delivered-to: mathgroup-newsend@smc.vnet.net
- References: <20120806083748.C04B9683E@smc.vnet.net>
Try using a different Method for NMaximize $Version "7.0 for Mac OS X x86 (64-bit) (November 11, 2008)" f[x_, a_] = (a^3 - 6 x - a^2 (4 + x) + a (2 + 12 x - 4 x^2))/(8 a); aa1 = .7481; NMaximize[{Abs[f[x, aa1]], 0 <= x <= aa1}, x, Method -> "SimulatedAnnealing"] {0.0540933, {x -> 0.}} To find available methods enter a method that is invalid NMaximize[{Abs[f[x, aa1]], 0 <= x <= aa1}, x, Method -> "error"]; NMaximize::bdmtd: Value of option Method -> error is not Automatic, "DifferentialEvolution", "NelderMead", "RandomSearch", or "SimulatedAnnealing". >> In the worst case (i.e., no single method works best for all values of aa1), you could use all of the methods and select the one(s) with the best result Module[{sol = {#, NMaximize[{Abs[f[x, aa1]], 0 <= x <= aa1}, x, Method -> #]} & /@ {"DifferentialEvolution", "NelderMead", "RandomSearch", "SimulatedAnnealing"}}, Select[sol, #[[2, 1]] == Max[sol[[All, 2, 1]]] &]] NMaximize::cvmit: Failed to converge to the requested accuracy or precision within 100 iterations. >> {{"RandomSearch", {0.0540933, {x -> 0.}}}, {"SimulatedAnnealing", {0.0540933, {x -> 0.}}}} Bob Hanlon On Mon, Aug 6, 2012 at 4:37 AM, Cisco Lane <travlorf at yahoo.com> wrote: > Hmm - My Mathematica (Mathematica 7 Home Edition, Ver 7.0.1.0, Mac OS X X86 (32-bit)) gives a different answer: > > f[x_, a_] = (a^3 - 6 x - a^2 (4 + x) + a (2 + 12 x - 4 x^2))/(8 a); > aa1 = .7481; > NMaximize[{Abs[f[x, aa1]], 0 <= x <= aa1}, x] > > {0.0274936, {x -> 0.403948}} > > Any idea why? I must use an automatically selected start point, because the values of aa1 vary widely. > > Using the rational aa1 and Maximize works: > > f[x_, a_] = (a^3 - 6 x - a^2 (4 + x) + a (2 + 12 x - 4 x^2))/(8 a); > aa1 = 7481/10000; > N[Maximize[{Abs[f[x, aa1]], 0 <= x <= aa1}, x]] > > {0.0540933, {x -> 0.}} > > but I am not sure why. If this method is reliable, I could use it, but it seems klugy. >
- References:
- Re: Problem finding maximum
- From: Cisco Lane <travlorf@yahoo.com>
- Re: Problem finding maximum