Advertisement
Guest User

Untitled

a guest
Apr 18th, 2020
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. `Manipulate[
  2. Column[{tog[n],
  3. Button["reset samples", {n = 1000,
  4. samphorm =
  5. Transpose[{RandomReal[{0, 3}, {10000}],
  6. RandomReal[{0, 2}, {10000}]}];
  7. sampcmc = 3 RandomReal[{0, 1}, {10000}];
  8. sampva = 3 RandomReal[{0, 1}, {10000}]}]}], {{n, 1000,
  9. "sample size"}, 200, 10000, 50, Appearance -> "Labeled"},
  10. Initialization :> {
  11. SeedRandom[12345];
  12. horm[n_] :=
  13. a = ListPlot[
  14. 4. 6 Accumulate[
  15. If[# == True, 1,
  16. 0] & /@ (#[[2]] <= 2 Sqrt[1 - (#[[1]])^2/9] & /@
  17. Take[samphorm, n])]/Range[n],
  18. PlotStyle -> {GrayLevel[0],
  19. PointSize[
  20. Which[n < 100, 0.007, n < 1000, 0.004, True, 0.004]]},
  21. PlotLabel -> Style[
  22. Grid[{
  23. {"Metoda hit-or-miss: czarne kropki"}, {"Metoda surowa \
  24. Monte Carlo: czerwone kropki"}, {"Metoda przeciwstawnych zmiennych: \
  25. niebieskie kropki"}}, Alignment -> Center, Spacings -> 0.3], "Label",
  26. 9], AxesOrigin -> {0, 8.5}, ImageSize -> {800, 600},
  27. Epilog ->
  28. Tooltip[{Opacity[0.5], Orange, Thickness[0.005],
  29. Line[{{0, 18.85}, {n, 18.85}}]}, "True area = 18.85"],
  30. PlotRange -> {{0, n}, {16.2, 20.6}}];
  31. cmc[n_] :=
  32. b = ListPlot[
  33. 4 6 Accumulate[( Sqrt[1 - #^2/9] & /@ Take[sampcmc, n])]/
  34. Range[n],
  35. PlotStyle -> {PointSize[
  36. Which[n < 100, 0.007, n < 1000, 0.004, True, 0.004]],
  37. Hue[1]}];
  38. mcva[n_] := (r1 =
  39. 4 6 Accumulate[( Sqrt[1 - #^2/9] & /@ Take[sampva, n])]/
  40. Range[n];
  41. r2 = 4 6 Accumulate[(
  42. Sqrt[1 - (3 - #)^2/9] & /@ Take[sampva, n])]/Range[n];
  43. c = ListPlot[(r1 + r2)/2,
  44. PlotStyle -> {Hue[0.7], PointSize[0.004]}]);
  45. tog[n_] := (horm[n]; cmc[n]; mcva[n];
  46. Show[a, b, c, ImageSize -> {800, 600}, ImagePadding -> 20]);
  47. samphorm =
  48. Transpose[{RandomReal[{0, 3}, {10000}],
  49. RandomReal[{0, 2}, {10000}]}];
  50. sampcmc = 3 RandomReal[{0, 1}, {10000}];
  51. sampva = 3 RandomReal[{0, 1}, {10000}];
  52. }]`
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement