|
|
Re: Pi for a beginner - easy one!
Posted:
Jun 1, 2000 3:51 PM
|
|
Charles H. Giffen schrieb in Nachricht <39367795.8EB3491@virginia.edu>... >Mike Mccarty Sr wrote: >> >> In article <393460D7.42F4@pointecom.net>, >> Lynn Killingbeck <killbeck@pointecom.net> wrote: >> >> )Use a search engine (e.g., http://www.yahoo.com/) to find already >> )computed values of PI to lots of digits. Try search keywords such as >> )"PI", "digits", or such. I found one with 50,000 or so a while back, and >> )there are more readily available. At least one of these will a pointer >> )to the world-record with several billions of digits. Don't even think >> )about downloading that one - which would take several dozen CDs - but >> )your 100,000 should be easy to find and download. >> >> It should be easy to compute, Lynn. 100,000 digits can be attained just >> by Machin's formula >> >> PI = 16 atan(1/5) - 4 atan(1/239) >> >> 1,000,000 can be computed on most desktop machines in an hour or so, >> using quadratically converging techniques. >>
In http://www.snippets.org are several cute little C programs (Machin and AGM) using simple home-made extended precision fixed point arithmetic and computing pi up to several thousand digits. Prefer PI8.C and PI_AGM.C Have fun Hermann --
>> )PI is not rational; therefore, not rational in any number system. I'll >> )leave you to ponder what this may (or may not!) mean, since PI=1 in >> )base_PI arithmetic. >> ) >> )For converting among bases, I'd search for some arbitrary arithmetic >> )package. They get mentioned fairly often in sci.math.num-analysis. I >> )don't know which, if any, handle arbitrary precision fractions (rather >> )than integers). Again, use a search engine, with keywords such as "high >> )precision", "big number", "bignum", "arbitrary precision". See if you >> )can find one that includes arbitrary bases for the input/output. >> >> Not necessary. Just compute integer(PIxBase^SomePower). Integer routines >> suffice. I wouldn't bother to convert to another base; I'd do the >> computation in the other base. >> >> Mike >> -- >> ---- >> char *p="char *p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);} >> This message made from 100% recycled bits. >> I don't speak for Alcatel <- They make me say that. > > If you want to go a little faster, use Euler's arctangent series: > > arctan(x) = ( > 4^j*j!^2*x^(2*j + 1)/((2*j + 1)!*(1 + x^2)^(j+1)), > j = 0 .. infinity) > > = x/(1+x^2)+2*x^3/(3*(1+x^2)^2) + > 2*4*x^5/(3*5*(1+x^2)^3) + > 2*4*6*x^7/(3*5*7*(1+x^2)^4) + ... , > >which converges for all x and for abs(x) <= 1 converges much more >rapidly than the Taylor series for the arctangent. > > The error E[n](x) in using the first n terms (the zero-th >through (n-1)-st terms) satisfies the inequality: > > |E[n](x)| <= 4^n*n!^2*|x|^(2*n + 1)/((2*n + 1)!*(1 + x^2)^n), > >so one can readily determine just how many terms to use in calculating >an arctangent by Euler's series. > > Euler discovered the formula > > Pi = 20*arctan(1/7) + 8*arctan(3/79) , > >and used his arctangent series along with this formula to compute 20 >digits of Pi by hand in under an hour. Incidentally, the particular >formula Euler used in computing Pi works rather well for hand >calculation, since the quantity x^2/(1+x^2) is quite manageable >when x = 1/7 or 3/79, as you can see for yourself. > >--Chuck Giffen
|
|