Run Code  | API  | Code Wall  | Users  | Misc  | Feedback  | Login  | Theme  | Privacy  | Patreon 

Pi estimation


            
                
            
 run  | edit  | history  | help -1

textpi.est <- function(n){ x <- runif(n, -1, 1) y <- runif(n, -1, 1) z <- x^2 + y^2 f = c() for(i in 1:n){ if( abs(z[i]) <= 1){ f[i] <- 1 }else{ f[i] <- 0 } } qt1 = sum(f[f==1]) pi.est = qt1/n return(4*pi.est) }

pi.est(1000000)

  by  Asrarmushtaq111@gmail.com, 3 months ago




Please log in to post a comment.