More Iterated Functions!

Math 242 Modern Computational Math, spring 2021

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

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

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

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

Now we can make a cobweb plot:

cobwebPlot[h[3.6875], 0.8, 1000,{0,1}]

NestList[h[3.84],0.1,100]

Bifurcation Diagrams

For a given r value, we will compute 500 iterates of h. Often, the iterates settle into a cycle, but there may be some initial noise before the cycle emerges. To ignore the noise, we will drop the first 100 iterates, as in the following function eventual[r]:

eventual[r_]:=Drop[ NestList[h[r],0.1,500],100]

eventual[3.3]

Now we define a set of points (r,y), for all values y in eventual[r]:

points[r_]:={r,#}& /@eventual[r]

points[3.3]

Now make a plot of the points obtained for lots of values of r:

bifurcationPlot=Graphics[ {PointSize[0.002],Opacity[0.1], Point[Flatten[Table[points[r],{r,3.5,4,0.0005}],1]]}, AspectRatio->1/2,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]

NestList[f,5,20]

NestList[f,1.642,200]

NestList[f,1.0+I,20]

NestList[f,0.1+0.2I,20]

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
]

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,100,30],{x,1.9,2.1},{y,-0.1,0.1},PlotPoints->{200,200},ColorFunction->"Rainbow",AspectRatio->Automatic,PlotLegends->Automatic]

The Mandelbrot Set

The Mandelbrot set is a famous fractal. It is defined to be the set of complex numbers c such that the function (Subscript[m, c])(z)=(z^2)+c remains bounded in absolute value when iterated from z=0.

m[c_][z_]:=z^2+c

We can plot the Mandelbrot set:

DensityPlot[numSteps[m[x+y*I],0,50],{x,-2,1},{y,-1,1},PlotPoints->{300,100} , ColorFunction->"GreenPinkTones",AspectRatio->Automatic,PlotLegends->Automatic]

Question: How is the Mandelbrot set connected to the bifurcation diagram of the logistic map?