| Author |
Comment/Response |
Michael
|
07/02/12 01:01am
In Response To 'Re: Re: Re: Maximizing solutions of NDSolve' --------- Find the absolute maximum is tricky, especially for a bumpy function like yours (try plotting it, if you haven't). If no method is specified, Mathematica automatically chooses one. Probably they tweaked the algorithm between v7 and v8, so the answers are different.
Some suggestions:
1. Try different methods:
NMaximize[{int[x], 0 < x < 1.5}, x, Method -> "RandomSearch"]
NMaximize[{int[x], 0 < x < 1.5}, x, Method -> "DifferentialEvolution"]
NMaximize[{int[x], 0 < x < 1.5}, x,
Method -> {"DifferentialEvolution", "ScalingFactor" -> 1}]
NMaximize[{int[x], 0 < x < 1.5}, x, Method -> "SimulatedAnnealing"]
See the Url for more information.
2. Use NDSolve to find y as a function of x and \[Kappa]02:
s[(q0_)?NumericQ] :=
s[q0] = First@
NDSolve[{Derivative[2, 0][y][
x, \[Kappa]02] + (4 q[q0,
x]) (\[Kappa]02/(2 Sqrt[a[x] q[q0, x]]) + Sin[x]^2) y[
x, \[Kappa]02] == 0, Derivative[1, 0][y][0, \[Kappa]02] == 0,
y[0, \[Kappa]02] == 0.5}, y, {x, 0, 200}, {\[Kappa]02, 0, 1.5},
MaxSteps -> 500000, Method -> {Automatic},
MaxStepFraction -> 1/100,
WorkingPrecision -> $MachinePrecision + 2]
n[\[Kappa]02_, q0_,
t_] := \[Omega][\[Kappa]02, q0, t]/
2 (Abs[Derivative[1, 0][y][t, \[Kappa]02] /.
s[q0]]^2/\[Omega][\[Kappa]02, q0, t]^2 +
Abs[y[t, \[Kappa]02] /. s[q0]]^2) - 1/2
Then you can call
NMaximize[{mueff[x, (32 Pi)^2, 30.5 Pi], 0 < x < 1.5}, x,
Method ->...]
directly on mueff without using Interpolation. Should be more accurate.
3. If you notice the "s[(q0_)?NumericQ] :=
s[q0] = ...", that's called cacheing a function value. Basically, the first time s[q0] is called with, say, q0=(32 Pi)^2, the NDSolve is called and the result is stored in s[(32 Pi)^2]. Any time s[(32 Pi)^2] is called, the stored value is returned without using NDSolve. It's useful if you're going to use the same function value many times, as will happen with NMaximize. It can speed things up.
URL: http://www.wolfram.com/learningcenter/tutorialcollection/ConstrainedOptimization/ConstrainedOptimization.pdf, |
|