ticalc.org
Basics Archives Community Services Programming
Hardware Help About Search Your Account
   Home :: Archives :: News :: Feature: Calculating Pi

Feature: Calculating Pi
Posted by Nick on 14 March 2000, 03:57 GMT

I hope everyone is having a very happy Pi Day! In case you don't know, today (March 14) is Pi Day. In honor of this, this week's feature will be in homage of our favorite irrational number. Andy Selle has written us a feature regarding pi and its origins.

Check out the updated version instead. It is available in PDF or HTML


Calculating pi: an explorative tour

Andrew Selle (aselle@ticalc.org)


Abstract:

A look at calculating pi with a TI graphing calculator. This article goes through a variety of methods for finding the ever closer decimal approximation of our favorite trancendental number.



Introduction

pi is a very interesting number. We are first introduced to it early in our grade-schooling as a component of the formulas A=pi*r^2and C=2*pi*r. It seems odd to us that we need to use this number. Where did it come from? How did we ever figure it out? These our questions that I hope to address and perhaps answer. However, the major point of this article is to explore methods of calculating pi using a Texas Instruments graphing calculator (and perhaps a few computers).


History

The history of pi is a long one. The first significant advancement in the understanding of pi was the Ancient Greeks. They came up with the concept of inscribing a polygon inside a circle. As you added more sides to the polygon, the polygon became closer and closer to a circle. By taking the ratio between the polygon's area to the circle's area, you could find pi Thus, the first method of calculating pi was born.
During the middle ages, time for calculating pi was not readily available. Even when it was, the polygon inscribing method was very slow and painstaking. It was eventually discovered that an infinite series approximating arctan was a good means to calculate pi. Once the computer was invented, pi was quickly calculated to many places.

This history is in no way complete, but it covers the major ideas.


Math

Obviously, a lot of math is involved in calculating pi. I will derive all my mathematics as completely as possible, but don't be afraid to skip the derivations if you are not interested. I will highlight the important results found to make this easy.

Monte Carlo Method

Derivation

One of my favorite methods, and one of the simplest to understand is the Monte Carlo method. I first ran into this method when I was learning BASIC for my Apple II. One sets up a square that is 2 by 2. One then inscribes a circle inside the square. Random points are then plotted repeatedly. For each point we add one to the variable n, and if the point is within the circle we add one to the variable i. Then to calculate we simply put together what we know. area(circle)=pi*r^2,areasquare = 4. Now, we can setup the proportion 4/pi=i/n. Thus, pi=(4i)/n

Implementation

This program can be easily implemented in 8x TI-BASIC as:

:0 --> N0 --> D
:While 1
:rand*2-1 --> X
:rand*2-1 --> Y
:If sqrt(x^2+y^2)=< 1
:N+1 --> N
:End
:D+1 --> D
:Disp (N/D*4)
:End

Bibliography

1) Dara Hazeghi: Dara's Pi Page http://www.geocities.com/EnchantedForest/5815/,
Accessed 3/4/2000
2) JOC/EFR: Pi Through the Ages http://www-groups.dcs.st-and.ac.uk/


If you don't yet know how to celebrate Pi Day, here's a few tips:

  • Watch the movie Pi. It was written rather recently, and it's a bit artsy, but I love it. I'm planning on watching it with friends during the evening.
  • Serve pie to your classes, or if you don't have enough pie, have it for dinner!
  • Be psychotic like me and memorize sixty digits of pi. :)

Best wishes to you during this Pi Day season.

 


The comments below are written by ticalc.org visitors. Their views are not necessarily those of ticalc.org, and ticalc.org takes no responsibility for their content.


Re: Feature: Calculating Pi
brentes
(Web Page)

I am going to tell all of you this just FYI.

My search pi script is now DOWN because I got a message from my Server Administrator saying it took up an unbelievable amount of cpu from their machines or something. After all, it was on slashdot :)

sorry for the inconveniance :)

     14 March 2000, 17:57 GMT


Re: Re: Feature: Calculating Pi
brentes
(Web Page)

and it brought my server down for an hour :) He had to reboot the locked up machine

     14 March 2000, 18:44 GMT


Re: Re: Re: Feature: Calculating Pi
enigma2e  Account Info
(Web Page)

Hey, I run a server with 3.14 million free cpu cycles. You could run that pi script on my server, if it would run on NT...

     15 March 2000, 02:23 GMT

Re: Feature: Calculating Pi
Nathan Walters  Account Info

Happy Pi Time!!! in Eastern time, it is 3/14, at 1:59 and 26.5 seconds approxamately.

i hurried home from school to make it! :-) sorry i can't make it more exact, but it takes time to post this message, and different clocks are going to show slightly different times.

nathan (by the way, Yes, i do need a life)

     14 March 2000, 19:58 GMT

Re: Re: Feature: Calculating Pi
Nathan Walters  Account Info

oh, and i took cherry pie to school today, with pi(the letter) inscribed on it. I proclamed Pi-day to the world, and the world called me crazy and told me to shut up and sit down.

     14 March 2000, 20:09 GMT


Re: Re: Re: Feature: Calculating Pi
akdjr  Account Info
(Web Page)

heh heh, if i did that, just about my entire school would probably hang me up on the flagpole by my pants or probably burn pi or some odd thing like that (you know, the mob mentality:
"what - you dare mention pi! BURN HIM! BURN HIM! BURN HIM! ok, i'm bored. oooh, lets burn that guy over there....) =) =)

     15 March 2000, 04:28 GMT


Re: Re: Re: Re: Feature: Calculating Pi
Chris Fazio  Account Info

hahahaha

     17 March 2000, 03:18 GMT


Re: Re: Feature: Calculating Pi
AuroraBoriales  Account Info

Well, to me, you don't look like you have a life. Lucky for me, it's spring break, and "pi-time" is coming up in about 30 minutes Central time. Geez... I wonder how else i should waste my time instead of staring at a cathode ray tube and reading about pi

     14 March 2000, 20:24 GMT

A few more tidbits
Grant Elliott  Account Info
(Web Page)

My favorite formula for pi:

lim (as n approaches infinity) sin(180/n)*cos(180/n)*n

This is the easiest to derive. The area of a regular polygon with n sides and radius R is:

sin(180/n)*cos(180/n)*n*R^2

And since the area of a regular polygon with infinite sides is pi*R^2 (we can prove that it is directly proportional to R^2), we obtain that pi is equal to the above limit.

Of course, this formula is useless if the algorithm you use for sin and cos uses pi. But there are plenty that don't.

On another fun note, I'll now list off a few other fun tricks with transidential numbers and other fun stuff:

The nth Fibonacci number is (phi^n-psi^n)/sqrt(n)

e^(pi*i) = -1

i^i = e^(-pi*i/2)

tau(tau(15!)) = 42

My favorite is the last one : )

On a final note, you can't appreciate pi until you read The Joy of Pi. You can enjoy some of the fun at www.joyofpi.com The book has all sorts of fun things. Among them are the first 1,000,000 digits of pi printed in the background on every page. (You can find 10,000 at the webpage.) Better still,
important digits are marked. Ever wonder what the 3rd digit of pi is? What about the 31st? 314th? 3141st? 31415th?

And, of course, the most important digit: THE 42nd DIGIT OF PI : ) I looked it up once. I think it's a 9.

Why didn't ticalc celebrate e day? What about phi day? Why not celebrate the 42nd day of the year?

This concludes yet another edition of "Grant Babbles meaninglessly."

     14 March 2000, 22:21 GMT


Stuff I forgot
Grant Elliott  Account Info
(Web Page)

While we're celebrating pi day, we need to remember that today is also Albert Einstein's birthday. Happy birthday Al!

I also forgot to mention that there exists a digit extraction formula for pi. Unfortunately, it's in hexadecimal:

Sigma (as n goes from 0 to infinity) (4/(8n+1) - 2/(8n+4) - 1/(8n+4) - 1/(8n+6)) * (1/16)^n

You can find that formula in a legible form at http://www.mathsoft.com/asolve/plouffe/ plouffe.html

And let's not forget our good buddy Ramanajun (sp). The man was an absolute genius. He came up with five or 6 expressions for (are you ready for this?) 1/pi. I'd type them here, but they'd be mulilated in standard text (much like the digit extraction theorem was).

     14 March 2000, 22:43 GMT


Re: Stuff I forgot
amicek  Account Info
(Web Page)

And nowwww - Grant will babble for 1 hour straight about math concepts that roughly 50% of us don't understand!

*Rimshot*
*muted laughter*

Jeez, that wasn't even funny, sorry everybody....

Oh! But I do have something worthwhile to say! How did that person get the printout of pi that was like 50,000 digits long?

amicek

     15 March 2000, 00:55 GMT


50 Million Digits of Pi
Grant Elliott  Account Info
(Web Page)

The above URL (http://www.cecm.sfu.ca/projects /ISC/data/pi.html) can get you up to 50 million digits. I found a page with 200 million, but the link no longer works. You could always run a program with one of the previous formulas. My favorite way: use the hexadecimal digit extracter and convert to DCB. In case you were wondering, 10 digits is enough to accurately calculate the volume of a sphere the size of the sun.

Maybe I should shut up now...

     15 March 2000, 02:20 GMT


Re: 50 Million Digits of Pi
amicek  Account Info
(Web Page)

It was starting to get almost interesting there with the thing about the sun - j/k :)

amicek

     15 March 2000, 04:46 GMT

Re: Feature: Calculating Pi
Garrett Cradduck  Account Info
(Web Page)

Alright...apparently(as far as I can tell) no one's seen fit to mention another method of
calculating grand ol' pi, so here it is:
1/1 +1/4 +1/9 +1/16 +1/25 +1/36 + ....... = [(pi)^2]/6.
Bernoulli never managed to find this exact answer, so it was left to
Euler, whom you can thank for the above equality.
I don't suggest using this to calculate pi, though, as convergence
is absolutely horrendous. Just thought I'd throw it out there.

     14 March 2000, 22:32 GMT

Re: Re: Feature: Calculating Pi
mysteryegg  Account Info
(Web Page)

if we really wanted a strange way to calculate pi, we could take the integral of e^x^-2 from 0 to infinity... (don't bother taking the indefinate integral first :P)... you should end up with [sqrt(pi)]/2

     15 March 2000, 00:37 GMT

Re: Re: Feature: Calculating Pi
net-cat
(Web Page)

To test this, I entered the following program into Qbasic:

DEFDBL A-Z 'sets double precision
CLS 'clears screen
pi = 0 'init pi variable (not necassary)
FOR i = 1 TO 100000
pi = pi + 1 / i ^ 2 'takes 1/1^2+1/2^2+...+1/100000^2
NEXT
PRINT SQR(pi * 6) 'Answer (SQR = sqrt)

Answer: 3.141583104326457


In TI-86 BASIC,

:0->p
:For(i,1,100000)
:p+1/i^2->p
:End
:Disp sqrt(p*6)

I got: 3.14149716395
(Yes, it did take a while for the calc to crunch all those numbers.)

Why is it different? I don't know, but from now on I will double check stuff by hand. (If I have time.)

By hand i got, ... (j/k)

     15 March 2000, 07:22 GMT


Re: Re: Feature: Calculating Pi
The_Professor  Account Info
(Web Page)

Personaly, I like this equation to find pi:

pi = -ln(-1)*i

     16 March 2000, 23:18 GMT

Re: Feature: Calculating Pi
S B Account Info

You know that if you are realy inclined to do the calculations (or the aproxamate 22/7). you could calculate it on the calculator in your computer (or just press the frigging pi key).

     14 March 2000, 23:31 GMT

Re: Feature: Calculating Pi
damian Ancukiewicz  Account Info
(Web Page)

I memorized 66 digits of pi about a year ago:
3.141592 6535897932 38462643383 27950 2884197169 399375105

Whenever I recite it people think i'm crazy.
Maybe i am...

     15 March 2000, 02:45 GMT

Re: Feature: Calculating Pi
Spoon_Man

I know this is off subject but could someone please email me info on how to downgrade from AMS 2.03 to 1.0x, thank you

Ps. I have an H1 Ti-89

     15 March 2000, 03:12 GMT

Program for Pi
Wolf  Account Info
(Web Page)

Those are all good programs on the top, but they take too long, and don't give the right answers, not right enough. Here is a program that is easier, faster, and gets the right answer. It's different, without the "circle" graphic, but I think it's better this way.

The " ' " in the code mean commenting, don't type that in

Program:Pi
Degree 'sets the mode for degrees, otherwise all screwed up
0->d 'clears values
2->x 'clears values
While 1 'starts an endless loop
x+1->x 'increases number of verteces on the figure
(x*sin ((360/x)/2)))+x*(tan((360/x)/2))->N 'calculates the value
n/2->d 'stores the value
Disp d 'outputs the actual value

' Disp x ' put this to tell you at what point the value comes really close to Pi

End 'says where the loop goes to the beginning


Hope you're happy this way. Visit the website, and write me back, any flames welcome.

     15 March 2000, 06:09 GMT

Re: Program for Pi
Wolf  Account Info
(Web Page)

By the way, the program puts a figure with an n number of verteces both inside AND outside the figure, finds the perimeter of both, and then averages, this is exact, but REALLY needs a high number of verteces, in the order of five THOUSAND. I'll be putting the program on my website, plus program to calculate e, all for the TI-86/85. have fun, and happy coding!

     15 March 2000, 15:58 GMT


Re: Program for Pi
Derrick Staples  Account Info
(Web Page)

The quickest, easiest way to calculate pi on TIs is to press [2nd] and [^]. Just incase no one knew.

     20 March 2000, 01:05 GMT

1  2  3  4  5  6  7  

You can change the number of comments per page in Account Preferences.

  Copyright © 1996-2012, the ticalc.org project. All rights reserved. | Contact Us | Disclaimer