MC.hitormiss(FUN = function(x) x - x^2, n = ani.options("nmax"),
from = 0, to = 1, col.points = c("black", "red"), pch.points = c(20,
4), ...)
points
x1
integrate
, MC.samplemean
oopt = ani.options(interval = 0.2, nmax = ifelse(interactive(),
100, 2))
## should be close to 1/6
MC.hitormiss()$est
## should be close to 1/12
MC.hitormiss(from = 0.5, to = 1)$est
## HTML animation page
saveHTML({
ani.options(interval = 0.5, nmax = ifelse(interactive(),
100, 2))
MC.hitormiss()
}, img.name = "MC.hitormiss", htmlfile = "MC.hitormiss.html",
title = "Hit or Miss Monte Carlo Integration", description = c("",
"Generate Uniform random numbers", "and compute the proportion",
"of points under the curve."))
ani.options(oopt)
Run the code above in your browser using DataLab