Created
September 6, 2011 13:41
-
-
Save marsam/1197554 to your computer and use it in GitHub Desktop.
This file contains 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 characters
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
""" | |
Estimation of Pi using the Mandlebrot set | |
http://en.wikipedia.org/wiki/Mandelbrot_set | |
http://code.activestate.com/recipes/577584-amazing-estimation-of-pi-using-the-mandlebrot-set/ | |
https://home.comcast.net/%7Edavejanelle/mandel.pdf | |
""" | |
def pi(err, abs=abs): | |
"""Approximation of pi +/- err using the Mandlebrot set""" | |
n = 0 | |
z = c = complex(-0.75, err) | |
while abs(z) < 2.0: | |
n += 1 | |
z = z * z + c | |
return n * err | |
if __name__ == '__main__': | |
for i in range(1, 8): | |
err_bound = 10 ** (-i) | |
print(pi(err_bound), 'within', err_bound) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment