# AMAT 415 — Matlab activity 1: My first fractal

If you haven’t used Matlab before, I recommend you spend half-an-hour going through the first few sections of the Matlab Primer to familiarize yourself with the basis syntax.  In particular, you should learn how to enter and manipulate matrices (with real or complex entries) and generate basic plots.

To test your understanding, can you — without using any loops — generate a 10-by-10 matrix whose $(i,j)$-th entry is $i$? How about one whose $(i,j)$-th entry is $i^2+j$? And, finally, one whose $(i,j)$-th entry is $0$ if $i^2+j<20.5$ and $1$ if $i^2+j>20.5$? (Hint: Consider $\begin{pmatrix}1\\2\\3\end{pmatrix}\begin{pmatrix}1&1&1\end{pmatrix}$.)  Now plot a 10-by-10 grid so that the box at position $(i,j)$ is one color if $i^2+j>20.5$ and another color if $i^2+j < 20.5$.  You’ll want to use the “image” command or something similar.  If you want to choose the colors, look up the “colormap” command.

As our first nontrivial Matlab activity, we’ll generate pictures of Mandelbrot sets.  The classical Mandelbrot set is defined as follows.  For complex numbers $z$ and $c$, define $f_c(z)=z^2+c$. For $n\geq 1$, we define $f_c^{n}(z)=f_c(f_c^{n-1}(z))$. We define the $f_c$-orbit of $0$ to be the set $\{0,f_c(0),f_c(f_c(0)),f_c(f_c(f_c(0))),\ldots\}$. The Mandelbrot set $M$ is defined to be the set of complex numbers $c$ for which the $c$-orbit of $0$ is bounded. In other words, $M$ is the set of $c$ such that $|f_c^{n}(0)|$ does not tend to infinity as $n$ grows.

Let $h$ be a small number, say $h=0.01$ to start with. To generate a picture of the Mandelbrot set (with resolution $h$) we want to build a matrix $A=(a_{pq})$ such that $a_{pq}=1$ if $h((p-1)+(q-1)i)\in M$ and $a_{pq}=0$ if $h((p-1)+(q-1)i)\notin M$.  For simplicity, you can assume that $c=h((p-1)+(q-1)i)\in M$ if $|f_c^{20}(0)|>5$.  I suggest you start by building a 101-by-101 matrix $C$ whose $(p,q)$-th entry is $h((p-1) + (q-1)i)$, and a zero matrix $Z$ of the same size. With this setup, the recursion is simply Z=Z.^2+C. (In Matlab, Z.^2 squares each entry of the matrix Z.)  After you can generate a picture, try playing with the resolution parameter $h$ and the range of values in $C$ to get a “nicer” picture.  In particular, try making the entries of $C$ symmetric about $0$ instead of lying in the first quadrant. (Nicer is subjective, of course.)

Now, generate yourself a personal Mandelbrot set by replacing $f_c$ by $f_c(z)=z^2+0.(\text{your student number})z+c$ or some other interesting function of your choice involving a parameter $c$.  Make a nice picture of your personal Mandelbrot set.  Submit printout of the picture, together with the Matlab code you used to generated it, as part of HW 1. Here’s mine, drawn with $h=0.001$ symmetrically around $0$:

This entry was posted in Uncategorized and tagged , . Bookmark the permalink.