|
Post by tenochtitlanuk on Feb 2, 2020 15:49:56 GMT -5
' Nilakantha series ' pi = 3 + 4/(2*3*4) - 4/(4*5*6) + 4/(6*7*8) - 4/(8*9*10) + 4/(10*11*12) - 4/(12*13*14)
I hadn't seen this series before- you can code it in a handful of lines and a few minutes and it converges very quickly.
How long did you take to code it?
Bit of an antidote to my ten-dimension hypersphere method..
|
|
|
Post by Brandon Parker on Feb 2, 2020 18:09:08 GMT -5
I did this a while ago ... like April 2013 while ago ...
Print calcPI(1114)
Function calcPI(stepsToCalc) For i = 2 To (stepsToCalc + 2) Step 2 If (i Mod 4) Then calcPI = calcPI + 4/ (i * (i + 1) * (i + 2)) Else calcPI = calcPI - 4/ (i * (i + 1) * (i + 2)) End If Next i calcPI = (3 + calcPI) End Function
{:0)
Brandon Parker
|
|
|
Post by sarossell on Feb 3, 2020 0:29:51 GMT -5
Pi = ASN(1)*2
|
|
|
Post by tenochtitlanuk on Feb 3, 2020 5:42:48 GMT -5
Brandon- nice series method isn't it! Your comment makes me feel like a necroposter..
sarossell- the point of the OP was to use this method.
I memorised 10 digits of Pi as a teenager and don't need to use ANY calculation when coding. I thought I'd collected most methods of calculating Pi to varying numbers of digits ( as on my web pages) but Nilakantha had escaped me, even if he operated 500 years ago. So before my teenage years, but not widely known 'back then'. The Wikipedia pages on Pi give lots of methods that are fun to program. However it goes way beyond my maths level- gamma functions etc. and more -at Ramanujan's level.
This was my code..
' Nilakantha series
' pi = 3 + 4/(2*3*4) - 4/(4*5*6) + 4/(6*7*8) - 4/(8*9*10) + 4/(10*11*12) - 4/(12*13*14)
' 199 terms 3.1415926219 error -0.0000000317 ' 200 terms 3.1415926848 error 0.0000000312 and decreasing.
LBpi =4 *atn( 1) start =2 pi =3
for i =1 to 200 print i, using( "#.##########", pi), using( "##.##########", pi -LBpi) if ( i mod 2) =0 then sgn =-1 else sgn =1 denom =start *( start +1) *( start +2) pi =pi +4 /denom *sgn start =start +2 next i
end
|
|
timur77
Junior Member
Someday I will tell my grandsons that I am older than the Internet. And it will blow their brain.
Posts: 79
|
Post by timur77 on Apr 1, 2020 3:53:47 GMT -5
I would like to share my experience in finding the number Pi.
I wrote the first program for finding the Pi number on another 286 PCs. Here is the code.
p=0 s=0 p1=0 p2=0 p3=0 p4=0 p5=0 for i=1 to 50000 p1=p b=10^15*(-1)^(i+1) p=p+(b-(b mod (i*2-1)))/(i*2-1) p3=p2 p2=((p1+p)-((p1+p) mod 2))/2 p4=p3 p3=((p2+p3)-((p2+p3) mod 2))/2 p5=((p3+p4)-((p3+p4) mod 2))/2
s=4*p5 locate 0,0 print s scan next i wait
Then I searched for faster methods for finding more PI digits.
p=2 a=0 for i=1 to 500 a=sqr(2+a) p=p*2/a locate 0,0 print p next i
But the best result I got in the next program. The calculation is made in whole numbers, the number of digits you need can be set in a cycle, more digits are longer the calculation, for example, 200 digits of the number of PIs I find in 4 minutes, and 400 digits in 8 minutes and 20 seconds
ms=10^600 s=0 for i=0 to 400 ii=8*i s=s+del(1*ms, 16^i)*(del(4*ms, (ii+1))-_ del(2*ms, (ii+4))-_ del(1*ms, (ii+5))-_ del(1*ms, (ii+6))) locate 0,0 print s scan next i print "Все" end function del(a, b) del=(a-(a mod b))/b end function
|
|
|
Post by tenochtitlanuk on Apr 1, 2020 4:54:39 GMT -5
Neat! I don't think I've ever thought of coding a line involving 10^600 to avoid the decimal...
It is fun to see if your date of birth ( in your local way of expressing it) comes in the first 10000 digits- eg 09042020 in UK standard way. Or check if all digits are equally represented...
|
|
timur77
Junior Member
Someday I will tell my grandsons that I am older than the Internet. And it will blow their brain.
Posts: 79
|
Post by timur77 on Apr 1, 2020 5:19:17 GMT -5
|
|
|
Post by tenochtitlanuk on Apr 1, 2020 6:14:00 GMT -5
Thanks for that reference... looking forward to more contributions from you!
(and I did do the checks..)
|
|
|
Post by bluatigro on Apr 1, 2020 8:27:06 GMT -5
my genetic programing code trys to find a alteritive formula for PI it often finds sqr( 10 ) and than does not go on
|
|