2
$\begingroup$

I have the following equation:

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

I want to map this on the imaginary plane such that if it converges under iterations of the function then it is plotted. I would like to then color this in a Mandelbrot type way. How would I go about plotting this?

The goal is to explore the fractal mentioned here.

This is the type of image i'm trying to produce with the ability to zoom in to particular points.

Goal

$\endgroup$
8
  • 1
    $\begingroup$ Have you seen Speeding up this fractal-generating code $\endgroup$
    – user9660
    Commented May 20, 2016 at 7:03
  • $\begingroup$ Have you seen MandelbrotSetPlot $\endgroup$
    – user9660
    Commented May 20, 2016 at 7:11
  • $\begingroup$ Have you seen Mandelbrot Set $\endgroup$
    – user9660
    Commented May 20, 2016 at 7:14
  • 3
    $\begingroup$ Tweak as needed: DensityPlot[-Length[FixedPointList[Function[z, (2 + 7 z - (2 + 5 z) Cos[Pi z])/4], x + I y, 100, SameTest -> (Abs[#2] > 25. &)]], {x, -5, 5}, {y, -1, 1}, AspectRatio -> Automatic, ColorFunction -> (RGBColor[0, 0, #] &), PlotRange -> All] $\endgroup$ Commented May 20, 2016 at 8:04
  • 3
    $\begingroup$ I'm always at a loss with these pictures, about what is being plotted. Nathaniel Johnston writes that the black portions of the plot are areas where the orbit is bounded (Check out the Orbit function here). But what is the color in the rest of the plot based on? $\endgroup$
    – Jason B.
    Commented May 20, 2016 at 9:59

1 Answer 1

12
$\begingroup$

One way of coding the iterations may be defined as follows. The function CollatzFractal01[z0] returns a list {Abs[z],iter}, where Abs[z] is the final value of z, and iter is the number of iterations required to escape the bound of Abs[z]>200. Use compilation and parallelisation for speed.

CollatzFractal01 = Compile[{{z0, _Complex, 0}},
   Module[{iter = 0, max = 3000, z = z0},
      While[iter++ < max, 
         If[Abs[z = (2 + 7 z - (2 + 5 z) Cos[Pi z])/4] > 200., Break[]]];
      {Abs[z], iter}],
   CompilationTarget -> "C", Parallelization -> True, 
   RuntimeAttributes -> {Listable}];

Generate a table of locations in the complex plane with ParallelTable.

d = ParallelTable[i + I*j, {j, -0.5, 0.5, 0.001}, {i, 0.3, 2.5, 0.001}];

Graphics[Raster[...]] can be faster than ArrayPlot[...]. This plot shows the final Abs[z].

Graphics[Raster[
   Rescale[Log[Log[CollatzFractal01[d][[All, All, 1]] + 1.] + 1.]],
   ColorFunction -> (ColorData["FallColors", 1 - #] &)],
   ImageSize -> 600, Background -> Black]

CollatzFractal01 Abs z

This plot shows the number of iterations.

Graphics[Raster[
   Rescale[Log[Log[CollatzFractal01[d][[All, All, 2]] + 1.] + 1.]],
   ColorFunction -> (ColorData["Rainbow", #^0.5] &)],
   ImageSize -> 600, Background -> Black]

CollatzFractal01 iter

Slightly redefining your original equation gives more "interesting" plots, with far more structure. However, the calculation time increases substantially.

CollatzFractal02 = Compile[{{z0, _Complex, 0}},
   Module[{iter = 0, max = 3000, z = z0},
      While[iter++ < max, 
         If[Abs[z = (1 + 4 z - (1 + 2 z) Cos[Pi z])/4] > 200., Break[]]];
      {Abs[z], iter}],
   CompilationTarget -> "C", Parallelization -> True, 
   RuntimeAttributes -> {Listable}];

The iteration count for example:

CollatzFractal02 iter

$\endgroup$
1
  • 1
    $\begingroup$ Only slightly slower: DensityPlot[Log[1 + Log[Length[FixedPointList[Function[z, (2 + 7 z - (2 + 5 z) Cos[Pi z])/4], x + I y, 3*^3, SameTest -> (Abs[#2] > 200. &)]]]], {x, 1/3, 5/2}, {y, -1/2, 1/2}, AspectRatio -> Automatic, ColorFunction -> (ColorData["Rainbow", Sqrt[#]] &), PlotPoints -> 145, PlotRange -> All] $\endgroup$ Commented May 21, 2016 at 17:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.