Question
1.Implement a MCM in R to estimate the value of pi as seen here: https://en.wikipedia.org/wiki/Pi#Monte_Carlo_methods Display the output of your code at N = 20,
1.Implement a MCM in R to estimate the value of pi as seen here:
https://en.wikipedia.org/wiki/Pi#Monte_Carlo_methods Display the output of your code at N = 20, 100, 200.
2.Compare and contrast von Neumann's random number generator (code is below) with the more modern linear congruential generator (LCG).
List at least 3 differences/similarities.
> vonNeumann <- function(x,n){
+ rx <- NULL
+ d <- max(2,length(unlist(strsplit(as.character(x),""))));
+ getNext <- function(x,d){
+ temp <- x2
+ tbs <- as.numeric(unlist(strsplit(as.character(temp),"")))
+ # to be split
+ tbs_n <- length(tbs);
+ diff_n <- 2*d - tbs_n;
+ dn <- ceiling(d/2)
+ ifelse(diff_n == 0, tbs <- tbs, tbs <- c(rep(0,diff_n),tbs)) + tbs_n <- length(tbs)
+ NEXT <- tbs[-c(1:dn,((tbs_n-dn+1):tbs_n))]
+ return(as.numeric(paste(NEXT,collapse="")))
+}
+ rx[1] <- x
+ for(i in 2:(n+1)) rx[i] <- getNext(rx[i-1],d)
+ return(rx)
+}
> vonNeumann(x=11,n=10)
[1]11121419362984 5 2 0 0 > vonNeumann(x=675248,n=10)
[1] 675248 959861 333139 341914 > vonNeumann(x=8653,n=100) [1] 8653 8744 4575 [30] 2545 4770 7529 [59] 4100 8100 6100 [88] 8100 6100 2100 1354 8333 4388 8100 6100 2100 6100 2100 4100 4100 8100 6100
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started