Consider the experiment where a pair of numbers (x,y) is chosen at random in the unit square; that is, x and y are uniform (0,1) random variables. What is the probability of (x,y) lying within the unit circle?

  • 2
    $\begingroup$ Where are you stuck in the resolution of this standard exercise? $\endgroup$ – Xi'an Mar 1 '15 at 19:46
  • $\begingroup$ I know the answer is pi/4, but I don't understand why..? $\endgroup$ – John Alperto Mar 1 '15 at 21:21
  • 1
    $\begingroup$ Think of areas... $\endgroup$ – usεr11852 Mar 1 '15 at 21:45
  • $\begingroup$ Although answers purely in terms of areas will work in this case (because the distribution is uniform) they will not enlighten anyone concerning the probabilistic idea this exercise is attempting to inculcate. A good answer in terms of probability calculations would show how the reasoning generalizes to non-uniform distributions. $\endgroup$ – whuber Mar 1 '15 at 21:50

Generally, if region $A$ is a measurable subset of the support of random variable $X$, then the probability of the event $X\in A$ is $P(A)=\int_{A} f(x)dx$, where $f(x)$ is the density function of $X$.

For bivariate uniform distribution, the joint density $f_{X,Y}(x,y)$ has the same value $c$ at all points $(x,y)$ in its support, so $$P\{(X,Y) \in A\} = \int_A f_{X,Y}(x,y)\, \mathrm dx\,\mathrm dy = c\cdot\int_A \, \mathrm dx\,\mathrm dy = c\cdot\text{area of}~ A.$$ In your case, we know $$1 = P\{(X,Y) \in \text{unit square}\} = c\cdot\text{area of unit square} = c\cdot 1 = c,$$ so $c=1$, and thus $$P\{(X,Y) \in (\text{unit circle }\cap \text{unit square})\}$$ $$= 1 \cdot \text{area of (unit circle}\cap \text{unit square}) = \frac{\pi*1^2}{4} = \frac{\pi}{4}$$

enter image description here

  • 2
    $\begingroup$ Or, alternatively, change the double integral for $P(A)$ to polar coordinates to get $$P(A)=\int_{r=0}^1\int_{\theta=0}^{\pi/4}1\cdot r\, \mathrm d\theta\,\mathrm dr =\frac{\pi}{2}\int_0^1 r\,\mathrm dr = \frac{\pi}{4}.$$ $\endgroup$ – Dilip Sarwate Mar 2 '15 at 5:03
  • 1
    $\begingroup$ Your claim that all points in the unit square have equal probability of being chosen is trivially true: $P\{(X,Y) = (x,y)\}$ equals $0$ for all $(x,y)$, not just the points in the unit square. Worse, $P\{(X,Y) = (x,y)\} = 0$ for any continuous random variable, not just for uniformly distributed random variables. In other words, the "probability" of all points in the unit square being the same does not justify the claim about the areas: you need to say that the density has the same value. I have edited your answer to reflect this but feel free to roll back the edit. $\endgroup$ – Dilip Sarwate Mar 3 '15 at 0:27
  • $\begingroup$ @DilipSarwate Thank you very much! You are right. I will follow your suggestions:) $\endgroup$ – JellicleCat Mar 3 '15 at 20:18

+1 @JellicleCat's answer. Just to give a quick code and visual example as @whuber asked. I code this in MATLAB but the generalization is quite trivial for most languages. As mentioned in the original questions comments take notice that we use uniform sampling. This procedure of calculating $\pi$ is an extremely basic example of Monte Carlo methods.

rng(1234) % Fix the random seed
N = 10^5; % Number of samples

x = rand(N,1); % N random variables in [0,1]
y = rand(N,1); % N random variables in [0,1]

d = x.^2 + y.^2; % Distance from (0,0) to point (x(j),y(j))

pointsInTheCircle = find(d <= 1);

numberOfPoints = numel(pointsInTheCircle);

pi = numberOfPoints/(N/4); 
disp(pi) % 3.1441 / Think what would make this more accurate 

plot(x(pointInTheCircle), y(pointInTheCircle), 'ko','MarkerSize',2);
title('Where is $\Pi$?')
axis square; 
grid on;
% Explain to yourself why they are some white spots between the black spots

Where is pi?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.