Lab 8
Fractals
There is an excellent article about fractals on Wikipedia.

Roughly, fractals are sets (patterns) that are "self-similar" at (many or all) scales. Zooming in, similar patterns appear.
• Given a sequence of numbers {zn} generated by some formula zn = f(n), as n → ∞ ,
either the sequence converges (towards some limit) or it diverges, e.g. tends to ±∞ .
• If a sequence is defined recursively (iteratively), i.e. the next term is determined
from the previous term(s), then with different starting value(s), the convergence
behavior of the sequence may be different.
The orbit of a starting point z0 is the set of its iterates {z0, z1, z2, ..., zn, ... }
• A very important class of recursions are of "fixed point type": z = g( z ) for some function g(z).
Then the orbit of a starting z0 is generated by iterating the function g:  zn+1 = g( zn ) , n=0,1,2,...
For example, taking g(z)=z2, the sequence will be generated by: zn+1 = zn2,
i.e. one squares the current term to get the next term.
For this sequence, if we start with any value z0 with   |z0| < 1 then the orbit converges to 0.
If we start with any value z0 with |z0| > 1 then the orbit diverges (to infinity). Try it! can you see why?
• If a sequence is defined recursively by a formula involving a parameter, like zn+1 = g( zn , c )
then for different values of the parameter c the behavior of orbits may be different.
• Quadratic Recursion: Consider the sequence generated recursively by zn+1 = zn2 + c ,
with c complex (so all zn will also be complex). Then we can:
(1) fix c and look at the behavior of orbits of various starting values z0.
The "filled-in" Julia Set is the set of starting points whose orbit does not diverge.
(2) fix z0 and look at the behavior for various c. The Mandelbrot Set is of this type.
Look them up on wikipedia.

Since each complex number z=x+iy corresponds to a point (x,y) on the xy-plane, we can plot points using various coloring schemes.
Escape-time-algorithm coloring scheme: provides a nice coloring scheme to display fractal shapes.
We pick an "escape radius" R, and color starting points z ( = z0) according to number
of iterations it takes for the orbit to "escape" (get outside the circle of radius R):
if |zk| > R then k-th iterates escaped. The ingredients are:
• window: choose a rectangular window of dimensions W × H , for −W < x < W and −H < y < H
• grid: choose Mx grid points for x ∈ [−W , W] and My grid points for y ∈ [−H , H]. Construct an x-grid and a y-grid.
Then z-grid points are   zij=( xi , y j ). = xi + i y j (as complex number).
We take each z-grid point as starting point, z0, and compute its orbit.
For simplicity, one can use a square window by taking H=W and My=Mx=M.
• maxIT = number of ITerations to allow.
• coloring scheme: Choose Ncolors = number of colors in the pallet.
If the k-th iterate of z0 escapes, we color the starting point z0
by scaling relative to the number Ncolors:   color = Ncolors ( 1 − k / maxIT ).

B. To do:
1. julia1.m code: Implement the "escape-time algorithm" in a matlab script "julia1.m".
a. Good default values are: W=2, M=100 , R=2 , maxIT=20, Ncolors=64, and to start with c = −1−0.2i .
Play around with the program trying different parameter values to see the effect, e.g.   R = 1 or 3,   M = 50 or 200, etc.
Different fractal shapes appear for different c . Some interesting ones are:
c = −1,   c = 0.4+0.4i ,   c = 0+i ("dendrite"),   c = −0.123+0.745i ("Douadi rabbit")   Try them!
You can enter complex numbers in Matlab using i, as 0.3+0.4i or as 0.3+0.4*i
b. Other powers may also work, try the cubic: z = z3 + c, and 4th degree: z = z4 + c with c=−1
c. Which one is your favored?

2. julia2.m code:
a. Copy your (debugged) "julia1.m" to new file "julia2.m" and modify it into a
Matlab function with two input arguments: c , M . Test and debug with various inputs.
b. Then make it more flexible, so as one can call it with 2 or 1 or 0 arguments
[use  "if( nargin ) < 2"  and  "if( nargin ) < 1" and insert defaults for appropriate parameters].
Test and debug with 2 inputs: (c,M), with 1 input: (c), and with no inputs.
c. Insert short comments explaining what is being done.

C. Prepare for submission:
1. Copy your "julia2.m" code to "julia.m"
2. Edit the "julia.m" file to clean it up,
3. At the top insert % Name , Date , Lab8
4. Then insert the c value that generated your favored pattern: % my favored c = ????
5. Run it with your favored c and M=200
6. Publish it on Matlab: e.g. if c = −1−0.2i : publish( 'julia(−1−0.2i, 200)' , 'pdf' )
7. Check the resulting "julia.pdf" to make sure it contains what it should (code and plot).
8. Submit on Canvas.