mc_int: Simple Monte-Carlo integration

Description Usage Arguments Value Author(s) Examples

Description

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.

Usage

1
mc_int(x_range, fun, B, seed = 1291)

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 be integrated. It is assumed that x is used as the variable of interest.

B

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

seed

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

Value

A list containing the following attributes:

I

Estimated value of the integral

var

Estimated variance of the estimator

Author(s)

Stephane Guerrier

Examples

1
2
mc_int(x_range = c(0,1), fun = "x^2", B = 10^5)
mc_int(x_range = c(0,1), fun = "x^2*sin(x^2/pi)", B = 10^5)

dzc5426/inclassdemo documentation built on May 8, 2019, 6:52 p.m.