calcpi | R Documentation |
Demonstration of example in 14.3.1 "What is pi". This uses Monte Carlo simulation uses the ratio of randomly drawn points that are in a circle of radius r to a square with length r.
calcpi(n.iters = 1e+05, viewcode = F)
n.iters |
the number of Monte Carlo iterations. Must exceed 1000. |
viewcode |
TRUE or FALSE (default) indicating whether to print the function code |
Monte Carlo based estimate of pi
# use a small number of iterations, likely get a poor estimate of pi
pi.est <- calcpi(n.iters = 1000)
# get a more robust estimate, but very slow
pi.est <- calcpi(n.iters = 10000000)
# run and view function code
pi.est <- calc.pi(printfun = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.