[Math] Let $X$ and $Y$ be independent random variables, uniformly distributed in the interval $[0, 1]$. Find the CDF and the PDF of $|X − Y|$.

probabilityprobability distributions

So this what I have:
\begin{align}
\ F_{z}(Z) &= P (Z<z) \\\
\ &= P( |X-Y| < z)\\
\ &= P(-z < X-Y < z) \\
\ &= P(-z+y<X<z+y)\\
\ &=F_x(z+y)-F_{x}(-z+y) = ?
\end{align}

As for the pdf it is just:

\begin{align}
f_{z}(Z)=f_{x}(z+y)+f_{x}(-z+y)
\end{align}

Best Answer

Consider the unit square $\Omega = [0,1]^2$. $|X-Y|$ is directly proportional to the distance from the diagonal from the diagonal $X = Y$. The event $\{|X - Y| \le z\}$ is represented by the red region. For all $d \in [0,1]$,

The CDF is the area of the $\color{red}{\text{red region}}$. $$F_Z(d) = P(\color{red}{|X - Y| \le d}) = 1 - (1-d)^2 = 2d - d^2$$

Differentiating the CDF with respect to $d$ on $(0,1)$ gives the PDF. $$f_Z(d) = F_Z'(d) = 2 - 2d.$$

enter image description here