I'm a undergraduate student now learning a graduate simulation course, and I met some problems.
The Professor ask us to sample this function by composition method. Its CDF and PDF are like:
$$
F(x)=1-e^{-x}-e^{-2x}+e^{-3x} \\
f(x)=-3e^{-3x}+2e^{-2x} +e^{-x}
$$
I found out the PDF has a negative term $-3x$, and I don't know how to deal with it.
P.S. The Professor taught us the examples but there're all positive terms.
thx btw.
Rewrite your density as $(e^{-x} - e^{-3x}) + 2(e^{-2x} - e^{-3x})$. Neither $e^{-x} - e^{-3x}$ nor $e^{-2x} - e^{-3x}$ are proper densities, but you can check that \begin{align} f_1(x) &= \tfrac{3}{2}(e^{-x} - e^{-3x}),\\ f_2(x) &= 6(e^{-2x} - e^{-3x}) \end{align} are. That means you can write your $f$ as \begin{align*} f(x) &= \tfrac{2}{3}f_1(x) + (2)(\tfrac{1}{6})f_2(x) \\ &= \tfrac{2}{3}f_1(x) + \tfrac{1}{3}f_2(x). \end{align*} So one possible composition method is:
The latter step is easy since you can use sums of two exponentially distributed variates. Generate $E$ and $E'$ as independent exponentially distributed, each with mean 1. If you need an $f_1$ return $E + \tfrac{1}{3}E'$. Otherwise $\tfrac{1}{2}E + \tfrac{1}{3}E'$ gives you an $f_2$.