Pi Square Over 6
The Basel Problem
calc_pi <- function(n){
summation = 0
for (i in 1:n) {
summation = summation + 1/i^2
#print(sqrt(6*summation))
}
return(sqrt(6*summation))
}
pi_approx <- numeric()
pi_approx <- calc_pi(500000)
print(pi_approx)
## [1] 3.141591
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.