在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 - #] &)]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值