π Approximation

Using an infinite series shown by Euler, π can be approximated.
The series goes as follows: \sum\limits_{n=1}^{\infty} \frac{1}{n^2} = \frac{1}{1^2} + \frac{1}{2^2} + \frac{1}{3^2} + \frac{1}{4^2} + \dots = \frac{\pi^2}{6}
By rearranging the equation, you get the following: \pi = \sqrt{6\cdot\big(\frac{1}{1^2} + \frac{1}{2^2} + \frac{1}{3^2} + \frac{1}{4^2} + \dots\big)}

Approximating π...


# Python 2.7.7 Code
# Jonathan Frech 14th of December, 2015

# using Euler's formular: (pi**2)/6 = 1/1**2 + 1/2**2 + 1/3**2 + ... to calculate pi
sum = 0
s = 1
while True:
	sum += 1. / (s**2)
	pi = (sum * 6)**.5
	s += 1
	
	print "pi approx. " + str(pi)
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s