# NestList and RandomChoice from a list of functions

I am tryingg to modify Chaos Game Fractals from Wolfram Demonstrations. The part I am having problem with is this. Original code:

m1 = .5; m2 = 0; m3 = 0; m4 = .5; n1 = .5; n2 = 0; n3 = 0; n4 = .5;
k1 = .5; k2 = 0; k3 = 0; k4 = .5;
NestList[RandomChoice[{{{m1, m2}, {m3, m4}}.# + {0,
0}, {{n1, n2}, {n3, n4}}.# + {1/2,
Sqrt[3]/2}, {{k1, k2}, {k3, k4}}.# + {1, 0}}] &, {1, 1}, 2]


This works. The output is

{{1, 1}, {1., 1.36603}, {1., 1.54904}}


(In the original code we have 10000 insted of 2)

But if I define first the list of functions:

F={{{m1, m2}, {m3, m4}}.# + {0,
0}, {{n1, n2}, {n3, n4}}.# + {1/2,
Sqrt[3]/2}, {{k1, k2}, {k3, k4}}.# + {1, 0}};


And then do the NestList:

 NestList[RandomChoice[F] &, {1, 1}, 2]


the output is

{{1, 1}, {{{0.5, 0}, {0, 0.5}}.#1, {{0.5, 0}, {0, 0.5}}.#1}, {{{0.5, 0}, {0, 0.5}}.#1, {{0.5, 0}, {0, 0.5}}.#1}}

Question: If my list of functions is longer and functions are more complicated ( I would like to use Table to create my list of functions, perhaps even compiled functions), how can I make the second method to work? I would like to understand the reason why it is not working?

• Dear @arkajad, you've been using this site for more than two years now, and you've never voted and never accepted an answer. Please follow the advice in the following comment to improve your collaboration with the site (don't worry, you don't need to put much effort on it) Feb 27, 2015 at 12:23
• When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! Feb 27, 2015 at 12:23
• Please start ASAP accepting answers to your past questions and voting up (at the very least) those people that had helped you with effort and ideas Feb 27, 2015 at 12:25

SeedRandom[42];
m1 = .5; m2 = 0; m3 = 0; m4 = .5; n1 = .5; n2 = 0; n3 = 0; n4 = .5;
k1 = .5;
k2 = 0; k3 = 0;
k4 = .5;
F = {({{m1, m2}, {m3, m4}}.# + {0, 0}) &,
{{n1, n2}, {n3, n4}}.# + {1/2, Sqrt[3]/2} &,
{{k1, k2}, {k3, k4}}.# + {1, 0} &};

ListPlot@NestList[RandomChoice[F][#] &, {1, 1}, 1000]


• Thanks. This works. But still, I would like to understand the reason why the first method in my post works while the second does not work. Should not they be completely equivalent? If are not equivalent - why? Why Mathematica parses them differently? Feb 27, 2015 at 7:55