Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- `Manipulate[
- Column[{tog[n],
- Button["reset samples", {n = 1000,
- samphorm =
- Transpose[{RandomReal[{0, 3}, {10000}],
- RandomReal[{0, 2}, {10000}]}];
- sampcmc = 3 RandomReal[{0, 1}, {10000}];
- sampva = 3 RandomReal[{0, 1}, {10000}]}]}], {{n, 1000,
- "sample size"}, 200, 10000, 50, Appearance -> "Labeled"},
- Initialization :> {
- SeedRandom[12345];
- horm[n_] :=
- a = ListPlot[
- 4. 6 Accumulate[
- If[# == True, 1,
- 0] & /@ (#[[2]] <= 2 Sqrt[1 - (#[[1]])^2/9] & /@
- Take[samphorm, n])]/Range[n],
- PlotStyle -> {GrayLevel[0],
- PointSize[
- Which[n < 100, 0.007, n < 1000, 0.004, True, 0.004]]},
- PlotLabel -> Style[
- Grid[{
- {"Metoda hit-or-miss: czarne kropki"}, {"Metoda surowa \
- Monte Carlo: czerwone kropki"}, {"Metoda przeciwstawnych zmiennych: \
- niebieskie kropki"}}, Alignment -> Center, Spacings -> 0.3], "Label",
- 9], AxesOrigin -> {0, 8.5}, ImageSize -> {800, 600},
- Epilog ->
- Tooltip[{Opacity[0.5], Orange, Thickness[0.005],
- Line[{{0, 18.85}, {n, 18.85}}]}, "True area = 18.85"],
- PlotRange -> {{0, n}, {16.2, 20.6}}];
- cmc[n_] :=
- b = ListPlot[
- 4 6 Accumulate[( Sqrt[1 - #^2/9] & /@ Take[sampcmc, n])]/
- Range[n],
- PlotStyle -> {PointSize[
- Which[n < 100, 0.007, n < 1000, 0.004, True, 0.004]],
- Hue[1]}];
- mcva[n_] := (r1 =
- 4 6 Accumulate[( Sqrt[1 - #^2/9] & /@ Take[sampva, n])]/
- Range[n];
- r2 = 4 6 Accumulate[(
- Sqrt[1 - (3 - #)^2/9] & /@ Take[sampva, n])]/Range[n];
- c = ListPlot[(r1 + r2)/2,
- PlotStyle -> {Hue[0.7], PointSize[0.004]}]);
- tog[n_] := (horm[n]; cmc[n]; mcva[n];
- Show[a, b, c, ImageSize -> {800, 600}, ImagePadding -> 20]);
- samphorm =
- Transpose[{RandomReal[{0, 3}, {10000}],
- RandomReal[{0, 2}, {10000}]}];
- sampcmc = 3 RandomReal[{0, 1}, {10000}];
- sampva = 3 RandomReal[{0, 1}, {10000}];
- }]`
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement