Stats

Popular Posts

Followers

Mathematica 教學 Bifurcation diagram of Logistic Map

戴忠淵 於 2011年7月9日星期六 下午8:56 發表

(*  Definition of Logistic Map *)

lmap[r_][xn_] := r xn (1 - xn);

(*Run n iterations and pick the last m pts*)

np[n_][m_][r_] :=Thread[{r, Take[NestList[lmap[r], Random[], n], -m]}]

(*Collect data from r=r1 to r=r2 with step dr*)

s[r1_, r2_, dr_, n_, m_] := Flatten[np[n][m] /@ Range[r1, r2, dr], 1];

(* rewrite np with CompilationTarget *)

npc = Compile[{{n, _Integer}, {m, _Integer}, {r, _Real}}, {r, #} & /@
NestList[r*#*(1 - #) &, Random[], n][[-m ;; -1]],
CompilationTarget -> "C"
];

t[r1_, r2_, dr_, n_, m_] :=
Flatten[Map[npc[n, m, #] &, Range[r1, r2, dr]], 1]
u[r1_, r2_, dr_, n_, m_] :=
Flatten[ParallelMap[npc[n, m, #] &, Range[r1, r2, dr]], 1]

ex1 = AbsoluteTiming@s[2.9, 4, .0005, 1000, 200];
ex2 = AbsoluteTiming@t[2.9, 4, .0005, 1000, 200];
ex3 = AbsoluteTiming@u[2.9, 4, .0005, 1000, 200];
ex1[[1]]
ex2[[1]]
ex3[[1]]

ListPlot[#[[2]], PlotRange -> {{2.9, 4}, {0, 1}},
PlotStyle -> PointSize[.0001], FrameLabel -> {"r", "xn"},
Frame -> True, RotateLabel -> False]&/@{ex1, ex2, ex3}

Tags:

讀者回應 ( 0 意見 )

發佈留言

Please leave your name and tell me what you thought about this site. Comments, suggestions and views are welcomed.

如果這篇文章對你有幫助,那請留個訊息給我~