Created
February 17, 2020 18:57
-
-
Save alexamies/063ba8e62fc008fa3285bf1d4f4fd18a to your computer and use it in GitHub Desktop.
Revisions
-
alexpamies created this gist
Feb 17, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ import math """Estimates the value of pi Uses the secant of successivly smaller slices of a unit circle as an estimate of the circumference """ # Initial value is the hypotenuse of a quarter of a circle # 2pi ~ 4 * srt(2) # pi ~ 2 * sqrt(2) # x is the length of the secant x = math.sqrt(2) N = 2 print('The estimate of pi is') for i in range(30): y = math.sqrt(1 - (x / 2)**2) z = 1 - y x = math.sqrt((x / 2)**2 + z**2) N *= 2 pi = N * x print('{0:d}, {1:.20f}'.format(i, pi))