在Mathematica中使用BinCounts绘制de Jong吸引子
使用BinCounts,可以做如下编码:
naiveDeJong[{x_, y_}, {a_, b_, c_, d_}] := {Sin[a y] - Cos[b x], Sin[c x] - Cos[d y]}Log[(BinCounts[NestList[naiveDeJong[#, {1.641, 1.902, 0.316, 1.525}] &, {1., 1.},10^5], {-2, 2, 0.005}, {-2, 2, 0.005}] + 1)] // ArrayPlot
这个迭代非常慢,并且在运行中很容易代买存储问题。相反的,可以编译迭代器并同时归结到某统计堆。
dejongCompiled = Compile[{{xmin, _Real}, {xmax, _Real}, {ymin, _Real}, {ymax, \
_Real}, {delta, _Real}, {itmax, _Integer}, {a, _Real, 0}, {b, _Real, 0}, {c, _Real, 0}, {d, _Real, 0}}, Block[{bins, dimx, dimy, x, y, tx, ty}, bins = ConstantArray[0, Floor[{xmax - xmin, ymax - ymin}/delta] + {1, 1}];{dimx, dimy} = Dimensions[bins];{x, y} = {0., 0.};Do[{x, y} = {Sin[a y] - Cos[b x], Sin[c x] - Cos[d y]};tx = Floor[(x - xmin)/delta] + 1;ty = Floor[(y - ymin)/delta] + 1;If[tx >= 1 && tx <= dimx && ty >= 1 && ty <= dimy, bins[[tx, ty]] += 1], {i, 1, itmax}];bins], RuntimeOptions -> "Speed"(*,CompilationTarget\[RuleDelayed]"C"*)];ArrayPlot[Log[dejongCompiled[-2., 2., -2., 2., 0.005, 10000000, 1.641, 1.902, 0.316, 1.525] + 1], Frame -> False, ImageSize -> 500, ColorFunction -> (ColorData["CMYKColors"][1 - #] &)]