Description Usage Arguments Value Examples
Aproximate the solution of the integral of a function using Monte Carlo Method.
1 | integrate_mc(func, interval, y_interval = NULL, n = 10000, plot = TRUE)
|
func |
either a regular function of x, eithe a character string representing
the function to be integrated. Examples: |
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 |
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. |
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.
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.