代码拉取完成,页面将自动刷新
同步操作将从 霍开拓/ComputationalPhysics 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
"""
this generates a Mandelbrot set using a simple slow method
"""
import numpy as np
import matplotlib.pyplot as plt
from datetime import datetime
# input parameters
# ------------------------------
# set xy-domain size
xmin = -1.8
xmax = 0.8
ymin = -1.0
ymax = 1.0
# set xy-grid size
xpts = 200
ypts = 200
# set max iterations
maxn = 20
# ------------------------------
# iterate over Mandelbrot equation
# z = z^2 + c for complex numbers c and z
# start timer
t0 = datetime.now()
# initialize variables
im = np.complex(0,1)
z0 = np.complex(0,0)
x = []
y = []
# get grid
xgrid = np.linspace(xmin,xmax,xpts)
ygrid = np.linspace(ymin,ymax,ypts)
# evaluate grid points
for i in xgrid:
for j in ygrid:
c = i + im*j
z = z0
k = 0
# if abs(z) stays less than about 2 then point is in set
while abs(z) < 2 and k < maxn:
z = z*z + c
k += 1
if k >= maxn:
x.append(i)
y.append(j)
# make plot
plt.plot(x,y,'.k')
# print elapsed time
t1 = datetime.now()
print '\nelapsed time:'
print t1-t0
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。