Fang Talks

I do things on the internet!
16 01 13

Pi

Maths is full of interesting numbers.

Among those numbers, is pi. We all know and love (or hate, depends on your point of view) the cute little constant with which we can calculate all kinds of fancy things about our circles and spheres. It’s seemingly endless. Well, seemingly, it really is endless. 3.1415926~ it keeps going on. Irregular, but we can still calculate it!

There’s a bunch of nifty formulas one can use to calculate pi. Often-times you’ll have to repeat the formula with a different value (one which you just calculated), or just keep stretching the formula into infinity. For a school project, I decided to see if I could go and accurately calculate pi myself. I’m… kind of disappointed with the results so far.

One series you can use, is the Gregory-Leibniz series.
pi = 4/1 - 4/3 + 4/5 - 4/7 + 4/9 - 4/11 + ...~
It basically goes on like that. All you do is alternate add/subtract, and add 2 to the divisor. The longer you go on doing this, the more precise your calculation of pi becomes.
So far I’ve had the most success with this method, but it converges awfully slowly. (Meaning you need a lot of iterations to get somewhat precise.) Ten billion iterations in this series took my computer over 3.5 hours to complete, and the result I got was a mere eight decimal digits of accuracy (the same as with a billion iterations, oddly).

I’ve tried out other methods as well (there’s a lot, from the arcsine series to the Bailey-Borwein-Plouffe method (which is really awesome, by the way)), but my code isn’t working too well with those. I’m having a hard time putting some of those series or functions into Java code, especially with the need for BigIntegers and BigDecimals, since the numbers can (and need to) get really large.

I’ll keep working on it, I think. You guys’ll hear it when I make a breakthrough!
~ Fang

Comments

Post a comment

Your email will stay hidden, required field are marked with a *.

Experimental anti-spam. You only have to do this once. (Hint: it's "Fang")