I need a script that calculates pi.
Offline
You should check out the Wikipedia page. There are many algorithms for calculating Pi. My favorite is this the Gauss-Legendre Algorithm. Here's how it works:
setAccuracy ▼to50Choose a big number.seta.n ▼to1setb.n ▼to1/sqrt ▼of2sett.n ▼to0.25setp.n ▼to1repeatAccuracyseta.n+1 ▼to/a.n+b.n2setb.n+1 ▼tosqrt ▼ofa.n*b.nsett.n+1 ▼tot.n-p.n**a.n-a.n+1a.n-a.n+1setp.n+1 ▼to2*p.nseta.n ▼toa.n+1setb.n ▼tob.n+1sett.n ▼tot.n+1setp.n ▼top.n+1setPi ▼to/*a.n+b.na.n+b.n4*t.n
Offline
You could do something like this:
whenclicked
deleteallofpiaddthingto PisetPIto0setFractionsto 1foreversetPItoPI+4/FractionschangeFractionsby2setPItoPI- 4 /FractionschangeFractionsby2sayPireplace item1ofPiwithPI
Offline
sanjayraj wrote:
You could do something like this:
whenclicked
deleteall ▼ofPi ▼addthingtoPi ▼setPi ▼to0setFractions ▼to1foreversetPi ▼to/Pi+4FractionschangeFractions ▼by2setPi ▼to/Pi-4FractionschangeFractions ▼by2sayPireplace item1ofPi ▼withPi
Fixed your scripts.
Last edited by amcerbu (2012-05-27 23:06:31)
Offline
I have a Pi calculating project, if none of these work. The scripts there might help.
Last edited by Splodgey (2012-05-28 06:20:35)
Offline
amcerbu wrote:
You should check out the Wikipedia page. There are many algorithms for calculating Pi. My favorite is this the Gauss-Legendre Algorithm. Here's how it works:
setAccuracy ▼to50Choose a big number.seta.n ▼to1setb.n ▼to1/sqrt ▼of2sett.n ▼to0.25setp.n ▼to1repeatAccuracyseta.n+1 ▼to/a.n+b.n2setb.n+1 ▼tosqrt ▼ofa.n*b.nsett.n+1 ▼tot.n-p.n**a.n-a.n+1a.n-a.n+1setp.n+1 ▼to2*p.nseta.n ▼toa.n+1setb.n ▼tob.n+1sett.n ▼tot.n+1setp.n ▼top.n+1setPi ▼to/*a.n+b.na.n+b.n4*t.n
Thanks! I used your script and it worked perfectly. You can find the final product here: http://scratch.mit.edu/projects/skippito/2569922
Offline
Here is my (very slow) pi calculator:
You can find the (very slow) calculator on my profile.whenclicked
deleteall ▼ofpil ▼add4topil ▼setno ▼to1setpi ▼to4set+/- ▼to0foreverreplace item1 ▼ofpil ▼withpiif+/-=0changepi ▼by*4/no-1set+/- ▼to1elsechangepi ▼by4/noset+/- ▼to0changeno ▼by2
Last edited by likegames (2012-05-30 19:02:22)
Offline