Skip to main content
added 395 characters in body
Source Link
Mariusz Iwaniuk
  • 16.4k
  • 1
  • 27
  • 46

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} *)

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:

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} *)

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:

Using 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} *)
added 395 characters in body
Source Link
Mariusz Iwaniuk
  • 16.4k
  • 1
  • 27
  • 46

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]]

(* {3858.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:

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} *)

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]]

(* {38.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.

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:

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} *)
deleted 1 character in body
Source Link
Mariusz Iwaniuk
  • 16.4k
  • 1
  • 27
  • 46

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]]

(* {38.8097, 0.922105} *)

Using code user's Anton Antonov on my machine gives output with time:

 (*{192.335, 0.922105}*)

In the commnentcomment, what I wrote about method NelderMead in NMinimize.I don't know why gives a incorrect result.

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]]

(* {38.8097, 0.922105} *)

Using code user's Anton Antonov on my machine gives output with time:

 (*{192.335, 0.922105}*)

In the commnent, what I wrote about method NelderMead in NMinimize.I don't know why gives a incorrect result.

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]]

(* {38.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.

Source Link
Mariusz Iwaniuk
  • 16.4k
  • 1
  • 27
  • 46
Loading