I want to derive the CDF of an Erlang distribution, which is simply the sum of two IID exponentials. In the answer here, @SecretAgentMan derives the cumulative distribution function:
$$F_{S_2}(x) = \int_0^x\left(1-\text{e}^{-\lambda(x-x_1)}\right)\lambda \text{e}^{-\lambda x_1}dx_1$$ which he then states equals: \begin{equation}=\lambda^2 x \text{e}^{-\lambda x} \label{1}\end{equation}
However, I tried working out the integral myself and keep getting something different:
$$F_{S_2}(x) = \int_0^x (\lambda e^{-\lambda x_1} -\lambda e^{-\lambda x})dx_1$$
$$ = (1-e^{-\lambda x}) - \lambda x e^{-\lambda x}$$
This is decidedly different from the Erlang result above. I've been looking through my steps and can't spot an error. What am I missing?
I actually just realized the error. Instead of deleting the question, I figured I'd leave it in and answer it so that people there can be linked here. The integral above is indeed correct. The answer on the link I provided had an error. The expression he derived is the CDF. To convert to a PDF, we need to differentiate it.
$$f_{S_2}(x) = \frac{\partial}{\partial x}F_{S_2}(x)$$ $$ = \frac{\partial}{\partial x} (1-e^{-\lambda x} -\lambda x e^{-\lambda x})$$ $$ = \lambda e^{-\lambda x} - \lambda (x e^{-\lambda x}(-\lambda)+e^{-\lambda x})$$ $$ = \lambda^2 x e^{-\lambda x}$$