Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions