Created
December 28, 2010 13:00
Mandelbrot and Pi
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 characters
#!/usr/bin/ruby | |
# Calculates Mandelbrot equation for point (-0.75, x) where x -> 0 | |
# Amazingly the resulting iterations approximate pi | |
def mandel_iter (xp, yp, max) | |
x = y = 0.0 | |
n = 0 | |
while ((x*x + y*y) <= 4 and n < max) do | |
x , y , n = x*x - y*y + xp , 2*x*y + yp, n + 1 | |
end | |
n | |
end | |
(0..7).each do |i| | |
t = Time.now | |
puts "#{10**(-i)}, #{mandel_iter(-0.75, 10**(-i), 10**10)}, #{Time.now - t}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment