28 lines
1.2 KiB
Plaintext
28 lines
1.2 KiB
Plaintext
A '''Monte Carlo Simulation''' is a way of approximating the value of a function
|
|
where calculating the actual value is difficult or impossible. <br>
|
|
It uses random sampling to define constraints on the value
|
|
and then makes a sort of "best guess."
|
|
|
|
A simple Monte Carlo Simulation can be used to calculate the value for <big><math>\pi</math></big>.
|
|
|
|
If you had a circle and a square where the length of a side of the square
|
|
was the same as the diameter of the circle, the ratio of the area of the circle
|
|
to the area of the square would be <big><math>\pi/4</math></big>.
|
|
|
|
So, if you put this circle inside the square and select many random points
|
|
inside the square, the number of points inside the circle
|
|
divided by the number of points inside the square and the circle
|
|
would be approximately <big><math>\pi/4</math></big>.
|
|
|
|
|
|
;Task:
|
|
Write a function to run a simulation like this, with a variable number of random points to select.
|
|
|
|
Also, show the results of a few different sample sizes.
|
|
|
|
For software where the number <big><math>\pi</math></big> is not built-in,
|
|
we give <big><math>\pi</math></big> as a number of digits:
|
|
3.141592653589793238462643383280
|
|
<br><br>
|
|
|