Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

Let $X$ and $Y$ be i.i.d. random variables with Uniform $(0, 1)$ continuous distribution.
The problem is to find the expected value of the distance between X and Y.

My reasoning was, for all $(x, y) \in X \times Y$, any distance must be $0 \le |x - y| \le 1$, so we can consider two cases, $0 \le y - x \le 1$ and $0 \le x - y \le 1$.

So to find the expectated value of the distance, I would take the sum of the two integrals,

$$ \int_0^1 \int_{y-1}^1 (y - x) \; dx \; dy $$

$$ \int_0^1 \int_{x-1}^1 (x- y) \; dy \; dx $$

The first and second integrals each give $1/3$, so the answer I reached is $2/3$, whereas the correct answer for expected distance is $1/3$ and uses integrals over different limits of integration. I know what the correct answer says, but where am I going wrong here?

share|improve this question

3 Answers 3

up vote 4 down vote accepted

The setting up of the integrals was not correct. If $X$ and $Y$ are our random variables, we want to find $$\iint_{S} |x-y|\,dxdy,$$ where $S$ is the $1\times 1$ square. Draw that square. Now it is useful to break up this integral into two parts, by drawing the line $y=x$, which slices our square into two parts: (i) where $y\ge x$ and (ii) where $y\le x$.

To do (i), express as an iterated integral. If you wish to integrate first with respect to $x$, note that $x$ travels from $0$ to $y$. The travels of $x$ can be seen clearly in the picture. So for (i) we need $$\int_{y=0}^1\left(\int_{x=0}^y(y-x)\,dx \right)\,dy.$$

Because of symmetry, (ii) will give the same result.

There are a couple of problems with your integrals. First note that there has not even been an integration with respect to $y$. Secondly, the setting up of the limits has no clear connection to the geometry.

share|improve this answer
+1 yes those limits (i, ii) are the same given in the answer (not mine). What I'd like to find out, however, is why the setup of $ 0 \le (y - x) \le 1 $ and $0 \le (x - y) \le 1 $ cannot work or what is wrong with that reasoning. If it's possible to use that approach then how would you setup the proper integrals to express that? –  Not a NaN notha Aug 29 '12 at 21:25
@T.Webster: For the second integral, it is true that $0\le x-y\le 1$. But if you want to express as an iterated integral, and want to integrate first with respect to $x$, $x$ will travel from $y$ to $1$, and not from $y$ to $y+1$. For if we travel to $y+1$, we are beyond our square. Personal note: After a zillion years of teaching this sort of stuff, I still have to draw a picture. Not for the sake of the students, but because I can't get the answer right, and certainly can't be sure I am right, without a picture. –  André Nicolas Aug 29 '12 at 21:40
I did try to draw a picture the first time, but until I looked more closely didn't see that the math will just not work out with my choice of integration. While the expression $ 0 \le |x - y| \le 1$ is how I intuitively saw the answer, I don't see any upper bound on the integral that would make sense using the inequality $ |x - y| \le 1$ as a lower bound, since e.g. $(1 - y, y)$ can't work, since it would always span a length of $y - (1 - y) = 1$. –  Not a NaN notha Aug 29 '12 at 23:28

Edit: my previous answer was actually not correct, so I removed it completely.

I had said that you need to divide your integral results by 2, since they each represented half of the domain space. This is not correct; if the integrals' bounds are set up correctly and we are actually integrating over the correct areas, the fact that they individually account for only half of the domain will naturally be accounted-for.

The only error in your original approach is the setup of the integrals. So, draw the image of $[0,1]\times[0,1]$ as a visual aid, and work from there. The integrals corresponding to your two cases should be $$\int_{0}^{1}\int_{0}^{y}(y-x)dxdy$$ for the upper triangle, where $y>x$, and $$\int_{0}^{1}\int_{0}^{x}(x-y)dydx$$, where $x>y$. By symmetry these integrals will have the same value, so double the calculation from each. (each has value 1/6).

Sorry for the confusion.

share|improve this answer
thanks and +1. I like your answer because to me it helps explain where I went wrong from closer to my perspective. Could the conditions of domain space you mentioned on domain space (e.g. $P(x < y)=1/2$) be satisfied with the upper limit on the inner integrals? If so, what is the upper limit there? (Please see I updated my post because I left off the proper dx, dy from carelessness typing, but really had them in my work). –  Not a NaN notha Aug 29 '12 at 21:18
Apparently I was careless in typing my integrals as well (I had no upper limits!). The upper limits should both be 1 here as well. –  Kirk Boyer Aug 29 '12 at 21:26
Actually the limits on my inner integrals did not reflect the image I was describing at all. I've corrected them as well. –  Kirk Boyer Aug 29 '12 at 22:20
I really appreciate your answers, but I'm only allowed to choose one. –  Not a NaN notha Aug 29 '12 at 23:23
Don't worry about it :D I was wrong at first anyway, lol. I just wanted to make sure I didn't have a misleading answer that sounded correct. I upvoted Andre's answer, myself. –  Kirk Boyer Aug 29 '12 at 23:45

This is not really an answer to the question "Where am I going wrong here?" but rather an alternative way of approaching the problem to be solved that gives the answer quite easily.

$Z = |X-Y|$ is a non-negative random variable taking on values in $[0,1]$, and hence $$E[Z] = \int_0^{\infty} P\{Z > z\}\,\mathrm dz = \int_0^1 P\{Z > z\}\,\mathrm dz.$$ But, for $0 \leq z \leq 1$, $P\{Z > z\}$ is the probability that the random point $(X,Y)$ lies in one of two right-triangular regions of area $\frac{1}{2}(1-z)^2$ each. This is easiest to figure out if you follow André Nicolas's suggestion to draw a sketch: the triangles have vertices $(z,0), (1,0), (1,1-z)$ and $(0,z), (0,1),(1-z,1)$ respectively. Hence, $$E[Z] = \int_0^1 P\{Z > z\}\,\mathrm dz = \int_0^1(1-z)^2\,\mathrm dz = \left. \frac{-1}{3}(1-z)^3\right|_0^1 = \frac{1}{3}.$$

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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