gpt4 book ai didi

python - 使用 Python 将 9 倍尖峰 multibrot 和 enneagram 结合起来

转载 作者:行者123 更新时间:2023-12-04 08:18:13 26 4
gpt4 key购买 nike

我正在研究 Python 和 LaTeX(最好是矢量图形 TikZ/Asymptote/PGF/Metapost/GeoGebra,按此顺序)通过在终端上运行简单代码来生成此动画的代码。
这是一个 thread on Tex.SE其中讨论了几种绘制 Mandelbrot 集的方法,但我无法像在 Python 中那样容易地修改 LaTeX 中的数学方程。因此,我切换到 Python 并生成尽可能接近矢量图形的高分辨率输出(~2,000 dpi)。我想绘制尽可能一般定义的 multibrots。例如,当 d 为负时。
恩内布罗特
Enneabrot-animation
以下代码取自 this Mandelbrot (dimension=2) project在 GitHub 上,我需要通过更改指数来创建此分形项目的更高维度版本,例如 Triabrot(维度 = 4)、Pentabrot(维度 = 6)、Heptabrot(维度 = 8)和 Enneabrot(维度 = 10)在定义 Mandelbrot 集的递归方程中。换句话说,我们为 Mandelbrot 分形定义了一个变量 d,而不是 z_{n+1} = z_n * z_n + z_0,我们定义了一个维度变量 d,然后 d 维 Multibrot 的方程将是 z_{n+1} = z_n ^d + z_0 和每个这样的方程将在其稳定区图中产生 d-1 尖点。要了解有关此主题的更多信息,请观看以下两个 YouTube 视频:Times Tables by MathologerMandelbrot Set by Numberphile .
需要为每个输出补丁更改轴;发生这种情况是因为分形在复平面中移动,我们需要沿着镜头移动以通过 Python 观察它们。我们还可以使用哪些其他公式?也许axisFix = ((d^2-4)/d)/10?在这个建议的公式中,d^2-4 是因为我希望 Mandelbrot 分形 (d=2) 打印在中心,如果它没有任何位移打印。因此,轴平移的值将为零。这很有趣,因为它对于 d=-2 也是零,这意味着我们还必须尝试查看像 z_{n+1}=z_n^{-2.0} + z_0 这样的方程。目标是找到最平滑的函数 f(d),使得 f(2)=0 并通过以小尺寸 (0.01-0.1) 的增量增加 d 的值并打印 mandelbrot(threshold,密度,维度)函数在这里定义为动画。功能越流畅,演示文稿中幻灯片动画中的幻灯片过渡越流畅。

import numpy as np
import matplotlib.pyplot as plt
# counts the number of iterations until the function diverges or
# returns the iteration threshold that we check until
def countIterationsUntilDivergent(c, threshold, d):
z = complex(0, 0)
for iteration in range(threshold):
# here is the recurrence relation z_{n+1} = z_n^d + z_0, used for
# drawing d-1-dimensional Mandelbrot creatures (growing fractals)
z = z**d + c
if abs(z) > 4:
break
pass
pass
return iteration

# takes the iteration limit before declaring function as convergent and
# takes the density of the atlas
# create atlas, plot mandelbrot set, display set
def mandelbrot(threshold, density, d):
# it is necessary to change the axis for every patch of outputs;
# this happens because the fractals move in the complex plane
# and we need to move along our lens to watch them through Python
## what other formulas could we use? Maybe axisFix = ((d^2-4)/d)/10?
## d^2-4 is there because I want the Mandelbrot fractal (d=2)
## to be right there were it is printed without any replacement
## so the value of the axis translation would be zero. This is
## funny because it is also zero for d=-2 which means that
## we must also be trying to look at equations like
### z_{n+1}=z_n^{-2.0} + z_0
### the goal is to find the smoothest function
### f(d) such that f(2)=0 and make an animation
### by increasing the value of d by increments of small size (0.01-0.1)
### and printing the output of the mandelbrot function defined here
### as an animation. The smoother the function, the smoother
### the transition of slides in the animation
axisFix = d/10
# location and size of the atlas rectangle
realAxis = np.linspace(-2.25+axisFix, 0.75+axisFix, density)
imaginaryAxis = np.linspace(-1.5, 1.5, density)
# realAxis = np.linspace(-0.22, -0.219, 1000)
# imaginaryAxis = np.linspace(-0.70, -0.699, 1000)
realAxisLen = len(realAxis)
imaginaryAxisLen = len(imaginaryAxis)

# 2-D array to represent mandelbrot atlas
atlas = np.empty((realAxisLen, imaginaryAxisLen))

# color each point in the atlas depending on the iteration count
for ix in range(realAxisLen):
for iy in range(imaginaryAxisLen):
cx = realAxis[ix]
cy = imaginaryAxis[iy]
c = complex(cx, cy)
atlas[ix, iy] = countIterationsUntilDivergent(c, threshold, d)
pass
pass

# plot and display mandelbrot set
fig1 = plt.gcf()
plt.axis('off')
# plt.savefig('mandel.eps', format='eps')
plt.imshow(atlas.T, interpolation="nearest")
# plt.show()
output_name = str(d)+'.pdf'
fig1.savefig(output_name, format='pdf', bbox_inches='tight', dpi=2000)

# time to party!!
dimensions = np.arange(10, 100) / 10
# for d in dimensions:
# mandelbrot(120, 1000, d)

# Enneabrot
mandelbrot(120, 1000, 10)
# Heptabrot
mandelbrot(120, 1000, 8)
# Pentabrot
mandelbrot(120, 1000, 6)
# Triabrot
mandelbrot(120, 1000, 4)
# Mandelbrot
mandelbrot(120, 1000, 2)

最佳答案

这是结果,感谢 Aryan Hemmati 通过将灵魂的九型人格与十维 Mandelbrot 分形合并来编辑最终照片。
Enneabrot animation
我需要一个 Python 和 LaTeX(最好是矢量图形 TikZ/Asymptote/PGF/Metapost/GeoGebra,按顺序)通过在终端上运行简单的代码来生成这个动画。我们可以轻松更改参数以制作 Heptabrot (d=8)、Pentabrot (d=6) 甚至 Triabrot (d=4)。我附上了使用 Python 绘制 Enneabrot (d=10) 的代码,并且我修改了 this code由 Danyaal Rangwala 编写,并在递归方程中定义了一个新变量 d(维数)来计算解的精确平衡区,这最终表明 Enneabrot 是我尝试生成这种分形的最后一个数字(从 d=1.0 开始, 0.1 增量直到 d=10.0)。
在这里,我将发布 Mandelbrot 分形 (d=2) 以及我上面定义的分形的输出:Enneabrot (d=10)、Heptabrot (d=8)、Pentabrot (d=6),甚至是 Triabrot ( d=4)。在此 answer 的下一版本中要遵循的其他图表.
曼德布罗 (d=2)
Mandelbrot

Triabrot (d=4)
Triabrot

五角星 (d=6)
Pentabrot

Heptabrot (d=8)
Heptabrot

Enneabrot (d=10)
Enneabrot

关于python - 使用 Python 将 9 倍尖峰 multibrot 和 enneagram 结合起来,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65615783/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com