One of the earliest examples of the Monte Carlo process was performed by Georges-Louis Leclerc, Comte de Buffon in the 18th century. Buffon’s experiment was conducted by dropping a needle onto a surface randomly. The surface was bisected by a series of equally spaced parallel lines. The length of the needle was exactly one half the distance between the parallel lines. Through some math, he was able to determine a relationship to when the needle touched one of the lines to the ratio of the circumference of a circle to its diameter (i.e. ) (Dupree and Fraley; 2002)

Another method for estimating using a random process involves using square and a circle. Say we have a unit circle (radius = R), inside a square of sides 2R x 2R where the sides of the square are tangent to the circle as presented in Figure 4.3.
The area for the square is:
The area for the circle is:
If we randomly sample points within the square, some of those points will fall within the circle. The number of points sampled will be proportional to the area. We can then set up a ratio where:
Solving for :
Because all four quadrants of the circle are the same, we can simplify the problem by just focusing on the positive (top-right) quadrant. If we plot the positive quadrant on x and y axis the result is the left side of Figure 4.4.

If we set the radius of the arc = 1, we see that, by the Pythagorean Theorem, the radius is given by:
We can then use a random sample of points with coordinates of x and y between 0 and 1 and evaluate if they are inside the circle if the following condition is true:
Now we can use Equations 4-4 and 4-6 to get a relationship.
This relationship is an approximation because the area is being represented by points. The more samples taken, the closer the approximation will be. As with any random process, we must evaluate the precision of the result. We can do this by measuring the standard deviation of Equation (4-7). The standard deviation is:
Where represents each individual calculation performed using Equation 4-6. This estimate for can be easily written into a Julia script that allows the user to vary the number of samples to get a value and a standard deviation. This script and the analysis of the results is presented in Example 4.1. (Dupree and Fraley; 2002)
Example 4.1
Write a Julia program that uses the positive quadrant for a unit circle inside a square with an area of 1 to estimate the value of . The script should calculate the estimate using random points selected from x = 0 to x = 1 and y = 0 to y =1. It should prompt the user for the number of samples and output the value for and the standard deviation of the measurement. Report the value and standard deviation for sample sizes from 1.0E4 to 1.0E10 and plot the results compared to the known value.
Solution: Open a new Jupyter Notebook with the Julia kernel. Use the procedures outlined in Chapter 2 to develop the following input:


Note that the relationship x=rand() uses an internal Julia function to assign a random number between 0 and 1 to the x variable. The program will prompt for the number of trials and output the value of and its standard deviation. The results for the trials from 1.0E4 to 1.0E10 are as follows:
| Number | Estimate | Standard |
|---|---|---|
| of Trials | of | Deviation |
| 1.00E+04 | 3.1312 | 1.6494E-02 |
| 1.00E+05 | 3.13872 | 5.1993E-03 |
| 1.00E+06 | 3.140008 | 1.6433E-03 |
| 1.00E+07 | 3.141692 | 5.1928E-04 |
| 1.00E+08 | 3.14183408 | 1.6420E-04 |
| 1.00E+09 | 3.141727868 | 5.1927E-05 |
| 1.00E+10 | 3.141605163 | 1.6422E-05 |
If we plot the results and compare them to the known value of and use the standard deviation as the error bars we get the following graph.
The results show how the number of trials increases the accuracy of the value and greatly reduces the error associated with the value. As the number of trials approaches 1.0E8, the error is so small, it cannot be seen beyond the size of the marker on the graph. Note that even at 1.0E4, the accepted value is within the error bar. It is also noted that the calculation time for 1.0E9 and 1.0E10 was significantly longer than for the lower order calculations.

References
Full bibliography- Dupree, S. A. and Fraley, S. K. (2002). A Monte Carlo Primer : a Practical Approach to Radiation Transport, Kluwer Academic/Plenum, New York. https://books.google.com/books?vid=ISBN0306467488
