calcpi: Monte carlo simulation to estimate pi.

View source: R/calcpi.R

calcpiR Documentation

Monte carlo simulation to estimate pi.

Description

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.

Usage

calcpi(n.iters = 1e+05, viewcode = F)

Arguments

n.iters

the number of Monte Carlo iterations. Must exceed 1000.

viewcode

TRUE or FALSE (default) indicating whether to print the function code

Value

Monte Carlo based estimate of pi

Examples

# 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)




tessington/quantecol documentation built on June 1, 2025, 9:06 p.m.