1.3.5.5 Mandelbrot集合

mandelbrot

写一个脚本计算Mandelbrot分形。Mandelbrot迭代

  1. N_max = 50
  2. some_threshold = 50
  3. c = x + 1j*y
  4. for j in xrange(N_max):
  5. z = z**2 + c

点(x, y)属于Mandelbrot集合,如果|c| < some_threshold。

作如下计算:

  • 构建一个网格 c = x + 1j*y, 值在范围[-2, 1] x [-1.5, 1.5]
  • 进行迭代
  • 构建2-D布尔面具标识输入集合中的点
  • 用下列方法将结果保存到图片:
  1. import matplotlib.pyplot as plt
  2. plt.imshow(mask.T, extent=[-2, 1, -1.5, 1.5])
  3. plt.gray()
  4. plt.savefig('mandelbrot.png')

答案:Python源文件