Monte Carlo estimation of a constant?

166 Views Asked by At

I am currently learning monte carlo and I dont quite understand it. In the question I am given, I am asked to estimate $\pi$.

So I am to write a Matlab code that computes a numerical estimate of $\pi$ using N points with $D = [−1, 1]^{2}$ and r = 1. Plot the absolute error of your estimate as a function of N on a log-log scale using the loglog command, for N = 1, 10, 100, 1000.

So my question is this, in matlab to define the domain would I use rand(100,1) to generate the points ? My second question is I dont quite understand what I am supposed to integrate here. My prof says:

We know that the area of a circle C with radius r is $A_{C} = \pi(r^{2})$ . Now consider a domain $D$ of area $A_{D}$ that contains C (i.e., $C ⊂ D$). If we sample points in $D$ uniformly at random, then the fraction of points falling inside the circle, $N_{C}/N_{D}$, should approach the ratio $A_{C}/A_{D}$ as the number of points, N, grows large. Since we know $A_{D}$ and can measure $N_{C}/N_{D}$, we can estimate $A_{C}$ and thus we can estimate $\pi$ = $A_{C}/r^{2}$

So what does $A_{D}$ mean here ? Should I define it according to the area formula and the idea is that we don't know $C$?. I would appreciate if one could provide some help. Thank you

Edit:

enter image description here

enter image description here

1

There are 1 best solutions below

4
On BEST ANSWER

You need to pick points randomly in D. Then work out if the point lies inside or outside the circle (using distance formula). Repeat and keep track of what fraction are inside the circle. You can then multiple this fraction by the area of D (equal to 4) to get an estimate of $\pi$.

$A_D$ is the area of D. In your example the $2\times2$ square so area of 4.