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:
set [Accuracy v] to [50] // Choose a big number. set [a.n v] to [1] set [b.n v] to ([1]/( [sqrt v] of [2])) set [t.n v] to [0.25] set [p.n v] to [1] repeat (Accuracy) set [a.n+1 v] to (((a.n) + (b.n)) / [2]) set [b.n+1 v] to ([sqrt v] of ((a.n) * (b.n))) set [t.n+1 v] to ((t.n) - ( (p.n) * ( ( (a.n) - (a.n+1) ) * ( (a.n) - (a.n+1) ) ) )) set [p.n+1 v] to ([2] * (p.n)) set [a.n v] to (a.n+1) set [b.n v] to (b.n+1) set [t.n v] to (t.n+1) set [p.n v] to (p.n+1) end set [Pi v] to ((((a.n) + (b.n)) * ((a.n) + (b.n))) / ([4] * (t.n)))
Offline
You could do something like this:
when gf clicked delete (all) of (pi) add (thing) to Pi set (PI) to (0) set (Fractions) to 1 forever set (PI) to (PI) + (4) / (Fractions) change (Fractions) by (2) set (PI) to (PI) - 4 / (Fractions) change (Fractions) by (2) say (Pi) replace item (1) of (Pi) with (PI)
Offline
sanjayraj wrote:
You could do something like this:
when gf clicked delete (all v) of [Pi v] add [thing] to [Pi v] set [Pi v] to [0] set [Fractions v] to [1] forever set [Pi v] to (((Pi) + (4)) / (Fractions)) change [Fractions v] by (2) set [Pi v] to (((Pi) - (4)) / (Fractions)) change [Fractions v] by (2) say (Pi) replace item (1) of [Pi v] with (Pi)
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:
set [Accuracy v] to [50] // Choose a big number. set [a.n v] to [1] set [b.n v] to ([1]/( [sqrt v] of [2])) set [t.n v] to [0.25] set [p.n v] to [1] repeat (Accuracy) set [a.n+1 v] to (((a.n) + (b.n)) / [2]) set [b.n+1 v] to ([sqrt v] of ((a.n) * (b.n))) set [t.n+1 v] to ((t.n) - ( (p.n) * ( ( (a.n) - (a.n+1) ) * ( (a.n) - (a.n+1) ) ) )) set [p.n+1 v] to ([2] * (p.n)) set [a.n v] to (a.n+1) set [b.n v] to (b.n+1) set [t.n v] to (t.n+1) set [p.n v] to (p.n+1) end set [Pi v] to ((((a.n) + (b.n)) * ((a.n) + (b.n))) / ([4] * (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:
when gf clicked delete (all v) of [pil v] add [4] to [pil v] set [no v] to (1) set [pi v] to (4) set [+/- v] to (0) forever replace item (1 v) of [pil v] with (pi) if <(+/-) = (0)> change [pi v] by (((4) /(no))*(-1)) set [+/- v] to (1) else change [pi v] by ((4) /(no)) set [+/- v] to (0) end change [no v] by (2)You can find the (very slow) calculator on my profile.
Last edited by likegames (2012-05-30 19:02:22)
Offline