[bb] Pi Calculator by Arem [ 1+ years ago ]

Started by BlitzBot, June 29, 2017, 00:28:39

Previous topic - Next topic

BlitzBot

Title : Pi Calculator
Author : Arem
Posted : 1+ years ago

Description : 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.

Code :
Code (blitzbasic) Select
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...