integrate_mc: Aproximate Integral Solution by Monte Carlo Method

Description Usage Arguments Value Examples

Description

Aproximate the solution of the integral of a function using Monte Carlo Method.

Usage

1
integrate_mc(func, interval, y_interval = NULL, n = 10000, plot = TRUE)

Arguments

func

either a regular function of x, eithe a character string representing the function to be integrated. Examples: function(x) x + 2 OR "x + 2"

interval

length 2 array, giving the x limits of the inegral.

y_interval

length 2 array, giving the y limits. Default is NULL: in this case the function calculate the minimum and maximum of the function whitin the interval.

n

integer representing the number of repetition of the Monte Carlo method. Default = 1e4.

plot

logical defining if the output should be plotted or not.

Value

a list fo 2 items: $plot which is the plot of the function and $solution with the value aproximating the exact solution of the integral.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
## Not run: 
  ff <- "x * sin(x^2)"
  xx <- c(0, 2 * sqrt(pi))
  yy <- c(-10, 10)
  nn <- 1e5

  integrate_mc(ff, xx, n = nn)

  sol <- integrate_mc(function(x) x * sin(x^2), xx, y_interval = yy, n = nn)
  sol[[2]]
  sol$solution

## End(Not run)

ravenroadresources/rmontecarlo documentation built on May 23, 2019, 3:06 p.m.