Exercise 19.1

Exercise 19.1#

In Exercise 11.5 you were tasked with approximating \(\pi\) using a Monte-Carlo method. Here you are tasked with determining the standard uncertainty of your approximation using a Type A uncertainty analysis. Before that, here is a recap of the problem:

The area of a circle (\(A_\circ\)) can be approximated by generating \(N\) random points inside a square region (with area \(A_square\)) containing this circle, counting how many points fall inside the circle \(N_circle\) and using this in the relation:

\[ \frac{N_\circ}{N} \approx \frac{A_\circ}{A_\square} \]

Considering the equation for the area of a circle:

\[ A_\circ = \pi r^2 \]

we can estimate \(pi\):

\[ \pi \approx \frac{A_\square}{r^2} \frac{N_\circ}{N} \]

Question 1#

If you haven’t already done so for Exercise 11.5, write a program that takes a user input for \(N\) and prints an approximation for \(pi\). Run the program a few times for the same value of \(N\); do you notice the value changing?

Question 2#

If we consider our approximation of \(\pi\) from Question 1 as a single “measurement”, then we can apply a Type A uncertainty analysis to a set of \(n\) of these measurements. Modify your program to take an user inputs for \(N\) (the number of random points to use for each \(\pi\) approximation) and \(n\) (the number of \(\pi\) approximations) and outputs the following:

  • A printed message of the best approximation of \(\pi\) (mean of the set of \(\pi\) approximations) and the standard uncertainty (standard deviation of the mean)

  • A plot with:

    • A histogram of the set of \(\pi\) approximations

    • A normal distribution (normalized Gaussian) using the mean and standard deviation of the set of \(\pi\) approximations

    • Your best approximation (mean) of \(\pi\) (e.g. using a vertical line)

    • The value of \(\pi\) provided by NumPy (numpy.pi), which is determuined to floating point precision (e.g. using a vertical line)

    • The interval of one standard deviation about the mean (the standard deviation of the set of \(\pi\) approximations) (e.g. using two vertical lines or a fill of the Gaussian in this region)

    • The interval of one standard uncertainty about the mean (the standard deviation of the mean of \(\pi\) approximations) (e.g. using two vertical lines or a fill of the Gaussian in this region)

Do you notice a difference between the standard uncertainty interval and the standard deviation interval? Remember that the standard uncertianty is (an estimate of) the standard deviation of the mean, not the standard deviation of the set of measurements.

Question 3#

To explore what is meant by “the standard deviation of the mean, not the standard deviation of the measurements, generate a set of \(m\) best approximations and standard uncertainties of \(\pi\). Modify your program to take user inputs for \(N\) (the number of random points to use for each \(\pi\) approximation), \(n\) (the number of \(\pi\) approximations to generate for each best approximation and standard uncertainty) and \(m\) (the number of best approximations and standard uncertainties to generate).

Use the set of best approximations of \(\pi\) to create a plot with:

  • A histogram of the set of best approximations of \(\pi\)

  • A normal distribution using the mean and standard deviation of the set of best approximations of \(\pi\)

  • The mean of the best approximations of \(pi\) (e.g. using a vertical line)

  • The value of \(\pi\) provided by NumPy (e.g. using a vertical line)

  • The interval of one standard deviation about the mean (using the standard deviation of the set of best approximations) (e.g. using two vertical lines or a fill of the Gaussian in this region)

  • The interval of the average standard uncertainty about the mean (mean value of the set of standard uncertainties for the best approximations) (e.g. using two vertical lines or a fill of the Gaussian in this region)

How does the difference between the (mean) standard uncertainty interval and the standard deviation interval compare to Question 2? Note that here the standard deviation is the standard deviation of the mean of \(\pi\) estimates, which is what the standard uncertianty is defined as.