HMC Math 63: Linear Algebra II (Summer, 2002)
Further instructions for HW#13
(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 hw13.m into your MATLAB directory, you may load all necessary variables into your workspace simply by typing "hw13" 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.

If you are using a Windows-based version of MATLAB, there should be a print command handy on the figure itself, and printing should be straight-forward. On the other hand, for older or command-line versions, 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 you may then print from a web browser (for example). 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.

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

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. You could e-mail your m-file and figures to your grader, but MATLAB image files tend to be LARGE, and I don't know how he'd feel about that. Maybe I'll ask him.

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

Good luck.