Code archives/Algorithms/Pi Calculator
This code has been declared by its author to be Public Domain code.
Download source code
| |||||
| Calculates Pi based on the arc length of 1/4 of a circle with a radius of 4. Basically, it uses the trapezoidal rule to approximate the integral for arc length. Unfortunately, due to the limits of BB floats, the answer is rendered innacurate long before the trapezoidal rule would make it incorrect. Oh well. I'm considering writing a version that uses banks to get a MUCH more accurate answer. | |||||
n=100
total#=2*Sqr(1.5)
For temp=1 To 99
x#=-1*Sqr(2)+Sqr(2)*2/n*temp
total=total+2*Sqr(1+(-1/(x^2-4)))
Next
other#=Sqr(2)*2/(2*n)
pivalue#=total*other
Print "Pi="+pivalue
Print ""
asdf=Input$("Hit enter to end.")
End |
Comments
None.
Code Archives Forum