Yet another π formula
|
Yesterday, 05:57 PM
(This post was last modified: Yesterday 08:02 PM by Albert Chan.)
Post: #31
|
|||
|
|||
RE: Yet another π formula
Hi, EdS2
Here are improvements over your BBC Basic code. 1. k! / (2k+1)!!, numerator and denominator get huge very quickly We can let T = N/D, eliminate possible overflow issue. 2. 2k+1 replaced by 2k+p with p=1, for usage flexibility (see example below) 3. Instead of add last term for better pi estimate, I use Aitken extrapolated result. 4. Added plain 2*S pi estimate for comparison Code: 10 print "Calculate Pi with double factorial" BTW, my original Aitken code is this. Code: 40 T0=T:T=T*K/(2*K+P):S=S+T But I like D = 2+P/K ≈ 2 version better. It clearly showed T=T/D shrink to about half, thus sum accuaracy doubled per step. Also, it showed why add last term T to S improve estimate. Correction T/(D-1) ≈ T (Yesterday 01:28 PM)Albert Chan Wrote: pi/2 = (2 - 2/3 + 2/5 - 2/7 + 2/9) - 9!! * sum(k!/(2k+11)!!, k=0..inf) For this example, we change 1 line (run on DOS ubasic) Note: we start from k=1, thus k=0 correction goes to S. 20 L=6:P=11:T=-1/P:S=2-2/3+2/5-2/7+2/9+T run Calculate Pi with double factorial 3.1427128427128427129 3.1438783438783438784 3.1417266494189571114 3.1420135420135420136 3.1416139416139416141 3.1416844593315181551 3.1415967039496451264 3.1416151787668815534 3.1415935285904326155 3.1415986833943490292 3.1415928614981610796 3.1415943802536883708 OK |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 4 Guest(s)