GS 2005/Math - Collins
Computer Lab
Fractal Patterns: Mandelbrot and Julia Sets

From the world of sequences, we'll look at sequences generated
by the iteration

   z(n+1) = z(n)^2 + c

called the quadratic map.  The starting value z(1)
and the fixed value c are both complex numbers and we'll vary
them over various ranges and determine the behavior of the
resulting sequences.  To make things simple the only behavior
we will be looking for is whether or not the sequence is
bounded, i.e. if it remains close to the origin. 

0. Complex Background

   All the values we'll be using will be complex numbers, like 1+2i.
   MATLAB handles complex arithmetic with no extra effort.
   To enter complex numbers just write 1+2i or 1+2*i or 3.023943-i*72.39
   If you have problems it may be because you've accidently changed
   i from its default value, if so, say clear i and all should
   be fine. 

I. Julia Sets

   For each value of c in the quadratic map, there is a Julia set.
   The Filled Julia Set is the set of all z(1) such that
   the values z(n) stay bounded.  To create the set
   we take starting values in the box [-2,2]x[-2,2] and for each
   one we iterate until either we leave the box, or we reach the
   limit on the number of iterations.  If we reach the limit, we
   say the point is in the set (and draw it).

   Program Info

   Input consists of  c (complex) and m (integer).  m denotes
   how many subdivisions we use in the range of parameter
   values.  For example if m=4 then we use c = a+bi where
   a, b each comes from the values {-2, -1, 0, 1, 2}.  So
   we'll use 25 different values for c in this case.

   To make the cool color images, keep track of how
   many iterations it takes before the iterates leave
   the box.  We'll then color the image according to
   these values.  For example if m=4, then we need
   to store 25 values in a 5x5 array: it.  So if we number
   the possible values for a (and b) from 1 to 5, then
   we can store the result of our calculation using
   the 2nd value for a and the 4th value for b in the (2,4)
   spot in the array, by it(2,4) = k where k
   is the number of iterations done.

   Then to view the resulting picture, just use image(it).
   (See below about more about color)

   This is not an impossible program to write, but it does
   require two for loops and a while loop, so if you
   are overwhelmed, you can download a version I

        julia.m - color filled julia set
            (right click and save target in directory C:/matlab???/work)

   This is a function called by either
      julia(c,m)  or julia(c,m,[xmin xmax ymin ymax])
   where the first instance uses the range [-2,2]x[-2,2], and the
   second instance uses the range [xmin,xmax]x[ymin,ymax]
   m is the number of points to divide the ranges into.
   Try m = 50 to start.  It might take to long to compute
   with larger m.

   Here's some values for c you might try:
      -1.5 + 0.2i
      -0.1 + 0.75i
      -0.4 + 0.8i
       0.28 + 0.53i
      -0.11 + 0.86i
       0.48 + 0.48i
      -0.5 + 0.57i
      -0.4 + 0.4i

II. Mandelbrot Set

   There is only one Mandelbrot Set.  It is the set of all c
   values, so that starting with z(1) = 0, the values z(n)
   remain bounded.   The calculation is the same as for the Julia Set,
   except that c is taken from some range and z(1) is fixed.

   This program is just a slight modification of the Julia Set program.
   Again, if you don't want to write the program, you can get a 
   copy here:
      mandel.m - color mandelbrot set

   It is a function called by either
      mandel(m) or mandel(m,[xmin xmax ymin ymax])
   where m is the number of points to use in each direction
   and the range is either the default [-2,2]x[-2,2] or as specified.

   Again, try small values of m first to see how long it takes.

III. (Challenge) Other DEs

   Any function can be used to generate Julia and Mandelbrot sets.  Here's
   some additional functions you can try:

   1. z(n+1) = z(n)^2 + c*z(n)
   2. z(n+1) = c*exp(z(n))
   3. z(n+1) = c*sin(z(n))
   4. z(n+1) = z(n)^2/(1 + c*z(n)^2)

IV. Useful Information

   You can change the colors by using the command
       colormap  colormapname
   where colormapname is one of:
      hsv  hot  gray  bone  copper  pink  white  flag  lines
      colorcube  jet  prism  cool  autumn  spring  winter  summer

   If you want to print out a graph, you can just choose print from
   the file menu.

   If you want to save a graph as a jpeg to put on your webpage,
       axis off
       print -djpeg your_filename.jpg

   Or you can choose export from the file menu.
   If you want another type of file, use help print to get the options.
Last Modified: June 2, 2005