Saturday, April 12, 2008

π

I wrote a calculator program a couple days ago to calculate pi.  It was a very interesting experiment!

I used a Taylor series to do this.  If you let f(x) = arctan(x), then if x = 1, f(x) = π/4.  So if you calculate the Taylor series for f(x), the sum as the number of terms approaches infinity will approach π/4.  Here's the series:

     ∞
y = Σ  (-1)^(n-1) * x^(2n-1) / (2n-1)
    n=1

Let x=1, and then multiply the series by 4.

I programmed my brother's TI-84 Plus SE (because that's much faster than my TI-83) to calculate about 10,000 terms of the series.  The calculator thought for about two minutes, and returned an answer that was only correct to four or five digits.  That gave me a new respect for supercomputers that can calculate billions of digits of pi!  I wish I knew of a way to plug this equation into our computer and see how it did.

1 comment:

Unknown said...

Hi Marissa. It's Mr. Lum. I am having so much fun perusing your blog. I am so proud of you! you are a super genius forming a taylor series to solve for PI. It doesn't hurt that your parents are super geniuses too.

Anyway, a good FREE programming language you can use is GNU C compiler for your PC.

I am not sure how much you know about C programming, but it is not too bad of a language to learn and I think you would enjoy its capabilities in solving Math problems quickly.

Let me know if you want more info on this. It is amazing to realize the computing power we have in our own homes that we sometimes take advantage of.

Another good tool is MathCAD or MatLab (but these are expensive).