Question: Please convert the following R code to Python 3: rm(list = ls()) set.seed(1001) options(digits = 8) g

Please convert the following R code to Python 3:

rm(list = ls()) set.seed(1001) options(digits = 8) g <- function(x){ return(4*sqrt(1-x^2)) }

U <- matrix(runif(100*1000),ncol = 1000,nrow = 100) gU <- g(U) Y <- apply(gU, 1, mean) sd <- apply(gU, 1, sd) est <- matrix(NA,5,1000) for(n in 1:1000){ for(j in 1:5){ est[j,n] <- mean(gU[j,1:n]) } } plot(1:1000,est[1,],type="l",ylim = c(2,4)) for(k in 2:5){ par(new=TRUE) plot(1:1000,est[k,],type="l",ylim = c(2,4)) } #With increase in n estimate converges to actual value of pi

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!