Question: Suppose you have a random variable $Z=X\_1+X\_2$, where $X\_1$ and $X\_2$ are distributed identically with the following probability distribution function (pdf):
$$
p(X\_i=x)=
\begin{cases}
 1-\frac{x}{2},& \text{if } 0\leq x\leq 2;\\
 0, & \text{otherwise.}
\end{cases}
$$

If I wanted to convolve these two distributions, I thought I could just take the integral
$$p(Z=z)=\int\_0^2{\left(1-\frac{z-t}{2}\right)\left(1-\frac{t}{2}\right)dt}$$

but that integral evaluates to $\frac{4}{3}-\frac{x}{2}$. Since $Z$ should be valid on the interval $0\le Z \le 4$ the pdf would look like:

[![pdf of p(z)](https://i.stack.imgur.com/KwLGQ.jpg)](https://i.stack.imgur.com/KwLGQ.jpg)

However, this doesn't make any sense. The pdf should never be negative. I've tried different bounds of integration, etc., with no luck. What am I missing here?

Answer: 
If $f(x)$ is the pdf of $X\_1$ and $X\_2$, then the convolution is
$$ f\_Z(z)=\int\_{-\infty}^{\infty}f(z-t)f(t)\;dt=\int\_0^2f(z-t)f(t)\;dt $$
since $f(t)$ is zero if $t<0$ or $t>2$.

However, you also have to take this fact into account for $f(z-t)$. For instance, if $z=1$ then the requirement $z-t\geq 0$ implies that we must have $t\leq 1$ in the integral. Similarly, if $z=3$ then $z-t\leq 2$ implies that $t\geq 1$. So you need to be more careful with your bounds before substituting in the definition of $f$.
Okay, I figured it out thanks to the answer by carmichael561. 

I knew I had to do something about changing bounds of integration, but was getting confused on how to do so. The trick is you have to split the function for $p(z)$ into two different convolutions:

$$p(z) = 
\begin{cases}
 \int\_0^z{p(z-t)p(t)} = z-\frac{z^2}{2}+\frac{z^3}{24},& \text{for } 0\leq z\leq 2\\
 \int\_{z-2}^2{p(z-t)p(t)} = \frac{8}{3}-2z-\frac{z^2}{2}+\frac{z^3}{24}, & \text{for } 2\le z\le 4
\end{cases}
$$

it's easy to check that these are a good probability distribution as their integral adds to 1:

[![enter image description here](https://i.stack.imgur.com/W30aw.png)](https://i.stack.imgur.com/W30aw.png)

Also, the probability distribution is continuous:

[![enter image description here](https://i.stack.imgur.com/5HD7s.png)](https://i.stack.imgur.com/5HD7s.png)

Here is an image of the probability distribution:

[![enter image description here](https://i.stack.imgur.com/qsjL1.jpg)](https://i.stack.imgur.com/qsjL1.jpg)