# How to compute the limits for this uniform distribution problem?

I am trying to solve the following probability problem which involves uniform distribution:

An ambulance travels back and forth, at a constant speed, along a road of length L. At a certain moment of time an accident occurs at a point uniformly distributed on the road. (That is, its distance from one of the fixed ends of the road is uniformly distributed over (0, L).) Assuming that the ambulance’s location at the moment of the accident is also uniformly distributed, compute, assuming independence, the distribution of its distance from the accident.

The following is the suggested solution:

\begin{aligned} \text{Let } z &= |X-Y|, \\ \\ F_Z(z) &= P(|X-Y|<z) = P(-z<X-Y<z) \\ &=\int_0^L{P(y-z<X<y+z|Y=y)f_Y(y)}dy \\ &=\int_0^L{P(y-z<X<y+z)f_Y(y)}dy \\ &=\int_0^L{[F_X(y+z)-F_X(y-z)]f_Y(y)}dy \\ &=\int_0^z{\frac{(y+z)}{L}\frac{1}{L}}dy + \int_z^{L-z}{\frac{2z}{L}\frac{1}{L}}dy + \int_{L-z}^L{\frac{L+z-y}{L}\frac{1}{L}}dy \\ &=\cdots \end{aligned}

Problem source: here

I don't understand how the solution derived the limits for the sum of 3 integrals in the last step (as shown above). I also do not understand how they derived the terms for the 3 integrals from the second last step. Could someone please explain these to me?

• So do you know $F_X$? It is a piecewise function and thus you need to split the interval like that. – BGM Apr 12 '17 at 17:05

First, note that $0\leq |X-Y|\leq L$, and therefore $$F_Z(z) = P(|X-Y|<z)=\begin{cases}0, & z\leq 0\\ P(-z<X-Y<z), & 0<z\leq L\\ 1, & z>L\end{cases}$$ So, the next calculations are for $0<z\leq L$ only: \begin{aligned} F_Z(z) &= P(|X-Y|<z) = P(-z<X-Y<z) \\ &=\int_0^L{P(y-z<X<y+z|Y=y)f_Y(y)}dy \\ &=\int_0^L{P(y-z<X<y+z)f_Y(y)}dy \\ &=\int_0^L{[F_X(y+z)-F_X(y-z)]f_Y(y)}dy \end{aligned} For $y,z\in(0,L]$ write both $F_X(y+z)$ and $F_X(y-z)$: $$F_X(y+z)=\begin{cases}\frac{y+z}{L}, & 0<y+z\leq L\\ 1, & y+z>L\end{cases}=\begin{cases}\frac{y+z}{L}, & 0<y\leq L-z\\ 1, & L-z<y\leq L\end{cases}$$ $$F_X(y-z)=\begin{cases}0, & y-z\leq 0\\ \frac{y-z}{L}, & 0<y-z\leq L\end{cases}=\begin{cases}0, & 0<y\leq z\\ \frac{y-z}{L}, & z<y\leq L\end{cases}$$ For the case when $z<L-z$ or $z<L/2$, the interval $(0,L]$ is divided into three parts $$(0,L]=(0,z]\cup(z,L-z]\cup(L-z,L].$$ And the difference of this functions equals $$F_X(y+z)-F_X(y-z) = \begin{cases}\frac{y+z}{L}-0, & 0<y\leq z\\ \frac{y+z}{L}-\frac{y-z}{L}, & z<y\leq L-z\\ 1 - \frac{y-z}{L}, & L-z<y\leq L\end{cases}$$ The integrals below are just integrals over these regions: \begin{aligned} F_Z(z) &=\int_0^L{[F_X(y+z)-F_X(y-z)]f_Y(y)}dy \\ &=\int_0^z{\frac{(y+z)}{L}\frac{1}{L}}dy + \int_z^{L-z}{\frac{2z}{L}\frac{1}{L}}dy + \int_{L-z}^L{\frac{L+z-y}{L}\frac{1}{L}}dy \\ &=\cdots \end{aligned}
For the case when $z> L-z$ or $z>L/2$, the difference $F_X(y+z)-F_X(y-z)$ looks quite different: $$F_X(y+z)-F_X(y-z) = \begin{cases}\frac{y+z}{L}-0, & 0<y\leq L-z\\ 1-0, & L-z<y\leq z\\ 1 - \frac{y-z}{L}, & z<y\leq L\end{cases}$$ And the integrals will be \begin{aligned} F_Z(z) &=\int_0^L{[F_X(y+z)-F_X(y-z)]f_Y(y)}dy \\ &=\int_0^{L-z}{\frac{(y+z)}{L}\frac{1}{L}}dy + \int^z_{L-z}{\frac{1}{L}}dy + \int_{z}^L{\frac{L+z-y}{L}\frac{1}{L}}dy \\ &=\cdots \end{aligned} Fortunately, the result will be the same as for the first case, but...
• I think I got it: I split $|x-y|$ into $-(x-y)$ and $(x-y)$ and plot the graphs of $x-y = z$ and $y-x=z$ treating $z$ as a constant. Then I plot the graph and saw that the "shaded area" had to be split into two parts as the area after $L-z$ is bounded by the line $x = L$. – LanceHAOH Apr 12 '17 at 18:22
• I'm not sure that I understood you correctly, so I'll repeat: shaded should be exactly such an area as in the picture, only 1/3 should be replaced by $z$. This is the area between the lines $y=x-z$, $y=x+z$ treating $z$ as a constant. It's area is $L^2-(L-z)^2$, and the CDFfor $0<z<L$ equals to $F_Z(z)=1-\left(\frac{L-z}{L}\right)^2$. – NCh Apr 13 '17 at 0:39