**HMC Math 73: Linear Algebra (Spring, 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) 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 in 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)`.

I believe most of the instructions and hints for creating your function are already 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 us white (as seems to be the case under Windows), you'll need to change `'w.'` to `'k.'` in the `plot` line of `frac.m`.

Note: I tried some plotting with Windows, and it seems to like annoyingly large dots when plotting points. Since the beauty of fractals is in the details, this is unfortunate. If you have the wherewithall, you may want to use a non-Windows system, or transfer the numeric output of `frac(C,k)` to a different plotting program. This is not a critical issue... it's purely aesthetic... but that is the whole point of fractals, after all.
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
Myya 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.