Monte Carlo Integration
set.seed(100)
true <- 3.5
n <- 10
samp <- runif(n = n, min = 0, max = 1)
gx <- 3*samp^2 + 5*samp
mean(gx)
n <- 100
samp <- runif(n = n, min = 0, max = 1)
gx <- 3*samp^2 + 5*samp
mean(gx)
n <- 1000
samp <- runif(n = n, min = 0, max = 1)
gx <- 3*samp^2 + 5*samp
mean(gx)
n <- 5e3
samp <- runif(n = n, min = 0, max = 1)
gx <- 3*samp^2 + 5*samp
plot.ts(cumsum(gx)/(1:n), ylab = "Running Average", xlab = "n")
abline(h = true, col = "red")
|
run
| edit
| history
| help
|
0
|
|
|