From: John Armstrong Newsgroups: sci.math Subject: Re: Mandelbroth Set Date: Fri, 13 Mar 1998 08:41:26 -0500 Omer Ahmad wrote: > Does anyone out there know about the mandelbroth set? I'm sure you do. > I'm just starting to program, and I was wondering if anyone could help > me with a personal project (I swear it isn't an assignment). How can I > program the mandelbroth set in C++. You don't have to give me the code, > but maybe some hints as to what I should be trying to do. > > Thanks... > > Omer. Firstly, it's the Mandelbrot set, but we won't hold that against you. The Mandelbrot set is the boundary of the set of points c where the set of z in the complex plane with bounded orbits under the map z_n+1 = z_n^2 + c is connected. To cut through the drek, for a fixed c, plot the points of C which don't diverge to infinity under mapping z_n+1 = z_n^2 + c. This actually means that they don't go outside the circle |z| = 2. Now this set can be shown to be connected iff z_0 = 0 is in it. Thus to plot points in Mandelbrot's picture, for each c in the complex plane, start with z = 0. Loop up to a certain number of times, seeing if you're outside |z| <= 2, and stop if you are. If you aren't at the end, plot a black point. c = C z = 0; for(int i = 0; i < 2500; i++) { z = z*z + c; // you'll have to use a complex multiplication } // either use the prepackaged one (yuck) // or write your own (yay) if (mag(z) > 2) plot(c,white); // plot you'll have to write too else plot(c,black); For coloured plots, say 256 colours: c = C z = 0; for(int i = 0; (i < 2550)&&(mag(z) <= 2); i++) { z = z*z + c; // you'll have to use a complex multiplication } // either use the prepackaged one (yuck) // or write your own (yay) if (mag(z) > 2) plot(c,i / 10); // make sure you code it to use integer division else plot(c,0); // 0 is usually black JRJA ============================================================================== From: israel@math.ubc.ca (Robert Israel) Subject: Re: Scanning the plane with Maple Date: 9 Aug 1999 08:03:56 GMT Newsgroups: sci.math Keywords: code to generate the Mandelbrot set In article <37ACB7DC.73D0@ath.forthnet.gr>, Ioannis Galidakis wrote: |>I want to explore some fractal images, and I have two choices: |>One is to code the program in Pascal or C, but I have no explicit |>algorithm for the LambertW function there, so I cannot calculate my |>fixed points in my orbits which are determined by this function. |>If I try to do it in Maple, it will be SLOOOOW. I have heard that it can |>be done though. In any case, in Maple I have the following problem: |>How to scan the plane, say [-1,1]x[-1,1], since Maple plots only |>finitely many functions at a time, and in my case I need a bit-continuum |>of scan lines. If I do something like: |>line:=(x,y)->y; with variable y, I can do a plot(line(x),x=-1..1); is |>there any way to plot the entire range of those scan lines |>bit-simultaneously with y ranging continuously from -1 to 1, (i.e. in |>one plot) with increments dy=dpixel? |>Better yet, how can I approximate the dpixel parsing of a plane square |>or rect if the above is not possible? Write a function F of two variables: the colour of the point [x,y] will be determined by F(x,y). E.g. for the Mandelbrot set, you could use F:= proc(x, y) local zr,zi,tmp, m; zr:= x; zi:= y; m:=0; to 200 while zr^2+zi^2<4 do tmp:= 2*zr*zi+y; zr:= zr^2-zi^2+x; zi:= tmp; m:=m+1; od; m; end: Then try > plot3d(F, -1 .. 1, -1 .. 1, grid=[100,100], shading=ZHUE, style=PATCHNOGRID, orientation=[0,0], axes=BOX); Robert Israel israel@math.ubc.ca Department of Mathematics http://www.math.ubc.ca/~israel University of British Columbia Vancouver, BC, Canada V6T 1Z2