I made this for a final project for Advanced Statistical computing (Stat 207)
This app shows the many different ways we can estimate \(\pi\) by using Statistical methods.
We know that the probability of any two integers being coprime is \(6/\pi^2\) So we sample a pair of numbers from uniform distribution(we round the numbers in the pair to be an integer). So we have created a pseudo-random integer pairs.
The see how many of those pairs of numbers had a GCD = 1. We then take that number and divided by total the number of observations (pairs), N.
We then solve for pi by setting that result equal to \(6/\pi^2 = N\) So \(\pi = (6/N)^{0.5}\)
We can approximate pi by taking many samples a Normal Distribution N(0, pi) and taking the variances of those samples. And then taking the the mean of those variances to estimate pi.
We know that this integral equals pi:
\[\int^0_1 -6 * (\pi/7)(x^2 - 3x) dx\]
So we will use Monte carlo integration to approximate this integral.
We sample N times from a unif(0,1) dist
We then define the function you want to integrate h.x(x)
We then find the average of the function mean(h.x(x))
Then we divide by the length of the interval
The ratio of an area circle and a square is: \[\frac{\pi r^2}{4 r^2} = \frac{\pi}{4 }\]
We randomly sample x and y from uniform \((-1,1)\) If \(x^2 + y ^2 <= 1\) then the point is in the circle
The ratio of points in the circle multiplied by 4 \(\approx \pi\)