I came across the following question:

What is the mean distance between two points in the unit square?

Disclaimer: I would very much appreciate not getting hints regarding how to solve this problem, but rather I would like to get help with the path I chose.

It is easy to solve this problem numerically. Either with Monte Carlo, or by integrating $$ \int_0^1 \int_0^1 \int_0^1 \int_0^1 \sqrt{(x_1-x_2)^2+(y_1-y_2)^2} dx_1 dx_2 dy_1 dy_2$$ The result for the mean distance then becomes $\approx 0.52$. However, I don't like this approach is I consider this somehow to be cheating.

So here is what I came up with: We have $x_1,x_2,y_1,y_2 \sim \mathcal{U}[0,1]$. I can then compute the distribution for $d_x= x_1-x_2$ to be $f_{d_x}(s) = 2-2s$. I would now like to compute the distribution for $d_x^2$. Using that distribution, I would then like to compute the distribution for $d_x^2+d_y^2$ and then try to compute the distribution for $\sqrt{d_x^2+d_y^2}$. However, I'm stuck with computing the distribution for $d_x^2$. I came across the Wikipedia article for the product distribution, stating for $Z=XY$ the distribution is $$ f_z(s) = \int f_X(s') f_y(s/s')\frac{1}{|s'|} ds'$$ which I cannot really follow. For my understanding, I would only need to compute $$ f_z(s) = \int f_X(s') f_y(s/s') ds'$$ Furthermore, my situation is different, as $Y$ and $X$ are not independent, since they are the same. With some educated guesses, it seems to me, that the distribution for $d_x^2$ could be given by $$ f_{d_x^2}(s) = \frac{2-\sqrt{s}}{s} $$ I came to this result, by comparing a histogram with some functions I constructed. But: This function is not a pdf, since it is not integrable on $[0,1]$.

So here is my question:

Given a distribution $f_x$ of a random variable $x$, where $f_x:[0,1]\rightarrow \mathbb{R}$ and $\int_0^1 f_x(x)dx=1$, how can I compute the distribution $f_{x^2}$.

Which would be the general setting. Or more concrete

Given a distribution $f_x$ of a random variable $x$, where $f_x(s) = 2-2s$, how can I compute the distribution $f_{x^2}$.

  • 2
    $\begingroup$ I see that you assume that the question is about uniformly distributed points and Euclidean distance - is it correct? $\endgroup$ – Tim Oct 10 '16 at 9:25
  • $\begingroup$ Yes, correct. The distance is the standard $l_2$ distance and points are uniformly distributed. $\endgroup$ – Thomas Oct 10 '16 at 9:28
  • 1
    $\begingroup$ Your description of the distribution of the difference $d_x = x_2 - x_1$ as $2-2s$ is incorrect. $\endgroup$ – wolfies Oct 10 '16 at 13:58
  • $\begingroup$ I'm sorry, it should be the distribution for $|x_2-x_1|$. Is this still wrong? $\endgroup$ – Thomas Oct 10 '16 at 14:25

Let $X = X_2-X_1$ denote the difference of two standard Uniform random variables, which is well-known to be a symmetric Triangular distribution on (-1,1). Similarly, let $Y = Y_2-Y_1$. By independence, the joint pdf of $(X,Y)$, say $f(x,y)$, is then:

(source: tri.org.au)

Then, the average distance between random points in the unit square is:

(source: tri.org.au)

where I am using the Expect function from the mathStatica package for Mathematica to do the nitty gritties, ArcSinh[1] denotes $\sinh^{-1}(1)$, and the answer to the first few decimal places is 0.521405 ...

P.S. The pdf of $U = X^2$ will be say $g(u) = \frac{1}{\sqrt{u}}-1$ defined on (0,1), but it is questionable as to whether making this transformation makes the integration any easier.

| cite | improve this answer | |
  • $\begingroup$ Thanks. I get the argument, that $f(x,y)=(1-|x|)(1-|y|)$. I think the "nitty gritties" is what I want to understand. Am I correct, that Expect[Sqrt[x^2+y^2],f] evaluates $$ \int_{-1}^1\int_{-1}^1 \sqrt{x^2+y^2}f(x,y)dx dy \quad ?$$ $\endgroup$ – Thomas Oct 10 '16 at 14:29
  • $\begingroup$ Yuppity .... it has the advantage of reducing it down to 2 integrals, rather than 4. $\endgroup$ – wolfies Oct 10 '16 at 14:36
  • 1
    $\begingroup$ Thanks a lot, I very much appreciate your answer! While it is correct in terms of the question What is the mean distance? except for the P.S. it does not answer the actual question I posed. Maybe you could elaborate on the computation of $g(u)$ . You might be correct, that this does not make the computation easier, but I would like to see how far I could get. $\endgroup$ – Thomas Oct 10 '16 at 19:03

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.