Description Usage Arguments References See Also Examples
Monte-Carlo integration using the hit and miss method
1 | hit_miss(ftn, a, b, f.min, f.max, n)
|
ftn |
a function of single variable. |
a |
lower bound of the integration. Must be finite. |
b |
upper bound of the integration. Must be finite and assume b > a. |
f.min |
lower bound of the ftn over the range [a,b]. |
f.max |
upper bound of the ftn over the range [a,b]. |
n |
number of samples used in the estimation. |
Owen Jones,Robert Maillardet,Andrew Robinson (2014).Introduction to Scientific Programming and Simulation Using R ; Second Edition
1 2 3 4 5 6 7 | ## We see that the number of repetitions n needs to be very large
## in order to get even just two decimal places of accuracy.
f <- function(x) return(x^3 - 7 * x^2 + 1 )
hit_miss(f, 0, 1, -6, 2, 1000)
hit_miss(f, 0, 1, -6, 2, 10000)
hit_miss(f, 0, 1, -6, 2, 100000)
hit_miss(f, 0, 1, -6, 2, 1000000)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.