MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Re: Iterated Function System

  • To: mathgroup at smc.vnet.net
  • Subject: [mg67728] Re: [mg67702] Re: Iterated Function System
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Thu, 6 Jul 2006 06:52:03 -0400 (EDT)
  • Reply-to: hanlonr at cox.net
  • Sender: owner-wri-mathgroup at wolfram.com

This adds the colors

Needs["Graphics`"];

M={{1/2,0},{0,1/2}};
T[1,x_]:={0,0}+M.x;
T[2,x_]:={1/2,0}+M.x;
T[3,x_]:={1/4,Sqrt[3]/4}+M.x;

steps=30000;
zi={Random[Integer,{1,3}],{Random[],Random[]}};

res=Module[{rand},
      Thread[{
          Map[
            Last,
            Split[
              Sort[
                NestList[
                  {rand=Random[Integer,{1,3}],T[rand,#[[2]]]}&,
                  zi,steps]],
              SameQ[First[#1],First[#2]]&],
            {2}],
          {Red,Green,Blue}}]];

DisplayTogether[
    ListPlot[#[[1]], 
          PlotStyle->{PointSize[0.00001],#[[2]]}]&/@res];


Bob Hanlon

---- JAMES ROHAL <jrohal at wooster.edu> wrote: 
> Daniel,
> 
> Thanks for the quick response, your algorithm runs much faster. Is there also a way to keep the colors as well? For the NestList function there is no way to differentiate between which function is applied, is there?
> 
> James Rohal
> College of Wooster 2007
> 
> >>> dh <dh at metrohm.ch> 07/04/06 5:01 AM >>>
> Hi James,
> you could e.g. try:
> M = {{1/2, 0}, {0, 1/2}};
> T[1, x_] := {0, 0} + M.x;
> T[2, x_] := {1/2, 0} + M.x;
> T[3, x_] := {1/4, Sqrt[3]/4} + M.x;
> 
> zi = {Random[], Random[]};
> 
> res = NestList[T[Random[Integer, {1, 3}], #] &, zi, 20000];
> 
> ListPlot[res, PlotJoined -> False]
> 
> Daniel
> 
> JAMES ROHAL wrote:
> > I am looking for a faster way to plot Iterated Function Systems in Mathematica. Currently my method is using Barnsley's algorithm which randomly chooses a transformation and applies it to a previous point to get the next point. I then store the points in a list corresponding to the transformation that was applied to it. Is there a faster way to program this using functional programming in Mathematica? Thanks in advance.
> > 
> > << Graphics`MultipleListPlot`
> > << Graphics`Colors`
> > 
> > steps = 30000;
> > 
> > M = {{1/2, 0}, {0, 1/2}};
> > T1[x_] := {{0}, {0}} + M.x;
> > T2[x_] := {{1/2}, {0}} + M.x;
> > T3[x_] := {{1/4}, {Sqrt[3]/4}} + M.x;
> > 
> > zi = {{Random[]}, {Random[]}};
> > T1listPoints = {};
> > T2listPoints = {};
> > T3listPoints = {};
> > 
> > For[i = 1, i < steps, i++;
> > 	rand = Random[Integer, {1, 3}];
> > 	Switch[rand,
> > 		1, {zi = T1[zi], T1listPoints = Append[T1listPoints, Flatten[zi]]},
> > 		2, {zi = T2[zi], T2listPoints = Append[T2listPoints, Flatten[zi]]},
> >         	3, {zi = T3[zi], T3listPoints = Append[T3listPoints, Flatten[zi]]}
> > 	];
> > ];
> > 
> > graph1 = ListPlot[T1listPoints, PlotStyle -> {PointSize[0.00001], RGBColor[1, 0, 0]}, DisplayFunction -> Identity];
> > graph2 = ListPlot[T2listPoints, PlotStyle -> {PointSize[0.00001], RGBColor[0, 1, 0]}, DisplayFunction -> Identity];
> > graph3 = ListPlot[T3listPoints, PlotStyle -> {PointSize[0.00001], RGBColor[0, 0, 1]}, DisplayFunction -> Identity];
> > Show[{graph1, graph2, graph3}, DisplayFunction -> $DisplayFunction];
> > 
> > James Rohal
> > College of Wooster 2007
> > 
> > 
> 
> 

--

Bob Hanlon
hanlonr at cox.net



  • Prev by Date: Re: Confidence intervall
  • Next by Date: Re: Another limit problem
  • Previous by thread: Re: Iterated Function System
  • Next by thread: Confidence intervall