圓週率公式(A): SUM(1/(2*n-1)^2) == ((π^2) / 8), n=1, 2, 3, 4, ...

圓週率公式(A): SUM(1/(2*n-1)^2) == ((π^2) / 8), n=1, 2, 3, 4, ...

Post by tt »

圓週率公式(A): SUM(1/(2*n-1)^2) == ((π^2) / 8), n=1, 2, 3, 4, ...


舉例: n = 1 ~ 512, 則 2^n-1 分母為積數 (Odd Number) 1, 3, 5, 7, 9 ... 至 1023

Code: Select all

e.g.  
-----------------------------------------
SUM(1/(2*n-1)^2) == ((π^2) / 8)
-----------------------------------------
sqrt ( 8 * (1/(1*1) + 1/(3*3) + 1/(5*5) + 1/(7*7) + 1/(9*9) + 1/(11*11) + 1/(13*13) + 1/(15*15) + 1/(17*17) + 1/(19*19) + 1/(21*21) + 1/(23*23) + 1/(25*25) + 1/(27*27) + 1/(29*29) + 1/(31*31) + 1/(33*33) + 1/(35*35) + 1/(37*37) + 1/(39*39) + 1/(41*41) + 1/(43*43) + 1/(45*45) + 1/(47*47) + 1/(49*49) + 1/(51*51) + 1/(53*53) + 1/(55*55) + 1/(57*57) + 1/(59*59) + 1/(61*61) + 1/(63*63) + 1/(65*65) + 1/(67*67) + 1/(69*69) + 1/(71*71) + 1/(73*73) + 1/(75*75) + 1/(77*77) + 1/(79*79) + 1/(81*81) + 1/(83*83) + 1/(85*85) + 1/(87*87) + 1/(89*89) + 1/(91*91) + 1/(93*93) + 1/(95*95) + 1/(97*97) + 1/(99*99) + 1/(101*101) + 1/(103*103) + 1/(105*105) + 1/(107*107) + 1/(109*109) + 1/(111*111) + 1/(113*113) + 1/(115*115) + 1/(117*117) + 1/(119*119) + 1/(121*121) + 1/(123*123) + 1/(125*125) + 1/(127*127) + 1/(129*129) + 1/(131*131) + 1/(133*133) + 1/(135*135) + 1/(137*137) + 1/(139*139) + 1/(141*141) + 1/(143*143) + 1/(145*145) + 1/(147*147) + 1/(149*149) + 1/(151*151) + 1/(153*153) + 1/(155*155) + 1/(157*157) + 1/(159*159) + 1/(161*161) + 1/(163*163) + 1/(165*165) + 1/(167*167) + 1/(169*169) + 1/(171*171) + 1/(173*173) + 1/(175*175) + 1/(177*177) + 1/(179*179) + 1/(181*181) + 1/(183*183) + 1/(185*185) + 1/(187*187) + 1/(189*189) + 1/(191*191) + 1/(193*193) + 1/(195*195) + 1/(197*197) + 1/(199*199) + 1/(201*201) + 1/(203*203) + 1/(205*205) + 1/(207*207) + 1/(209*209) + 1/(211*211) + 1/(213*213) + 1/(215*215) + 1/(217*217) + 1/(219*219) + 1/(221*221) + 1/(223*223) + 1/(225*225) + 1/(227*227) + 1/(229*229) + 1/(231*231) + 1/(233*233) + 1/(235*235) + 1/(237*237) + 1/(239*239) + 1/(241*241) + 1/(243*243) + 1/(245*245) + 1/(247*247) + 1/(249*249) + 1/(251*251) + 1/(253*253) + 1/(255*255) + 1/(257*257) + 1/(259*259) + 1/(261*261) + 1/(263*263) + 1/(265*265) + 1/(267*267) + 1/(269*269) + 1/(271*271) + 1/(273*273) + 1/(275*275) + 1/(277*277) + 1/(279*279) + 1/(281*281) + 1/(283*283) + 1/(285*285) + 1/(287*287) + 1/(289*289) + 1/(291*291) + 1/(293*293) + 1/(295*295) + 1/(297*297) + 1/(299*299) + 1/(301*301) + 1/(303*303) + 1/(305*305) + 1/(307*307) + 1/(309*309) + 1/(311*311) + 1/(313*313) + 1/(315*315) + 1/(317*317) + 1/(319*319) + 1/(321*321) + 1/(323*323) + 1/(325*325) + 1/(327*327) + 1/(329*329) + 1/(331*331) + 1/(333*333) + 1/(335*335) + 1/(337*337) + 1/(339*339) + 1/(341*341) + 1/(343*343) + 1/(345*345) + 1/(347*347) + 1/(349*349) + 1/(351*351) + 1/(353*353) + 1/(355*355) + 1/(357*357) + 1/(359*359) + 1/(361*361) + 1/(363*363) + 1/(365*365) + 1/(367*367) + 1/(369*369) + 1/(371*371) + 1/(373*373) + 1/(375*375) + 1/(377*377) + 1/(379*379) + 1/(381*381) + 1/(383*383) + 1/(385*385) + 1/(387*387) + 1/(389*389) + 1/(391*391) + 1/(393*393) + 1/(395*395) + 1/(397*397) + 1/(399*399) + 1/(401*401) + 1/(403*403) + 1/(405*405) + 1/(407*407) + 1/(409*409) + 1/(411*411) + 1/(413*413) + 1/(415*415) + 1/(417*417) + 1/(419*419) + 1/(421*421) + 1/(423*423) + 1/(425*425) + 1/(427*427) + 1/(429*429) + 1/(431*431) + 1/(433*433) + 1/(435*435) + 1/(437*437) + 1/(439*439) + 1/(441*441) + 1/(443*443) + 1/(445*445) + 1/(447*447) + 1/(449*449) + 1/(451*451) + 1/(453*453) + 1/(455*455) + 1/(457*457) + 1/(459*459) + 1/(461*461) + 1/(463*463) + 1/(465*465) + 1/(467*467) + 1/(469*469) + 1/(471*471) + 1/(473*473) + 1/(475*475) + 1/(477*477) + 1/(479*479) + 1/(481*481) + 1/(483*483) + 1/(485*485) + 1/(487*487) + 1/(489*489) + 1/(491*491) + 1/(493*493) + 1/(495*495) + 1/(497*497) + 1/(499*499) + 1/(501*501) + 1/(503*503) + 1/(505*505) + 1/(507*507) + 1/(509*509) + 1/(511*511) + 1/(513*513) + 1/(515*515) + 1/(517*517) + 1/(519*519) + 1/(521*521) + 1/(523*523) + 1/(525*525) + 1/(527*527) + 1/(529*529) + 1/(531*531) + 1/(533*533) + 1/(535*535) + 1/(537*537) + 1/(539*539) + 1/(541*541) + 1/(543*543) + 1/(545*545) + 1/(547*547) + 1/(549*549) + 1/(551*551) + 1/(553*553) + 1/(555*555) + 1/(557*557) + 1/(559*559) + 1/(561*561) + 1/(563*563) + 1/(565*565) + 1/(567*567) + 1/(569*569) + 1/(571*571) + 1/(573*573) + 1/(575*575) + 1/(577*577) + 1/(579*579) + 1/(581*581) + 1/(583*583) + 1/(585*585) + 1/(587*587) + 1/(589*589) + 1/(591*591) + 1/(593*593) + 1/(595*595) + 1/(597*597) + 1/(599*599) + 1/(601*601) + 1/(603*603) + 1/(605*605) + 1/(607*607) + 1/(609*609) + 1/(611*611) + 1/(613*613) + 1/(615*615) + 1/(617*617) + 1/(619*619) + 1/(621*621) + 1/(623*623) + 1/(625*625) + 1/(627*627) + 1/(629*629) + 1/(631*631) + 1/(633*633) + 1/(635*635) + 1/(637*637) + 1/(639*639) + 1/(641*641) + 1/(643*643) + 1/(645*645) + 1/(647*647) + 1/(649*649) + 1/(651*651) + 1/(653*653) + 1/(655*655) + 1/(657*657) + 1/(659*659) + 1/(661*661) + 1/(663*663) + 1/(665*665) + 1/(667*667) + 1/(669*669) + 1/(671*671) + 1/(673*673) + 1/(675*675) + 1/(677*677) + 1/(679*679) + 1/(681*681) + 1/(683*683) + 1/(685*685) + 1/(687*687) + 1/(689*689) + 1/(691*691) + 1/(693*693) + 1/(695*695) + 1/(697*697) + 1/(699*699) + 1/(701*701) + 1/(703*703) + 1/(705*705) + 1/(707*707) + 1/(709*709) + 1/(711*711) + 1/(713*713) + 1/(715*715) + 1/(717*717) + 1/(719*719) + 1/(721*721) + 1/(723*723) + 1/(725*725) + 1/(727*727) + 1/(729*729) + 1/(731*731) + 1/(733*733) + 1/(735*735) + 1/(737*737) + 1/(739*739) + 1/(741*741) + 1/(743*743) + 1/(745*745) + 1/(747*747) + 1/(749*749) + 1/(751*751) + 1/(753*753) + 1/(755*755) + 1/(757*757) + 1/(759*759) + 1/(761*761) + 1/(763*763) + 1/(765*765) + 1/(767*767) + 1/(769*769) + 1/(771*771) + 1/(773*773) + 1/(775*775) + 1/(777*777) + 1/(779*779) + 1/(781*781) + 1/(783*783) + 1/(785*785) + 1/(787*787) + 1/(789*789) + 1/(791*791) + 1/(793*793) + 1/(795*795) + 1/(797*797) + 1/(799*799) + 1/(801*801) + 1/(803*803) + 1/(805*805) + 1/(807*807) + 1/(809*809) + 1/(811*811) + 1/(813*813) + 1/(815*815) + 1/(817*817) + 1/(819*819) + 1/(821*821) + 1/(823*823) + 1/(825*825) + 1/(827*827) + 1/(829*829) + 1/(831*831) + 1/(833*833) + 1/(835*835) + 1/(837*837) + 1/(839*839) + 1/(841*841) + 1/(843*843) + 1/(845*845) + 1/(847*847) + 1/(849*849) + 1/(851*851) + 1/(853*853) + 1/(855*855) + 1/(857*857) + 1/(859*859) + 1/(861*861) + 1/(863*863) + 1/(865*865) + 1/(867*867) + 1/(869*869) + 1/(871*871) + 1/(873*873) + 1/(875*875) + 1/(877*877) + 1/(879*879) + 1/(881*881) + 1/(883*883) + 1/(885*885) + 1/(887*887) + 1/(889*889) + 1/(891*891) + 1/(893*893) + 1/(895*895) + 1/(897*897) + 1/(899*899) + 1/(901*901) + 1/(903*903) + 1/(905*905) + 1/(907*907) + 1/(909*909) + 1/(911*911) + 1/(913*913) + 1/(915*915) + 1/(917*917) + 1/(919*919) + 1/(921*921) + 1/(923*923) + 1/(925*925) + 1/(927*927) + 1/(929*929) + 1/(931*931) + 1/(933*933) + 1/(935*935) + 1/(937*937) + 1/(939*939) + 1/(941*941) + 1/(943*943) + 1/(945*945) + 1/(947*947) + 1/(949*949) + 1/(951*951) + 1/(953*953) + 1/(955*955) + 1/(957*957) + 1/(959*959) + 1/(961*961) + 1/(963*963) + 1/(965*965) + 1/(967*967) + 1/(969*969) + 1/(971*971) + 1/(973*973) + 1/(975*975) + 1/(977*977) + 1/(979*979) + 1/(981*981) + 1/(983*983) + 1/(985*985) + 1/(987*987) + 1/(989*989) + 1/(991*991) + 1/(993*993) + 1/(995*995) + 1/(997*997) + 1/(999*999) + 1/(1001*1001) + 1/(1003*1003) + 1/(1005*1005) + 1/(1007*1007) + 1/(1009*1009) + 1/(1011*1011) + 1/(1013*1013) + 1/(1015*1015) + 1/(1017*1017) + 1/(1019*1019) + 1/(1021*1021) + 1/(1023*1023))

== sqrt ( 8 * (1 + 0.11111111111111111111111111111111 +  0.04 + 0.02040816326530612244897959183673 + 0.01234567901234567901234567901235 + 0.00826446 +0.00591715976331360946745562130178 +  0.00444444444444444444444444444444 + 0.00346020761245674740484429065744 +  0.00277008310249307479224376731302 + 0.00226757369614512471655328798186 + 0.00189035916824196597353497164461 + 0.0016 + 0.00137174211248285322359396433471 + 0.00118906064209274673008323424495 + 0.00104058272632674297606659729448 + 0.001001001001001001001001001001 + 8.1632653061224489795918367346939e-4 + ...(這裡省略)... )

== sqrt ( 8 * 1.23321226904139004921588505179138 )

== sqrt ( 9.86569815233112039372708041433104  )

==> 3.14097

Re: 圓週率公式(A): SUM(1/(2*n-1)^2) == ((π^2) / 8), n=1, 2, 3, 4, ...

Post by tt »

Bash BC + PHP example of PI: 3.14159

3.14159

Code: Select all

$ cat pi-odd-number.php


<?php

        echo "scale=64; sqrt( 8 * (";
        for ($i=1; $i<=16777215; $i+=2)
        {
                echo "1/($i*$i) + ";
        }
        echo " 0 )) ";
?>


$ time php pi-odd-number.php  | bc 

3.1415926156442976203420241870879091412354242931426474819889608955

real    1m9.034s
user    1m10.228s
sys     0m4.137s