HMC Math 73: Linear Algebra (Fall, 1999)
Further instructions for HW#11
(Writing a fractal-drawing function frac.m)

In this assignment you are asked to create a MATLAB function frac(C,k) that takes as input the data for an Iterated Function System (IFS) (in the matrix C) and then draws the indicated fractal (where k is the number of points plotted). Each function in the system is a linear function f(x)=Ax+b, where A is a 2x2 matrix, and b a 2x1 vector. These are stored in augmented form [A b], and then stacked. So, for example, Sierpinski's Triangle is generated by the three functions
| 0.5  0  | |x|   | 0 |
|  0  0.5 | |y| + | 0 |

| 0.5  0  | |x|   | 0.5 |
|  0  0.5 | |y| + |  0  |

| 0.5  0  | |x|   | 0.25 |
|  0  0.5 | |y| + | 0.5  |
This data is stored in the single matrix
| 0.5   0    0   |
|  0   0.5   0   |
C = | 0.5   0   0.5  |
|  0   0.5   0   |
| 0.5   0   0.25 |
|  0   0.5  0.5  |
which is the input, along with the number of iterations k, into frac(C,k).

Most of the instructions and hints you'll need for actually creating your function are contained in the comments in the frac.m template provided.

Notice that the function as written actually returns the 2-by-n array of data points generated. As a result, you may want to supress the output when you call your function, or alter its prototype so that it returns nothing. When you start testing your frac(C,k) on the data sets provided, you may want to experiment with the k-value that gives the best picture without taking too much time. I've found that k=10000 works pretty well for most fractals, although this may vary. If you move the provided file hw11.m into your MATLAB directory, you may load all necessary variables into your workspace simply by typing "hw11" at the MATLAB command line. This file contains the variables Sier, Koch, Frac1, Frac2 and Frac3. So, for instance, typing
> frac(Sier,10000)
should generate a picture that looks something like this.

Images from MATLAB may be printed with the print command (as usual, type help print for more info). Your system should be configured so that simply typing print at the MATLAB command line will print the currently displayed image from an appropriate printer. Typing
> print -dgif8 fname
will save the image in your MATLAB directory as fname.gif, which will allow you to submit this portion of your homework via e-mail. If your system doesn't support the -dgif8 option, try -dbmp256 to save as a bitmap, or check help print for similar options. If the background color of your plot's display is black (as seems to be the case under UNIX), you'll need to change 'k.' to 'w.' if you're using the plot command, or [0 0 0] to [1 1 1] if you're using scatter.

Note: I tried some plotting with the Windows version using the plot command, and it seems to like annoyingly large dots when plotting points, regardless of what plot style you indicate. Since the beauty of fractals is in the details, this was unfortunate. It seems that using the scatter command instead rectifies this problem, so the supplied code for "frac.m" has been modified to reflect this.

Here's what you are expected to submit for this portion of your homework...

• The source code of your frac.m file
• Eight fractal drawings (2 from 11B, 3 from 11C, 2 from 11D, and 1 from 11E).
• The three IFS data matrices you came up with for 11D and 11E.
No MATLAB diary file is reuqired for this portion of the assignment, and I do not want to see thousands of numeric data points generated before plotting. All this material may, as usual, be submitted to your graders via e-mail. If you are planning to do so, you may save your images as GIFs or BMPs (see above), and attach them.

As always, if you have any problems, questions or comments, don't hesitate to contact me.

Good luck.