Fractals

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).

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

We can also use complex numbers: f(z)=[1+cos(πz)](z/4)+[1-cos(πz)]((3z+1)/2). 
Simplify the function to obtain f(z)=(1/4)[2+7z-(2+5z)cos(πz)].

f[z_]:=(2+7z-(2+5z)Cos[Pi*z])/4;

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.