Iterated Functions

Math 242 Modern Computational Math, spring 2021

Define the Collatz function:

c[n_?OddQ]:=3n+1
c[n_?EvenQ]:=n/2

Create a module that produces the sequence of Collatz iterates, starting with n, until reaching 1:

colSeq[n_]:=Module[{seq={n}},
While[Last[seq]≠ 1,
AppendTo[seq,c[Last[seq]]]
];
seq   (* return the sequence *)
]

Investigation of the max value in a Collatz sequence:

colMax[n_]:=Max[colSeq[n]]

colMax[3331]

Plot the max for a bunch of values of n:

maxList=colMax/@Range[10000]

ListPlot[maxList,AxesLabel->{"n","max in Collatz sequence"}]

Logistic Map

g[x_]:=8/5*x(1-x)

N[NestList[g,0.3,20],10]

The following module produces a “Cobweb Plot”. (Code modified from https://community.wolfram.com/groups/-/m/t/153946)

cobwebPlot[f_,start_,n_,xrange:{xmin_,xmax_}]:=Module[{cob, coor,x,g1,g2},
cob=NestList[f,N[start],n];
coor = Partition[Riffle[cob,cob],2,1];
coor[[1,2]]=0;
g1=Graphics[{Purple,Opacity[0.2],Line[coor]}];
g2=Plot[{x,f[x]},{x,xmin,xmax},PlotStyle->{Blue,Black}];
Show[{g1,g2},Frame->True]
]

Usage is: cobwebPlot[ function, starting value, number of iterates, {xmin, xmax} ], where xmin and xmax specify the domain to be plotted.

cobwebPlot[g,0.3,30,{0,1}]

h[r_][x_]:=r*x(1-x)

cobwebPlot[h[3.25],0.7,1000,{0,1}]

NestList[h[3.25],.7,30]

cobwebPlot[h[3.1],0.4,1000,{0,1}]

cobwebPlot[h[3.7],0.7,10,{0,1}]

cobwebPlot[h[3.5],0.6,1000,{0,1}]

NestList[h[3.5],.6,100]

Can you come up with a value of r and a starting value (Subscript[x, 1]) such that the sequence of iterates alternates between 3 values? ...or 5 values? ...or your favorite number of values?