I did a manipulate algorithm to see how Monte Carlo Integration precision works, using as example the Cauchy Function.
When Dynamic Updating is enabled, the resulting MC calculation keeps evaluating. Why?
funcCauchy[X_, A_] := Module[{x = X, a = A}, 1/(1 + (x/a)^2)];
Manipulate[
b = 2.;
a = -2.;
c = 1.5;
n = 0;
X = 0;
Y = 0;
data = Do[
X = RandomReal[{-2, 2}];
Y = RandomReal[{0, 1.5}];
fx = funcCauchy[X, 2];
If[Y < fx, n = n + 1],
Num];
TextCell[
Column[{{"resultado da Integração de f (x, a) = 1/(1 + (x/a)^2) é \
= ", Integrate[
1/(1 + (x/2.)^2), {x, -2,
2}]}, {"resultado da Integração por Monte Carlo, com N= ", Num,
" é igual a = ",
N[Integ = (b - a)*c *(n/Num), {Infinity, 6}]}}], FontSize -> 12,
TextAlignment -> Left, CellFrame -> True,
CellMargins -> {{300, 300}, {20, 20}}],
{{Num, 10, "N = N\[Degree]. de Rodadas"}, Appearance -> "Open", 10,
10^5, 100}, ContinuousAction -> False, ContentSize -> {700, 100}
]
Please, be free to improve this manipulate algorithm settings!
TrackedSymbols
? $\endgroup$Num
rather thannum
). You will also want to consider if any other symbols should trigger an update. $\endgroup$