In this lab we will explore the popular fractal images.
Instead of using linear transformations, these use nonlinear
transformations.
There are 6 MATLAB functions we will use.
1. 1D Chaos
The first function is chaos.m which is
a function which explores the behavior of the difference
equation x(n+1) = a x(n) (1-x(n)) for a range of a values.
To use, save the file in the work folder and then in MATLAB type
chaos(0,4)
The two numbers (0 and 4 in this case), specify the range of values for a.
2. 2D Fractals - Quadratic Map
The popular fractal images (Mandelbrot and Julia Sets) are based
on a simple quadratic difference equation (or quadratic map):
z(n+1) = z(n)2 + c
This is really a system of difference equations as z(n)
and c are complex numbers. If we let z(n) = x(n) + i y(n)
and c = a + i b, then this system is
x(n+1) = x(n)2 - y(n)2 + a
y(n+1) = 2 x(n) y(n) + b
This system has equilibrium values, but they are not all stable,
and even if they are stable, not all starting values will reach them.
To perform some iterations with this system, we need to specify
c and a starting value z(0).
quadmap.m is a MATLAB script which prompts
you for a value for c and z(0) and then plots 30 values
of z(n). To enter complex numbers in MATLAB, write them
at 2.5 + 0.3*i.
Save this script and run it with different values of c and z(0).
3. 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(0) 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.
There are two versions of the Julia Set program, one does b/w
and the other does color, using the number of iterations to
leave the box as the pointer to the color map.
julia.m - b/w filled julia set
julia2.m - color filled julia set
Both are functions and are 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],
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
4. Mandelbrot Set
There is only one Mandelbrot Set. It is the set of all c
values, so that starting with z(0) = 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(0) is fixed.
There are two functions for the Mandelbrot Set: b/w and color:
mandel.m - b/w mandelbrot set
mandel2.m - color mandelbrot set
Both are functions and are used by typing
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.
5. 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.