kirby urner schrieb:
This is just to get junior experimenting with convergence / divergence
on the complex plane. c is our variable.
Per this Wikipedia article (fine to project in class, why not, though
"teacher reading from encyclopedia" shouldn't come off as mechanical):
See: http://en.wikipedia.org/wiki/Mandelbrot_set
Also: http://www.4dsolutions.net/ocn/fractals.html
IDLE 3.0a2
def mandelbrot(c):
z = 0 + c
while True:
yield z
z = z ** 2 + c
May I again add an interesting thing,
this time another indispensable generator,
more exactly: three of them:
def feigenbaum1(c,x):
while True:
yield x
x = c*x*(1-x)
def feigenbaum2(c,x):
while True:
yield x
x = c*x-c*x*x
def feigenbaum3(c,x):
while True:
yield x
x = c*(x-x**2)
along with this testing/experimenting function:
def feigenbaumtest(feigenbaum, iterations=80):
f = feigenbaum(3.93, 0.5)
for i in range(iterations):
res = next(f)
return res
>>> feigenbaumtest(feigenbaum1, 4)
0.24761176565334103
>>> feigenbaumtest(feigenbaum2, 4)
0.24761176565334098
>>> feigenbaumtest(feigenbaum3, 4)
0.24761176565334167
>>> feigenbaumtest(feigenbaum1, 40)
0.43518828176766455
>>> feigenbaumtest(feigenbaum2, 40)
0.43518808407096854
>>> feigenbaumtest(feigenbaum3, 40)
0.43518950764209768
>>> feigenbaumtest(feigenbaum1)
0.70329204370098442
>>> feigenbaumtest(feigenbaum2)
0.8147039925205275
>>> feigenbaumtest(feigenbaum3)
0.66573747868397481
>>>
Certainly something which demonstrates a (by many)
unexpected relation between maths and computer science.
Regards,
Gregor
_______________________________________________
Edu-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/edu-sig