Mandelbrot集合,是一个很典型的分形案例。前面我们已经介绍很多绘制方法。今天给出一个简单的编程,使用Mathematica。并且将之与Mathematica内置函数做对比。这里使用迭代次数(也就是逃逸世间法)简单编写函数
fun[c_, maxiter_Integer : 10^4] := Abs[
NestWhile[
#^2 + c &, 0, Abs[#] < 2 &, 1, maxiter
]
] < 2
使用ArrayPlot函数进行绘制:
ArrayPlot[
Table[
Boole[fun[N[x + I y], 10^4]],
{y, -2, 2, 1/50}, {x, -2, 1.4, 1/50}
]
]
使用内置函数N[]的精度设置,可以做高精度计算:
ArrayPlot[
Table[
Boole[fun[N[x + I y], 200]],
{y, 0.14, 0.15, 10^-5}, {x, -0.75, -0.74, 10^-5}
]
]
与之做对比,使用Mathematica内置绘制函数绘制,可以得到:
MandelbrotSetPlot[(-0.743030 + 0.126433 I) + {-1 - I,
1 + I}/(1.01^550), MaxIterations -> (100 + 5000),
ImageResolution -> 2000, ColorFunction -> "Rainbow"]
也可以改变颜色函数,得到