
Last chance! 50% off unlimited learning
Sale ends in
Integrate a function from 0 to 1 using the Sample Mean Monte Carlo algorithm
MC.samplemean(
FUN = function(x) x - x^2,
n = ani.options("nmax"),
col.rect = c("gray", "black"),
adj.x = TRUE,
...
)
the function to be integrated
number of points to be sampled from the Uniform(0, 1) distribution
colors of rectangles (for the past rectangles and the current one)
should the locations of rectangles on the x-axis be adjusted?
If TRUE
, the rectangles will be laid side by side and it is
informative for us to assess the total area of the rectangles, otherwise
the rectangles will be laid at their exact locations.
other arguments passed to rect
A list containing
the Uniform random numbers
function values evaluated at x
number of points drawn from the Uniform distribtion
the estimated value of the integral
Sample Mean Monte Carlo integration can compute
by drawing random numbers
The height of the
Examples at https://yihui.org/animation/example/mc-samplemean/