1 回答
TA贡献1775条经验 获得超8个赞
这是我最后如何绘制逃生图:
def tetration_com(base, tol=10**-15, max_step=10**6, max_val=10**2):
# returns t, the infinite tetration of base.
# if t does not converge, the function returns an escape value
# aka how fast it diverges..
t = 1.0
step = 0
escape = None
t_last = 0
try:
while(abs(t - t_last) > tol):
if(step > max_step or abs(t) > max_val):
raise OverflowError
t_last = t
t = pow(base, t)
step += 1
except(OverflowError):
t = None
escape = 1000/step
# the escape value is is inversely related to the number of steps it took
# us to diverge to infinity
return t, escape
向量化辅助函数:
def tetra_graph_escape(real, imag, tol=10**-15, max_step=10**3, max_val=10**2):
return np.array([np.array([tetration_com(r + im*1j, tol=tol, max_step=max_step, max_val=max_val)[1]
for im in imag]) for r in real])
绘图:
# graph our escape:
nx, ny = 700, 500
x, y = np.linspace(-3.5, 3.5, nx), np.linspace(-2.5, 2.5, ny)
val, escape = tetra_graph_conv(x, y), tetra_graph_escape(x, y)
import matplotlib.pyplot as plt
for r in range(len(escape)):
for c in range(len(escape[0])):
if escape[r][c] is None:
escape[r][c] = -100
escape[460][250]
plt.contour(escape)
添加回答
举报