Graph several pi approximations in C#


[pi approximations]

This example graphs pi approximations by combining the techniques described in the following two posts:

For each series, the program uses the series to generate approximations for π with 1, 2, 3, …, 9 terms. It then connects those approximations with a smooth curve so you can see how the series approaches π as the number of terms increases.

From the picture you can see that the Gregory-Leibniz approximation converges the slowest. The others all move quickly to values pretty close to π so you really can’t tell from the picture that the Newton series is closer than the Nilakantha series after 14 terms.

This graph doesn’t include 355 / 113 because on this scale it looks the same as the true value for π.

After 14 terms, the following list shows the different series values in increasing order order of accurracy.

  • Gregory-Leibniz
  • Nilakantha
  • Newton
  • Arcsine

That’s also the order of complexity for the series. For example, the Arcsine series is the most accurrate but it’s also by far the most complicated.

It’s not until 22 terms that the Newton series beats the single term 355 / 113.


Download Example   Follow me on Twitter   RSS feed   Donate




About RodStephens

Rod Stephens is a software consultant and author who has written more than 30 books and 250 magazine articles covering C#, Visual Basic, Visual Basic for Applications, Delphi, and Java.

This entry was posted in algorithms, geometry, graphics, mathematics and tagged , , , , , , , , , , , , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *