Generating the Mandelbrot Set

Experimental Math Homework - Feb 12 (Due Feb 14) 2009

Since I already handed in (on paper) the Maple version of this assignment before the updated instructions were posted, I have re-done it on Mathematica as a challenge, and in the hopes that perhaps a Mathematica-generated image might be easier to make, and easier to make look good. Maple's graphics are unfamiliar to me, and they seem, at least, to be fairly limited, so I'll give this a try in Mathematica.

Off[General::"ovfl"];
M[c_, z_] := M[c, z] = z2 + c;
IsGood[c_, K_, L_] := IsGood[c, K, L] = Module[{z,i},
    z = 0;
    For[i = 1, i <= K, i++,
     z = N[M[c, z]]];
    If[Abs[z] < L, Return[True], Return[False]];
   ];
MS[a_, R_, K_, L_] := MS[a, R, K, L] = Module[{S, re, im},
   S = {};
   For[re = -a, re <= a, re += R,
    For[im = -a, im <= a, im += R,
     If[IsGood[re + im \[ImaginaryI], K, L], 
       S = S \[Union] {{re, im}}];
     ]];
   Return[S];
   ]

Manipulate[
 ListPlot[MS[2, r, 100, 10], PlotRange -> {{-2, 2}, {-2, 2}}, PlotStyle -> Red], 
 {r, 0.1, 0.01, -0.01}]

As we can see, Mathematica can be used to generate an interactive animation of this applet at various levels of refinement. Furthermore, I've made use of Mathematica's ability to remember previous values of functions and modules (definitions like IsGood[c_, K_, L_] := IsGood[c, K, L] = ...). That — and the fact that (as far as I can tell) Mathematica is just plain faster than Maple — allows us to compute and display these sets in only a few minutes, instead of what took Maple over an hour. Granted, this might also have to do with my inability to use Maple as efficiently as possible, however I used precisely the same "speed ups" for each system, so the superiority of Mathematica in this case does not seem to be biased by my familiarity with it.