6
$\begingroup$

The following code generates an iterative mapping of some trigonometric functions. I have a couple questions about it. The first question is how to optimize this iterative process using mathematica's language and the second is about the result. Do you think the flower looking structures that appear in these plots are a result of some numerical instability or a true part of the mathematics? Additionally, I was trying to get the different listplots to show up in different colors. thx

k = 100000;
m = 5;
For[l = 0, l <= m, l++,
  dt = .0001 + .0005 l; t = 0; x = RandomReal[{0, 2 \[Pi]}]; 
  y = RandomReal[{0, 2 \[Pi]}];
  xs = Table[0 , {n, 1, k}]; ys = Table[0 , {n, 1, k}];
  For[n = 1, n <= k, 
    n++, {xp = x, yp = y, x = Cos[4 yp] Cos[t], y = Sin[xp] Sin[t], 
     xs[[n]] = x, ys[[n]] = y, t = t + dt}]
   data = 
    Partition[Flatten[Table[{xs[[n]], ys[[n]]}, {n, 1, k}]], 2] // N;
  Subscript[p, l] = 
   ListPlot[data, AxesOrigin -> {0, 0}, 
    PlotStyle -> {Hue[l], PointSize[.001]}, AspectRatio -> 1]];
Art = Table[Subscript[p, n], {n, 0, m}];
Show[Art]

enter image description here

If you consider the frequency of the cosine term as a parameter $x_{n+1} = \cos(ay_n)\cos(t_n)$ a bifurcation occurs at approx. $a=2.939$.

$\endgroup$
2
  • 1
    $\begingroup$ Subscript[p, l] = ListPlot[data, AxesOrigin -> {0, 0}, PlotStyle -> {ColorData[3, "ColorList"][[l]], PointSize[.001]}, AspectRatio -> 1] shows i.stack.imgur.com/O3pjs.png $\endgroup$ Jun 2, 2014 at 17:59
  • 4
    $\begingroup$ No, it's not numerical instability. Take a look at Peter de Jong attractor which is created in similar manner. $\endgroup$
    – Kuba
    Jun 2, 2014 at 18:39

1 Answer 1

8
$\begingroup$
i = Module[{k = 100000, m = 5, data, dt, t},
       data = (dt = .0001 + .0005 #; t = -dt;
               NestList[{Cos[4 #[[2]]] Cos[t += dt], Sin[#[[1]]] Sin[t]} &, 
                        RandomReal[{0, 2 π}, 2], k]) & /@ Range[0, m];
       ListPlot[data, AspectRatio -> 1, PlotRange -> {{-1, 1}, .5 {-1, 1}}, Axes->None,
                PlotStyle->({PointSize[.001], #}&/@ ColorData[17,"ColorList"])]
]

And then we go for some embellishments:

ColorNegate@ColorCombine[MeanShiftFilter[#, 5, .3] & /@ 
                         DeleteSmallComponents /@ ColorNegate /@ ColorSeparate[i]]

Mathematica graphics

Edit

This is twice as fast:

r = Compile[{{k, _Integer}, {m, _Integer}}, 
   Module[{dt, t}, (dt = .0001 + .0005 #; t = -dt;
       NestList[{Cos[4 #[[2]]] Cos[t += dt], Sin[#[[1]]] Sin[t]} &, 
        RandomReal[{0, 2 π}, 2], k]) & /@ Range[0, m]]];
Module[{k = 100000, m = 5}, 
 ListPlot[r[k, m], AspectRatio -> 1, PlotRange -> {{-1, 1}, .5 {-1, 1}}, 
  Axes -> None,   PlotStyle -> ({PointSize[.001], #} & /@ ColorData[22, "ColorList"])]]
$\endgroup$
12
  • 1
    $\begingroup$ @Kuba Quality takes time! $\endgroup$
    – Öskå
    Jun 2, 2014 at 18:39
  • $\begingroup$ @Öskå I don't think I it's the case :) belisarius, don't you feel like NestList is kind of slow here? $\endgroup$
    – Kuba
    Jun 2, 2014 at 18:41
  • 1
    $\begingroup$ @Kuba I didn't try to run it, I just liked the image :) But I like the images you linked in the comment above even more. GimmeTehCodez! $\endgroup$
    – Öskå
    Jun 2, 2014 at 18:43
  • $\begingroup$ @Öskå The same as here, it's even simpler because there is no equivalent of dt. $\endgroup$
    – Kuba
    Jun 2, 2014 at 18:44
  • $\begingroup$ Are you implying that this is now easy? $\endgroup$
    – Öskå
    Jun 2, 2014 at 18:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.