Acceptance-Rejection Method

As an example, consider the evaluation of the integral $$ \begin{equation*} I=\int_0^3\exp{(x)}dx. \end{equation*} $$ Obviously to derive a closed-form expression is much easier, however the integrand could pose some more difficult challenges. The aim here is simply to show how to implent the acceptance-rejection algorithm. The integral is the area below the curve \( f(x)=\exp{(x)} \). If we uniformly fill the rectangle spanned by \( x\in [0,3] \) and \( y\in [0,\exp{(3)}] \), the fraction below the curve obtained from a uniform distribution, and multiplied by the area of the rectangle, should approximate the chosen integral.