I have a question about monte carlo estimation of integrals. Suppose I am told to estimate using monte carlo, the integral: $$f(y) = \int_{0}^{y}\frac{4}{1+x^{2}}dx$$ I want to estimate $f(\infty)$. I know that with some calculation, the exact values are given by $\pi$ and $2\pi$. However, there is some confusion with respect to defining the bounds and area given that the interval is now $\infty$. With an upper bound, such as $f(1)$ for example, I know I can generate random points from $[0,1]$x$[0,4]$ but I'm a bit confused as to what I should do in this case for $f(\infty)$.
I am told that:
To deal with this, pick a value $x_{max}$ and approximate the integrand as zero for $x > x_{max}$. Keeping the number of samples fixed at 107, use semilogx
to plot the absolute error of your estimate as a function of $x_{max}$ for $x_{max}$ = $10^{0}, 10^{1}, 10^{2}, . . . , 10^{7}$.
The biggest problem is that I am having trouble visualizing how to set $x_{max}$ and the points. I would greatly appreciate it if someone could provide some help with respect to this as I am just barely grasping the understanding monte carlo estimation.
Thank you
You have $\int_0^\infty \frac{4}{1+x^2} dx = \int_0^y \frac{4}{1+x^2} dx + \int_y^\infty \frac{4}{1+x^2} dx$. Here $y$ is a parameter that you choose. To make this work by using the rejection sampling method that you are proposing, you need an analytical error estimate for the second term (because there is no uniform distribution on an infinite rectangle). A lower bound is of course zero; an upper bound is $\int_y^\infty \frac{4}{x^2} dx = \frac{4}{y}$. So you can calculate the original integral with an error tolerance of $\varepsilon$ by calculating the first piece to an accuracy of $\varepsilon/2$ with $y>\frac{8}{\varepsilon}$ (so that the second piece is also less than $\varepsilon/2$).