# 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)$ Oct 28, 2015 at 8:00
• $f(z-b)$ shifts $f(z)$ to the right and not to the left.
– zoli
Oct 28, 2015 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? Oct 28, 2015 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? Oct 28, 2015 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. Oct 28, 2015 at 19:54

$$\newcommand{\bbx}{\,\bbox[15px,border:1px groove navy]{\displaystyle{#1}}\,} \newcommand{\braces}{\left\lbrace\,{#1}\,\right\rbrace} \newcommand{\bracks}{\left\lbrack\,{#1}\,\right\rbrack} \newcommand{\dd}{\mathrm{d}} \newcommand{\ds}{\displaystyle{#1}} \newcommand{\expo}{\,\mathrm{e}^{#1}\,} \newcommand{\ic}{\mathrm{i}} \newcommand{\mc}{\mathcal{#1}} \newcommand{\mrm}{\mathrm{#1}} \newcommand{\on}{\operatorname{#1}} \newcommand{\pars}{\left(\,{#1}\,\right)} \newcommand{\partiald}[]{\frac{\partial^{#1} #2}{\partial #3^{#1}}} \newcommand{\root}[]{\,\sqrt[#1]{\,{#2}\,}\,} \newcommand{\totald}[]{\frac{\mathrm{d}^{#1} #2}{\mathrm{d} #3^{#1}}} \newcommand{\verts}{\left\vert\,{#1}\,\right\vert}$$ By definition, the answer is given by: \begin{align} &\bbox[5px,#ffd]{\left.\int_{0}^{a}{1 \over a} {\bracks{0 < z - x < b} \over b}\,\dd x \,\right\vert_{\ 0\ <\ a\ \leq\ b}} \\[5mm] = &\ {1 \over ab}\int_{0}^{a} \bracks{z - b < x < z}\,\dd x \\[5mm] = &\ {\bracks{z - b < 0} \over ab} \bracks{0 < z < a}\int_{0}^{z}\dd x \\[2mm] + &\ {\bracks{z - b < 0} \over ab} \bracks{z > a}\int_{0}^{a}\dd x \\[2mm] + &\ {\bracks{0 < z - b < a} \over ab} \bracks{z > a}\int_{z - b}^{a}\dd x \\[5mm] = &\ {\bracks{0 < z < a} \over ab}\,z + {\bracks{a < z < b} \over ab}\,a \\[2mm] + &\ {\bracks{b < z < a + b} \over ab} \,\pars{a + b - z} \\[5mm] \substack{0\ <\ a\ \leq\ b \,\,\,\,\,\,\,\,\,\, \\[1mm] {\LARGE =}} &\ \!\!\!\!\! \left\{\begin{array}{lcl} \ds{z \over ab} & \mbox{if} & \ds{z \leq a} \\[2mm] \ds{1 \over b} & \mbox{if} & \ds{a < z \leq b} \\[2mm] \ds{{1 \over b} + {1 \over a} - {z \over ab}} & \mbox{if} & \ds{b < z < a + b} \\[2mm] \ds{0} && \mbox{otherwise} \end{array}\right. \end{align} The following picture is a particular example with $$\ds{\color{red}{a = 1}}$$ and $$\ds{\color{red}{b = 2}}$$: 