In the last lab we explored the behavior of some nonlinear
DEs and (hopefully) discovered that it was not so easy
to classify the bounded/unbounded behavior or sometimes
any type of behavior based on the parameter values.
In this lab we will explore some nonlinear DEs that generate
popular fractal images by systematically exploring and marking
the parameter values. Here's an example of an image you'll be
able to make during this lab.
We'll primarily use the complex DE called the quadratic map:
z(n+1) = z(n)^2 + c
We'll either vary z(1) in some range of complex values for
a fixed value of c, or vary c over a range for some fixed
value of z(1).
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
wrote:
julia.m - color filled julia set
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
-1.32
0.48 + 0.48i
1.5i
-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. (It will come out in b/w).
If you want to save a graph as a jpeg to put on your webpage,
type
axis off
print -djpeg your_filename.jpg
If you want another type of file, use help print to get the options.
V. Assignment
1. Generate several Julia sets.
2. Generate different views of the Mandelbrot set.
3. Have fun!