I had to write the answer on user's Anton Antonov special request.
We can speed up a little the code by using method SimulatedAnnealing
in NMinimize
function and adding PrecisionGoal
with low value.
f[x_?NumericQ, y_?NumericQ] := NMinimize[{Sin[a x y], 1 < a < 5}, {a},
PrecisionGoal -> 6, Method -> "SimulatedAnnealing"][[1]];
AbsoluteTiming[
NIntegrate[If[f[x, y] > 0, 1, 0], {x, 0, 1}, {y, 0, 1}, PrecisionGoal -> 2,
MaxRecursion -> 3]]
(* {58.8097, 0.922105} *)
Using code user's Anton Antonov on my machine gives output with time:
(*{192.335, 0.922105}*)
In the comment, what I wrote about method NelderMead
in NMinimize
.I don't know why gives a incorrect result.
Addition:
WithUsing information obtained from the book:Mathematica Navigator page: 749
I came to the conclusion, with good starting points NelderMead
gives a correct result.
f[x_?NumericQ, y_?NumericQ] :=
NMinimize[{Sin[a x y], 1 < a < 5}, {{a, 4, 5}}, PrecisionGoal -> 6,
Method -> "NelderMead"][[1]];
AbsoluteTiming[
NIntegrate[If[f[x, y] > 0, 1, 0], {x, 0, 1}, {y, 0, 1},
PrecisionGoal -> 2, MaxRecursion -> 3]]
(* {59.6583, 0.922105} *)