# [SOLVED]Calculate probability

#### evinda

##### Well-known member
MHB Site Helper
Hello!!! Suppose that $X$ has the uniform distribution on the interval $[0,2]$ and $Y$ has the uniform distribution on the interval $[2,4]$. If $X,Y$ are independent, I want to find the probability that the difference $Y-X$ is $\leq 1$.

I have thought the following.

The density function of $X$ is

$$p_1(x)=\left\{\begin{matrix} \frac{1}{2} &, 0 \leq x \leq 2 \\ 0 & , \text{ otherwise} \end{matrix}\right.$$

while the density function of $Y$ is

$$p_2(x)=\left\{\begin{matrix} \frac{1}{2} &, 2 \leq x \leq 4 \\ 0 & , \text{ otherwise} \end{matrix}\right.$$

How can we find the probability that the difference $Y-X$ is $\leq 1$ ? Do we use the above density functions? #### Klaas van Aarsen

##### MHB Seeker
Staff member
Hey evinda !! Yep, we use those density functions.

$X$ and $Y$ have a so called joint probability distribution $f_{X,Y}(x,y)$.
If means that:
$$P(Y-X\le 1) = \iint_{y-x\le 1} f_{X,Y}(x,y)\,dx\,dy$$
And since they are independent, we have:
$$f_{X,Y}(x,y) = f_X(x)f_Y(y) = p_1(x)p_2(y)$$ #### Klaas van Aarsen

##### MHB Seeker
Staff member
Just for fun, here's the corresponding graph.

The blue area corresponds to the part where the joint probability density is non-zero.
And the red area corresponds to the part where $Y-X \le 1$. #### evinda

##### Well-known member
MHB Site Helper
Nice, thank you!!! 