Monte-Carlo for Integrals

Let XX be a Random Variable with Uniform Distribution on (0,1)(0,1) and ff a continous function on [0,1][0,1] , then we can calculate the intergral from 00 to 11 of that function using the Arithmetic Mean as a Standard Estimator:

E(f(X))=01f(x)dx\mathbb{E}(f(X))=\int_0^1 f(x) d x

This approach is quite effective for high-dimensional integrals.

x = runif(100000)
mean(sin(x)) - integrate(sin, 0, 1)[1]$value
# 0.00026...