Sign in to follow this  

Calculating PI to n-decimal places anyone?

This topic is 4855 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey I would like to know of a method to calculate PI to n-decimal places. Does anyone know a way an algorithm to do this? (PS: Please try and use as simple terms as I am still in highschool as it were(Standard 9/Grade 11). This is not homework!) Thank you in advance.

Share this post


Link to post
Share on other sites
the only method i know i to do the following.

PI = 4/1 - 4/3 + 4/5 - 4/7 + 4/9 - 4/11... ad infinitum.

in order to calculate PI to an arbitrary digit this way youd need arbitrary + something accurate floats though, and besides i doubt this is the fastest way.

id recommend mathworld, its bound to have a detailled explanation on this stuff.

Share this post


Link to post
Share on other sites
The problem with most methods is that they can converge quite slowly. I think some of the greatest methods for "fastest" methods for finding PI to any decimal place were perhaps due to Ramanujan. (feel free to correct me, i'm not saying i KNOW this to be in fact true, it's just my impression from reading stuff)

Take a look at the following links. They might get you going on some methods. The first link might be a little hard for you to read since you're still in highschool, bu the others are more "light".

http://en.wikipedia.org/wiki/Pi#Numerical_approximations_of_.26pi.3B

http://mathforum.org/library/drmath/view/58286.html

http://www.lbl.gov/Science-Articles/Archive/pi-algorithm.html
(http://www.lacim.uqam.ca/~plouffe/articles/Miraculous.pdf)

Share this post


Link to post
Share on other sites
Why do you want to be able to do this, could you not find a value off the internet and store it in a constant?

IIRC:

pi = circumference of a circle/diameter of a circle

so you could draw yourself a circle and measure the circ and diameter and the bung them in the formula.

Share this post


Link to post
Share on other sites
Thanks. I have the answer I needed to know

I just wanted to know the answer, in order to know it and then program it. I don't even care how fast it is. There is no point in having the fastest as the record is 51,539,600,000 decimal digits of PI. This is easy to program in java as there are classes which can handle numbers with any number of digits.
(BigInteger and BigDecimal)

Thanks.

Share this post


Link to post
Share on other sites
Quote:
Original post by shadow12345
Quote:

PI = 4/1 - 4/3 + 4/5 - 4/7 + 4/9 - 4/11... ad infinitum.


Note that this is:

4 * arctan(1)

in radian mode of course


and your point being?

there are numerous ways to calculate Pi, the problem is finding one with arbitrary accuracy.

Share this post


Link to post
Share on other sites
The relevance is that arctan(x)=x-x^3/3+x^5/5-x^7/7+... so if you plug x=1 in all the x^n's become 1. That can lead you to p(n)=(8/[(4n-1)*(4n-3)]) * ([192n-44]/[5^(4n-1)] - [114240n-28559]/[239^(4n-1)]) by using it for 4*arctan(1/5)-arctan(1/239). That expansion will get you about three digits per term which is a little faster.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
If you have a way of calculating Sin() to arbitrary precision, which isnt all that hard (taylor expansion..) then this handy algorithm works quite well:

x[0] = 3
x[n+1] = x[n] + sin(x[n])

x starts as a first rough guess and converges on pi pretty rapidly.. 3 iterations will fill a 64-bit IEEE float with pi

certainly not the fastest method, but a lot faster than the 'old school' expansion methods - and its quite simple.

- Rockoon


Share this post


Link to post
Share on other sites
Quote:

and your point being?

there are numerous ways to calculate Pi, the problem is finding one with arbitrary accuracy.


calm down buddy, I was just saying what you posted and 4 arctan(1) are equivalent...if you already knew, cool, if you didn't then I figured you'd find it interesting (or useful, seeing as how typing that into your calculator is much easier than actually doing the taylor series out by hand or something), sorry for trying to help.

Share this post


Link to post
Share on other sites

This topic is 4855 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this