Solving Double Integral in calculating the expected value of the absolute value of the difference between two independent uniform random variables? The answer to the question is shown here, unfortunately I am having trouble evaluating the double integral shown below which is used to get the answer.
Can someone please explain how to solve the integral to get the answer shown?
$$
\operatorname E[|X_1-X_2|]=\int_0^2\int_0^2 \frac{|x_1-x_2|}{4} \, \mathrm{d}x_2 \, \mathrm{d}x_1 =\frac{2}{3}.
$$
Expected value of the absolute value of the difference between two independent uniform random variables?
Is the expression below correct?
$
\operatorname E[|X_1-X_2|]=\int_0^2\int_0^{x_1} \frac{|x_1-x_2|}{4} \, \mathrm{d}x_2 \, \mathrm{d}x_1 + \int_0^2\int_{x_1}^{2} \frac{|x_1-x_2|}{4} \, \mathrm{d}x_2 \, \mathrm{d}x_1 =\frac{2}{3}.
$ 
Can you explain how you came by the limits you suggested?
I know that for the case $E(X+Y)$ you use convolution which would give you the limits that you used. However, I would have expected that the limits would change for $|E(X-Y)|$ as the convolution is running in the opposite direction but apparently the limits stayed the same?
Tackling the integrals in order from left to right:  
$
\int_0^2\int_0^{x_1} \frac{|x_1-x_2|}{4} \, \mathrm{d}x_2 \, \mathrm{d}x_1
$
$
\int_0^2 \frac{|x_1x_2-x_2^2/2|}{4} |_0^{x1} \, \mathrm{d}x_1
$
$
\int_0^2 \frac{|x_1^2-x_1^2/2|}{4}  \, \mathrm{d}x_1
$
$
\int_0^2 \frac{|x_1^2|}{8}  \, \mathrm{d}x_1
$
$
\frac{|x_1^3|}{24} |_0^2
$
$
\frac{|8|}{24} 
$
Obviously $\frac{8}{24}$ is $\frac{1}{3}$. Given that the numerator is always positive the abs sign is redundant so I can just take the solution to the first part to be $\frac{1}{3}$ is the reasoning correct?
$
\int_0^2\int_{x_1}^2 \frac{|x_1-x_2|}{4} \, \mathrm{d}x_2 \, \mathrm{d}x_1
$
$
\int_0^2 \frac{|x_1x_2-x_2^2/2|}{4} |_{x1}^2 \, \mathrm{d}x_1
$
$
\int_0^2 \frac{|2x_1-2| - |x_1^2 - x_1^2/2|}{4}  \, \mathrm{d}x_1
$
$
\int_0^2 \frac{|x_1^2/2 + 2x_1 - 2|}{8}  \, \mathrm{d}x_1
$
$
\frac{|x_1^3/3 + x_1^2 - 2 x_1|}{8} |_0^2
$
$
\frac{|8|}{24} 
$
Again assuming I can take $\frac{|8|}{24}$ to be $\frac{1}{3}$ which give $\frac{2}{3}$ over all.
 A: If $X_1$ and $X_2$ are uniformily distributed from U(0,2),
then $Z = |X_1-X_2|$ has a pdf of 
$P(Z=z) = \frac{1}{2}(2-z)$, $0\le z \le 2$
Thus $E(Z) = \int_{0}^{2} \frac{1}{2}z(2-z)dz$
$=\frac{2}{3}$
Easy Understanding of Convolution  The best way to understand convolution is given in the article in the link,using that 
I am going to solve the above problem and hence you could follow the same for any similar problem such as this with not too much confusion.
$Z = X-Y$ where X and Y are U(0,2).
I am going to define a new variable W where W is distributed according to U(-2,0)
Thus $Z = X - Y = X+ W$ where X is U(0,1) and W is U(-2,0).
Now I am going define the bounds
$t_{X_0} = -2$
$t_{X_1} = 0$
$t_{W_0} = 0$
$t_{W_1} = 2$
Thus $$f_Z(z) = 0, z \le t_{X_0}+t_{W_0} ,$$
$$f_Z(z) = \int_{max(t_{W_0}, t-t_{X_1})}^{min(t_{W_1}, t-t_{X_0})} f_W(w)f_X(z-w)dw,    \text{     }     t_{X_0}+t_{W_0} \le z \le t_{X_1}+t_{W_1},$$
$$f_Z(z) = 0, z \ge t_{X_1}+t_{W_1} ,$$
These translate to the following:
$$f_Z(z) = 0, z \le -2 $$
$$f_Z(z) = \int_{max(0, z)}^{min(2, z+2)} f_W(w)f_X(z-w)dw,    \text{     }     -2\le z \le 2,$$
$$f_Z(z) = 0, z \ge 2 ,$$
$f_W(w) = \frac{1}{2}$ as $W$ is $U(-2,0)$.
$f_X(x) = \frac{1}{2} $ as $X$ is $U(0,2)$,
The middle one needs to be split into two intervals, and they are a) $-2\le z\le 0$, b) $0\le z\le 2$.
Thus 
$f_Z(z) = \int_{0}^{z+2}\frac{1}{4}dw = \frac{z+2}{4}$, $-2\le z\le 0$
$f_Z(z) = \int_{z}^{2}\frac{1}{4}dw = \frac{2-z}{4}$, $0\le z\le 2$
Sanity check is to find if $\int_{-2}^{2} f_Z(z) = 1$ which it is in this case You have to find the pdf of Z = |X-Y| and the only interval for this is $0\le z\le 2$ and the pdf is twice that of $2\frac{2-z}{4} = \frac{2-z}{2}$
and hence 
The pdf $\boxed{f_Z(z) = \frac{2-z}{2}, 0\le z \le 2}$
Goodluck
