Skip to main content
. 2019 Mar 6;19(5):1134. doi: 10.3390/s19051134
Algorithm 1 Monte Carlo Approximation of Double Integral

     Input: N: the total number of trials in Monte Carlo estimation.

     Output: The approximation result of the predefined double integral abg(x)h(x)f(x,y)dydx.

  • 1:

    valid_points0                       ▹ for counting the number of points inside the valid x–y region.

  • 2:

    function_evaluations0                       ▹ for summing up individual evaluations of f(x,y).

  • 3:

    X a random number between a and b

  • 4:

    Y a random number between MIN{g(x)} and MAX{h(x)}, x[a,b]

  • 5:

    for i1,N do

  • 6:

        if g(X)<=Y and Y<=h(X) then            ▹ If the random point (X,Y) is located inside the valid x–y region.

  • 7:

            valid_pointsvalid_points+1

  • 8:

            function_evaluationsfunction_evaluations+f(X,Y)

  • 9:

        end if

  • 10:

    end for

  • 11:

    area(b-a)·(MAX{h(x)}-MIN{g(x)})·valid_points/N, x[a,b]  ▹ Estimating the area of the valid x–y region.

  • 12:

    volumearea·function_evaluations/valid_points      ▹ Note that the function was evaluated valid_points times.

  • 13:

    returnvolume                              ▹ The estimated volume as the double integral result.