OP edit: This is a Mathematica-specific question about an approach it attempted for a fractal visualization problem described HERE. I'm using the Mandelbrot set there and here as an example, but the solutions apply to a broader fractal problem.
I need to apply an iterative function z
to a list.
z1[n_, c_] := If[n > 0, z1[n - 1, c]^2 + c, c];
c = {-1, -.5, 0, .5, 1};
z1[7, c]
(* {0, -0.350234, 0, 12005.5, 44127887745906175987802} *)
It happens that if Abs[z[n, c]] > 2
at n
, then all subsequent evaluations are also greater than 2. I only need to know the values of c
for which the z
series satisfies Abs[z] < 2
.
I tried to make my calculation more efficient by defining my function like this:
z2[n_, c_] := NestWhile[(#^2 + c) &, c, Abs[#] <= 2 &, 1, n];
This works great on single values of c:
z2[12, 1]
(* 5 *)
but it just returns the List back to me if c is a List:
z2[12, c]
(* {-1, -0.5, 0, 0.5, 1} *)
How can I fix this? I don't want to use a loop because I need to process long lists to high iterations values. In the example below, a lot of time is wasted iterating values that already satisfy Abs[z] < 2
.
stepSize = .0001;
iter = 46;
c = Flatten[Table[x + I*y, {x, -1.42, -1.39, stepSize}, {y, -.005, .025, stepSize}]];
p = z1[iter, c];
r = Pick[c, Abs[#] <= 2 & /@ p];
ListPlot[Transpose[{Re[r], Im[r]}]]
ListContourPlot[]
. $\endgroup$