February 26: More Iterated Functions!

Logistic Map

Here is the cobweb plot code from last time:

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]
]

Next, define a double-indexed function. For any r ∈(0,4), the function we iterate is g[r].

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

Make a cobweb plot:

cobwebPlot[g[3.84], 0.1, 1000,{0,1}]

Here is the code that produces the bifurcation diagram:

orbit[r_]:=Drop[ NestList[g[r],0.1,500],100]
column[r_]:={r,#}& /@orbit[r]

orbit[3.84][[100;;120]]

orbit[3.91][[1;;7]]

bifPlot=Graphics[ {PointSize[0.001],Opacity[0.1], Point[Flatten[Table[column[r],{r,3.8, 4,0.0001}],1]]}, AspectRatio->1,Frame->True]

Extending the Collatz function

Hear is an extension of the Collatz function to real numbers: f(x)=[1+cos(πx)](x/4)+[1-cos(πx)]((3x+1)/2).

max=7;
f[x_]:=(1+Cos[Pi*x])*x/4+(1-Cos[Pi*x])*(3x+1)/2;
dots=ListPlot[f/@Range[max],PlotStyle->{PointSize[Large], Purple}];
curves=Plot[{f[x],x/2,3x+1},{x,0,max+0.5}];
Show[curves,dots]

Let's iterate this new function on complex numbers and see what happens!

NestList[f,4.+0.5I,4]

NestList[f, 3.14+0.3I,4]

NestList[f,0.1I,5]

f[x]

ClearAll[f]

I^2

Drawing a Fractal

We want to iterate the function on complex numbers until the value exceeds some bound. We will use a module to do this; the module returns the number of steps until the bound is exceeded.

numSteps[f_,start_,bound_,maxSteps_:100]:=Module[{steps,z=start},
steps=0;
While[ Abs[z]≤ bound && steps<maxSteps,
z = f[z];
steps++
];
steps
]

numSteps[f,4.+I,1000]

Now compute numSteps for lots of complex numbers. We will use DensityPlot to choose complex numbers in a grid and color them according to their resulting number of steps.

DensityPlot[numSteps[f,x+y*I,10000,30],{x,1.8,2.2},{y,-0.1,0.1},PlotPoints->{300,150},ColorFunction->"Rainbow",AspectRatio->Automatic,PlotLegends->Automatic]