Compute an approximation of the integral of the function f(x) with respect to dx in the range [a, b] by Monte-Carlo integration using uniform sampling.

# S3 method for MCI
plot(x, ...)

Arguments

x_range

A vector of dimension 2 used to denote the integration region of interest, i.e. [a, b].

fun

A string containing the function to integrated. It is assumed that x is used as the variable of interest.

B

A numeric (integer) used to denote the number of simulation.

seed

A numeric used to control the seed of the random number generated by this function.

Value

A list containing the following attributes:

I

Estimated value of the integral

var

Estimated variance of the estimator

Examples

mc_int(x_range = c(0,1), fun = "x^2", B = 10^5)
#> $I #> [1] 0.3322249 #> #> $var #> [1] 8.882763e-07 #> #> $fun #> [1] "x^2" #> #> $x_range #> [1] 0 1 #> #> $B #> [1] 1e+05 #> #> attr(,"class") #> [1] "MCI"
mc_int(x_range = c(0,1), fun = "x^2*sin(x^2/pi)", B = 10^5)
#> $I #> [1] 0.06281515 #> #> $var #> [1] 7.002655e-08 #> #> $fun #> [1] "x^2*sin(x^2/pi)" #> #> $x_range #> [1] 0 1 #> #> $B #> [1] 1e+05 #> #> attr(,"class") #> [1] "MCI"