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.
mc_int(x_range, fun, B, seed = 1291)
x_range | A |
---|---|
fun | A |
B | A |
seed | A |
A list
containing the following attributes:
Estimated value of the integral
Estimated variance of the estimator
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"