D. Bailey, P. Borwein, and S. Plouffe (called "BBP") came up with this
formula for $\pi$:
$\pi=\sum\limits_{n=0}^\infty \frac{1}{16^n}\left(\frac{4}{8n+1}-\frac{2}{8n+4}-\frac{1}{8n+5}-\frac{1}{8n+6}\right)$
(from "Pi Unleashed," by J. Arndt and C. Haenel, p. 117).
Use a for loop of about 10 terms, and see how close this sum comes to $\pi$.
Now you try. Use this BBP sum to compute $\pi$! Try 100 terms! 1000!
Type your code here:
See your results here:
This code will not run! Fix the for-loop to run over your desired number of terms, and fix the term= line
to be the formula for each "term" in the sum (the $\frac{1}{16^n}\left(...\right)$ in the formula
above).
Here's another formula to try:
$\pi=\sum\limits_{n=1}^\infty\frac{1}{n^3}\left(\frac{-238}{n+1}+\frac{285/2}{2n+1}-\frac{667/32}{4n+1}-\frac{5103/16}{4n+3}+\frac{35625/32}{4n+5}\right)$
This one was found by Adamchik and Wagon in 1997 (see p. 227 of "Pi Unleashed).
Share your code
Show a friend, family member, or teacher what you've done!