106 - Madhava-Leibniz series for \pi

106 - Madhava-Leibniz series for \(\pi\)#

Implement a function to calculate \(\pi\) using the first N terms of the series:

\(\Large \displaystyle\frac{\pi}{4} = \displaystyle\sum_{k=0}^\infty \frac{(-1)^k}{2k+1} = 1 - \frac{1}{3} + \frac{1}{5} - \frac{1}{7} + \frac{1}{9} - \frac{1}{11} + \cdots\)

Tasks:

  • Make a plot of the result versus the number of terms included for the first 100 terms.

  • Make a plot of the difference of (four times) the series and the true value of \(\pi\) for the first 100 terms.

  • How many terms are needed to get within 0.01 of correct answer? 0.001 of the right answer? \(10^{-6}\) of the right answer? \(\frac{1}{129}\) of the right answer? Do you understand what you see?