**Math 171 - Alexiades**

Lab 8

** Fractals **

There is an excellent article about fractals on
Wikipedia.

A. ** *** Brief background about fractals*

Roughly, fractals are sets (patterns) that are "self-similar" at (many or all) scales. Zooming in, similar patterns appear.
Given a sequence of numbers {z_{n}} generated by some
formula z_{n} = 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 z_{0} is the set of its
iterates {z_{0}, z_{1}, z_{2}, ..., z_{n}, ... }
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 ** z**_{0} is
generated by iterating the function g:
** z**_{n+1} = g( z_{n} ) , n=0,1,2,...

For example, taking g(z)=z^{2}, the sequence will be generated
by:
** z**_{n+1} = z_{n}^{2},

i.e. one squares the current term to get the next term.

For this sequence, if we start with any value z_{0}
with |z_{0}| < 1 then the orbit converges to 0.

If we start with any value z_{0} with |z_{0}| > 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
** z**_{n+1} = g( z_{n} , c )

then for different values of the parameter **c**
the behavior of orbits may be different.
* Quadratic Recursion:*
Consider the sequence generated recursively by
** z**_{n+1} = z_{n}^{2} + c ,

with c complex (so all z_{n} will also be complex).
Then we can:

(1) fix **c** and look at the behavior of orbits of various
starting values z_{0}.

The "filled-in" *Julia Set* is the set of starting points whose orbit does not diverge.

(2) fix z_{0} 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
( = z_{0})
according to number

of iterations it takes for the orbit to "escape"
(get outside the circle of radius R):

* if |z*_{k}| > 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
z_{ij}=( x_{i} , y _{j} ).
= x_{i} + *i* y _{j} (as complex number).

We take each z-grid point as starting point, z_{0},
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 z_{0} escapes,
we color the starting point z_{0}

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.2***i* .

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.4***i* ,
**c = 0+***i* ("dendrite"),
**c = −0.123+0.745***i* ("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 = z^{3} + c,
and 4th degree: z = z^{4} + 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.