Method

Let \(I = \int_{x=a}^b f(x)\,dx\), which according to Riemann is the same as \(I = \lim_{n \to \infty} \sum_{i = 0}^{n-1}f(a + i(b-a)/n)(b-a)/n\).

Now, let’s consider a sequence of random variables \((X_{n})\) with suport \(\chi = \{a, a + (b-a)/n, ..., a + i(b-a)/n\}\), which assumes probability \(1/n\) in each possibility. Being it so, we have that the expected value of some function \(f(x)\) is:

\[ E(f(X)) = \sum_{i = 0}^{n-1} f(a + i(b-a)/n)/n \Rightarrow I = \lim_{n \to \infty} E(f(X))*(b-a)\]

intuitively, we can see that as \(n \to \infty\) we have that \(X_{n} \displaystyle\to^{D} U_{(a,b)}\). That implies:

\[ I = \lim_{n \to \infty} E(f(X))*(b-a) \Rightarrow I = E(f(\lim_{n \to \infty}X_{n}))*(b-a) \Rightarrow I = E(f(U))*(b-a) \]

Such that \(U_{(a,b)}\).

We will use the Monte Carlo Integral to see that it does indeed converges to the expected area. We will want to create a function that will give us the whole experiment and the final area. For simplicity we will do this univariate integral to estimate a fourth part of the circle with radius r, and center (0,0), which is pi/4 or aprox. 0.78.

Creating our function to estimate

#Monte Carlo Integration over the fourth part of the above mentioned circle.

fourth_part_circ <- function(r = 1){
  
  #We will fix the numbers of iterations
  N = 1000
  
  set.seed('123')
  
  b = r #upper limit of our integral
  a = 0 #lower limit
  
  c <- tibble(
    Index = 1:N,
    U.x = runif(n = N, min = a, max = r),
    f_y = sqrt(r^2 - U.x^2),
    Sum = cumsum(f_y),
    M.C.Integral_ = (b-a)*Sum/Index
  )
  
  d <- list(history = c, integral = c$M.C.Integral_[N]) 
  
  return(d)
}

Plots

df <- fourth_part_circ()$history

M.C.Integral = df$M.C.Integral_

ggplot(df, aes(x = Index, y = M.C.Integral)) + 
  geom_line(color = 'blue') +
 #xlim(0, n) + ylim(0,1) +
  geom_hline(yintercept = pi/4, color = 'red') +
  ggtitle('Integral estimator of the fourth part of a circle', subtitle = 'M.C. Integral')

We see that it converges.