Uncertainty calculation for calculating pi using Monte Carlo integration

googlygluon
Messages
2
Reaction score
0

Homework Statement


I wrote a code that calculates pi using accept&reject monte carlo integration. It picks -1000000000 pseudo-random points (x,y), and counts the number of points that fall within a unit circle (let's call that number k).

The ratio of k/ N (N = Number of trials = 1000000000) is equal to pi / 4 (the area of the circle / the area of the square around it).

I wish to find the variance so that I may present my result as 3.14158 +- [uncertainty].

The Attempt at a Solution



Now, since this is a random (pseudo random really, but anyway) process, the uncertainty should be 1 / sqrt(N). Am I mistaken? Do I have to calculate the variance for both x and y and use error propogation? Thanks in advance.
 
Physics news on Phys.org
The best way to estimate the uncertainty on your measurement would be to run the program several times, for various random seeds. This will give you a series of measurements of \pi, which you can then compute the mean and standard deviation of. The standard deviation should scale as the inverse square root of the number of trials.
 
The most exact way would be to use probability (assuming a true random uniform generator). Calculate the probability of finding a particular value of 'pi', the value where the probability falls to 1/e or 1/2 can be used as your error.

To calculate this probability, you can use the known probability of a random point being outside or inside the circle. For eg. with n random points, the probability of finding the value of pi as zero would be the case where all points fall outside, probabilty being (1 - area of circle/total area)^n

For other values there will be more than one case, but you should be able to generalize it and find an expression for any particular value of pi.

Note: when I say probability, I mean relative probability, relative to probability of getting value as 'pi'.
 
googlygluon said:
Now, since this is a random (pseudo random really, but anyway) process, the uncertainty should be 1 / sqrt(N). Am I mistaken? Do I have to calculate the variance for both x and y and use error propogation? Thanks in advance.

The uncertainty scales as 1/sqrt(N), but the proportionality factor is not 1.

We're trying to find the standard deviation of a binomial distribution with n samples, where the two outcomes are "inside the circle" and "outside the circle". It's just sqrt(npq), where p is the probability of a certain point being inside the circle (which is pi/4), and q is the probability of the point being outside.

This means that, with n samples, n*pi/4 +- sqrt(npq) will be inside the circle. Dividing the equation by the relevant constant will give you the right bounds on pi.
 
Mute said:
The best way to estimate the uncertainty on your measurement would be to run the program several times, for various random seeds. This will give you a series of measurements of \pi, which you can then compute the mean and standard deviation of. The standard deviation should scale as the inverse square root of the number of trials.

Bear in mind that this is the only method mentioned above which doesn't require you to already know the value of pi.
 
Thanks everyone, I appreciate your help.
 
Thread 'Need help understanding this figure on energy levels'
This figure is from "Introduction to Quantum Mechanics" by Griffiths (3rd edition). It is available to download. It is from page 142. I am hoping the usual people on this site will give me a hand understanding what is going on in the figure. After the equation (4.50) it says "It is customary to introduce the principal quantum number, ##n##, which simply orders the allowed energies, starting with 1 for the ground state. (see the figure)" I still don't understand the figure :( Here is...
Thread 'Understanding how to "tack on" the time wiggle factor'
The last problem I posted on QM made it into advanced homework help, that is why I am putting it here. I am sorry for any hassle imposed on the moderators by myself. Part (a) is quite easy. We get $$\sigma_1 = 2\lambda, \mathbf{v}_1 = \begin{pmatrix} 0 \\ 0 \\ 1 \end{pmatrix} \sigma_2 = \lambda, \mathbf{v}_2 = \begin{pmatrix} 1/\sqrt{2} \\ 1/\sqrt{2} \\ 0 \end{pmatrix} \sigma_3 = -\lambda, \mathbf{v}_3 = \begin{pmatrix} 1/\sqrt{2} \\ -1/\sqrt{2} \\ 0 \end{pmatrix} $$ There are two ways...
Back
Top