I have two random continuous RV $X$ and $Y$ and the sum $Z=X+Y$. I am trying to derive the pdf from the first principle but somehow I could not get the results to agree.
--
Let $Y\sim\mathcal{U}(0,1)$ and $X$ be a CRV with the pdf $f_X(x) = 2x$ with the support $[0, 1]$.
We have \begin{align} F_Z(z) &= \Pr(Z\le z) = \Pr(X+Y\le z)\\ &= \int_{y=0}^{1}\int_{x=0}^{z-y} f_{XY}(x,y) \ dxdy\\ &= \int_{y=0}^{1}\int_{x=0}^{z-y} f_{X}(x)f_Y(y) \ dxdy\\ &= \int_{y=0}^{1}\int_{x=0}^{z-y} 2x \ dxdy \end{align}
Now here is where things get weird... \begin{align} F_Z(z) &= \int_{y=0}^{1}\int_{x=0}^{z-y} 2x \ dxdy\\ &=\int_{y=0}^{1} (z-y)^2 \ dy\\ &= z^2 - z + \frac{1}{3} \end{align}
As you can see, the support for $Z$ should be $[0, 2]$ but clearly $F_Z(0)\ne0$ and $F_Z(2)\ne1$.
When I tried again with a different order of integration, I get \begin{align} F_Z(z) &= \int_{x=0}^{1}\int_{y=0}^{z-x} 2x \ dydx\\ &= \int_{x=0}^{1}2x(z-x) \ dx\\ &= z - \frac{2}{3} \end{align} which makes even less sense since I am integrating over the same triangle.
If anyone could point out my mistake I would really appreciate it!
You forgot the "support on $[0,1]$" when you simply write $2x$ in the integrand. It should be $2x\cdot1_{x\in[0,1]}$, which has the effect of changing the upper limit from $z-y$ to $\min\{1,\max\{z-y,0\}\}$.
\begin{align*} F_Z(z)&=\int_0^1\int_0^{z-y} 2x\cdot1_{x\in[0,1]}\,\mathrm{d}x\,\mathrm{d}y\\ &=\int_0^1\int_0^{\min\{1,\max\{z-y,0\}\}} 2x\,\mathrm{d}x\,\mathrm{d}y\\ &=\int_0^1\min\{1,(\max\{z-y,0\})^2\}\,\mathrm{d}y\\ &=\dots \end{align*}