# Finding PDF of sum of 2 uniform random variables

I need help understanding the question and its solution below.

Suppose that X is uniformly distributed in [0,a] and Y is uniformly distributed in [0,b], $0 < a \le b$, and that X and Y are independent. Find the PDF of $Z=X+Y$.

The solution is as follows.

For simplicity, define the unit square pulse

$$q(t) = u(t) - u(t-1)$$

where u(t) is the unit step function. Then the PDFs of X and Y are

$$f_X(x) = \frac{1}{a} q(\frac{x}{a})$$ $$f_Y(y) = \frac{1}{b} q(\frac{x}{b})$$

The PDF of Z is the convolution of $f_x$ and $f_Y$. i.e.

$$f_Z(z) = \int_{-\infty}^{\infty}\frac{1}{ab}q(\frac{\tau}{a})q(\frac{z-\tau}{b})d\tau$$

Therefore,

\begin{equation} f_Z(z) = \frac{1}{ab}\begin{cases} z, & \text{if $0<z\le a$}.\\ a, & \text{if $a<z\le b$}.\\ a+b-z, & \text{if $b<z\le a+b$}.\\ 0, & \text{elsewhere}.\\ \end{cases} \end{equation}

I have a few questions.

(1) How is the $f_X(x)$ and $f_Y(x)$ obtained? Why involve the unit step function instead of just taking $f_X(x) = \frac{1}{a}$ and $f_Y(x) = \frac{1}{b}$?

(2) I don't know how to get $f_Z$. I sketched out the 3 ranges for z.   I think my sketches must be wrong. My understanding of the convolution is that it is the resulting overlapping region between $f_X(x)$ and $f_Y(z-b)$ (the corresponding q functions seem to be a factor of $f_Y$ and $f_X$?), so I don't know how the overlapping region can be more than the red squares, bounded by $x = a$.

• For (1) the $q\left(\frac{x}{a}\right)$ term is equivalent to an indicator function taking the value $1$ in the interval $(0,a)$ and $0$ in the intervals $(-\infty,0)$ and $(a,\infty)$ – Henry Oct 28 '15 at 8:00
• $f(z-b)$ shifts $f(z)$ to the right and not to the left. – zoli Oct 28 '15 at 8:03

(1) How is the $f_X(x)$ and $f_Y(x)$ obtained? Why involve the unit step function instead of just taking $f_X(x) = \frac{1}{a}$ and $f_Y(x) = \frac{1}{b}$?

$$f_X(x) = \frac 1 a\;\mathbf q(\tfrac xa) = \frac 1 a \;\mathbf 1_{0\leq x\leq a} = \frac 1 a\begin{cases} 1 & : 0\leq x\leq a \\ 0 & :\text{otherwise}\end{cases}$$

The unit step function ensures the pdf is non-zero over the support and zero elsewhere.   Consider it as an indicator function.   This is useful in determining what bounds should be used for the convolution.

(2) I don't know how to get $f_Z$. I sketched out the 3 ranges for z.

\begin{align}f_Z(z) & = \int_{-\infty}^{\infty}\tfrac{1}{ab}\mathbf q\big(\tfrac{\tau}{a}\big)\mathbf q\big(\tfrac{z-\tau}{b}\big)\operatorname d\tau \\[1ex] & = \int_{-\infty}^{\infty}\tfrac{1}{ab}\mathbf 1_{0\leq \tau\leq a, 0\leq z-\tau\leq b}\operatorname d\tau \\[1ex] & = \mathbf 1_{0\leq z\leq a+b}\int_{-\infty}^{\infty}\tfrac{1}{ab}\mathbf 1_{0\leq \tau\leq a, z-b\leq \tau\leq z}\operatorname d\tau \\[2ex] & = \mathbf 1_{0\leq z\leq a+b}\int_{\max(0,z-b)}^{\min(a,z)}\tfrac{1}{ab}\operatorname d\tau \\[0ex] & = \mathbf 1_{0\leq z< a}\int_{0}^{z}\tfrac{1}{ab}\operatorname d\tau \\[0ex] & \quad + \mathbf 1_{a\leq z< b}\int_{0}^{a}\tfrac{1}{ab}\operatorname d\tau \\[0ex] & \quad + \mathbf 1_{b\leq z\leq a+b}\int_{z-b}^{a}\tfrac{1}{ab}\operatorname d\tau \\[2ex] & = \mathbf q\big(\tfrac{z}{a}\big)\int_{0}^{z}\tfrac{1}{ab}\operatorname d\tau \\[0ex] & \quad + \mathbf q\big(\tfrac{z-a}{b-a}\big)\int_{0}^{a}\tfrac{1}{ab}\operatorname d\tau \\[0ex] & \quad + \mathbf q\big(\tfrac{z-b}{a}\big)\int_{z-b}^{a}\tfrac{1}{ab}\operatorname d\tau \end{align}

• Thanks. Some follow-up questions - You included $1_{0 \le z \le a+b}$in the third line to make sure that the area of over the range of z? – Rayne Oct 28 '15 at 16:47
• Also, you integrate over $max(0,z-b)$ to $min(a,z)$ to ensure that the regions from $0 \le \tau \le a, z-b \le \tau \le z$ overlap? Specifically, it's $MAX(0,z-b)$ and $MIN(a,z)$ rather than say, $min(0,z-b)$ to $max(a,z)$ (just an example) for this reason? – Rayne Oct 28 '15 at 16:49
• Yes, that is right, @Rayne . When $0\leq\tau$ and $z-b\leq\tau$, that means $\max(0,z-b)\leq\tau$, so when $\tau<b$ then $\max(0,z-b)=0$ otherwise $\max(0,z-b)=z-b$. That gives the lower bounds of the integral and where to split the range of $z$ values to avoid having $\max$ in the bound. Likewise for the upper bounds. – Graham Kemp Oct 28 '15 at 19:54