# Plotting iterates of a piecewise defined map

This is a follow up question to the one I asked here. I’ve succeeded in figuring out how to plot the first image of my piecewise defined transformation $$T: [-1,1]^2 \to [-1,1]^2$$, but now I want to plot iterates of this map. I’m trying to use Nest[] to do this, but I must not be doing it correctly. Here’s what I’m trying to do:

a=5/12; b=17/12; c=1/4; d=1/3; e=5/3; f=-1/6;
T[x_,y_] := {Piecewise[{{a(x-1)+1, y>0}, {d(x+1)-1, y<=0}}], Piecewise[{{(b-c*x)(y-1)+1, y>0}, {(e-f*x)(y+1)-1, y<=0}}]}; (*the function I’m trying to iterate*)
points = RandomReal[{-1,1},{10000,2}];
ListPlot[Map[Apply[T],points]]


This code plots the image of 10,000 random points transformed by my map $$T$$. But now I want to see where these points go, so I want to iterate the map; say I want to plot the image of $$T(T(x))$$. To do this, I tried:


a=5/12; b=17/12; c=1/4; d=1/3; e=5/3; f=-1/6;
T[x_,y_] := {Piecewise[{{a(x-1)+1, y>0}, {d(x+1)-1, y<=0}}], Piecewise[{{(b-c*x)(y-1)+1, y>0}, {(e-f*x)(y+1)-1, y<=0}}]}; (*the function I’m trying to iterate*)
points = RandomReal[{-1,1},{10000,2}];
ListPlot[Map[Apply[Nest[T, #, 2]&],points]]


This doesn’t give me any errors, but it just gives me axes without any points plotted. So I’m guessing it just doesn’t register that I’m trying to plug points into the function Nest[T, #, 2]&. Should I be doing something else?

Nest and NestList allow you to achieve your aim.

For examples (with slight modification T):

a = 5/12; b = 17/12; c = 1/4; d = 1/3; e = 5/3; f = -1/6;
T[{x_, y_}] := {Piecewise[{{a (x - 1) + 1, y > 0}, {d (x + 1) - 1,
y <= 0}}],
Piecewise[{{(b - c*x) (y - 1) + 1, y > 0}, {(e - f*x) (y + 1) - 1,
y <= 0}}]};
points = RandomReal[{-1, 1}, {10000, 2}];
ListAnimate[
ListPlot[#, PlotRange -> {{-1, 1}, {-1, 1}}, Frame -> True] & /@
NestList[T /@ # &, points, 5]]


• This is what I had in mind in my comment to the OP's previous question. Jan 28, 2021 at 3:59
• Apologies I had not seen previous question J M. I please feel free to link to comment or edit as you see fit. Jan 28, 2021 at 4:01
• Thank you, both of you! This was exactly what I was looking for. Jan 28, 2021 at 4:18
• @DFord enjoy playing and working with Wolfram Language. There are many ways to achieve your goals. Jan 28, 2021 at 4:19