Question about the Monte Carlo Algortihm

57 Views Asked by At

I was reading the Monte Carlo algorithm for finding the area under a curve, say $y=f(x)$.

The algorithm considers, $0\le f(x)\le M$ over the closed interval $a\le x\le b$.

My question is,that why is it necessary for $f(x)\ge 0$ for the algorithm to work why can't it simply be $|f(x)|\le M$ ?

1

There are 1 best solutions below

0
On BEST ANSWER

Monte Carlo integration works by randomly choosing a large number of points $(x,y)$ within a rectangle of height $M$ whose bottom side is the segment [a,b], and computing what fraction of those points lie in the region "under the curve", i.e. having $y < f(x)$. If you tried this with $\int_{-\pi}^{\pi} \sin x \ dx$ (which equals $0$), you wouldn't get any "hits" for $x < 0$, and you'd get an answer of $2$. Of course you can adjust the algorithm to take negative areas into account, but maybe the book was just trying to show the idea and didn't want to fool with the details.