Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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$.

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

1 Answer 1

up vote 8 down vote accepted
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"])]]
share|improve this answer
1  
@Kuba Quality takes time! –  Öskå Jun 2 at 18:39
    
@Öskå I don't think I it's the case :) belisarius, don't you feel like NestList is kind of slow here? –  Kuba Jun 2 at 18:41
1  
@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! –  Öskå Jun 2 at 18:43
    
@Öskå The same as here, it's even simpler because there is no equivalent of dt. –  Kuba Jun 2 at 18:44
    
Are you implying that this is now easy? –  Öskå Jun 2 at 18:46

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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