# Mandelbrot Redux: Day 2

I can only imagine what you all think Iowa is like. Fields of corn and soy beans with churches and one-room school houses poking above the waving grain like children o’er the banister on Christmas morning. Overalls and slack-jawed pragmatism. It probably doesn’t help when I say that I’m currently teaching calculus to one (1) student. This is mostly because the rest graduated last week, and I’m dealing with an exceptionally intelligent junior.

Fun Fact! Field Corn is not he same as Sweet Corn (i.e. Corn-on-the-cob). We do not gorge ourselves on the acres of bounty to the point of maizitis. Field Corn is much “grainier” and is the raw starting point for almost all processed foods. (Corn Syrup, Corn Flour, Corn Chips, etc…)

So the question looms: how to take a student from zero understanding of the basics of infinite series, to a moderately strong command of the concepts of sets, series, and imaginary numbers (a la The Mandelbrot Set). This really puts my teaching philosophy to the test. My student’s goal is to write one of those fractal viewing programs from scratch. Do I really believe that this task/question will lead him through all of the necessary content of infinite series? Do I believe that I’ll be able to guide him without coming up with perfect lectures or razzle-dazzle .ppt slides? Yes.

Those of you for whom the words “Real-World” induce seizures, this appears to be the perfect example of something just being pretty enough to grab a kid. He just liked the way they looked, and off we went.

Here’s what happened today:

We checked out the first section in the book on series. This was a weird experience. I sat down next to the kid, and we began looking through the book like it was a child’s picture book. He pointed out things, I pointed out things. He said, “So series are kind of like functions but you only use regular numbers.” (He meant “integers.”) I let him tell me the story of the chapter as we read it. I asked things like, “Why would people come up with this?” and “What’s the motivation for developing series?”

He responded, “I’m not too sure, but it seems like they’re [series] just kind of interesting, like, you don’t know what they’re gonna do.” This kid is totally my favorite student. Not that teachers have favorites or anything.

The beauty of having a one-student class, is that there’s no need for formal assessment. I can just listen to him talk and get a a good idea of what he knows and what he doesn’t. We did a couple of good problems on the board, and then this kid was ready for the big dance.

# Programming Mandelbrot:

Series and computers are like peanut butter and jelly or malcontent and HS sophomores. Computers are built to think like this. The for loop structure is basically sigma notation waiting to happen. This student has reasonably proficient skills in the basics of programming. So, we jumped straight to Mandelbrot:

Here’s the kicker, *z *and *c* are complex numbers. For high schoolers the words “complex” and “imaginary” are terribly mired in their English denotations. They think that an imaginary number is irrelevant, like an imaginary pot of gold, and they think complex means that they’ll never understand the idea. This is the perfect time to build a little math from scratch. Show them the necessity for imaginary numbers. Why can’t a negative number have a root? Why can’t real and imaginary numbers be combined? This blew my student’s mind as he realized that all real numbers are that way just because their imaginary coefficient is zero.

For those of you that have had complex/imaginary numbers tacked onto your curriculum like an aluminum spoiler on a stock Honda Civic, I really think you should teach the Mandelbrot Set. I know the Mandelbrot Set is kind of a buzz word, and that fractals themselves are these pretty things that seem to have little direct application, but stay with me.

That’s what I thought too, until I watched this: PBS NOVA RULES. I’m not really a mathematician, in fact I’m a trained assumer and premise-simplifier (physicist), so this is all probably old news to you anyway, but the program is really well put together and you get to hear and see Benoit Mandelbrot in all his Frenchiness!

So what did my student and I do? We watched the show and programmed together. This was fun. He had his program projecting on the board, and we GoogleDoc-ed it.

I taught a mini lecture about the complex plane. I love the concept of the mini lecture. (in edu-jargon: “lecture burst,” which makes me think of pimples and the blueberry girl in the original Willy Wonka.)

Here’s the idea if you’re here for content. All complex numbers have a real and imaginary part (see *z* above). *a *reprsents how real the number is, and *b* represents how imaginary it is. If you plot these two numbers on a plane with axes for real and imaginary you can see all sorts of great stuff:

The Mandelbrot Set accepts complex numbers for the parameter *c*. (See the recursive statement above, assume *Z0* = 0) If you follow out a few terms of series, you can tell if your arbitrary choice for *c* is going to fly wildly off to infinity or be damned to repeat itself. The values for *c *that repeat themselves are *in *the set. The values that fly off are *out*. This is my stupidly simple way of thinking about sets. You’re either in or out, kind of like Marty McFly being propositioned by future Biff. The numbers that are *in* make up the set. These numbers turn out to make beautifully haunting images when they’re graphed (in the complex plane).

Here’s the program my student wrote:

`<script>`

`function mandel()`

`{`

`for(i=-2; i<=1; i+=0.01)`

`{`

`for(k=-1; k<=1; k+=0.01)`

`{`

`newi = i;`

`newk = k;`

`a=0;`

`b=0;`

`iteration = 0;`

`iteration_max = 1000;`

`while((a*a+b*b)<=4 && iteration<=iteration_max)`

`{`

`atemp = a*a - b*b + newi;`

`b = 2*a*b + newk;`

`a = atemp;`

`iteration++;`

`}`

`if(iteration==(iteration_max + 1))`

`{`

`color = "rgb(0,0,0)";`

`}`

`else`

`{`

`color = "rgb(256,0,0)"`

`}`

`var canvas = document.getElementById("canvas");`

`if(canvas.getContext)`

`{`

`var ctx= canvas.getContext("2d");`

`var fillColor=color`

`ctx.fillStyle=fillColor`

`var x=(i+2)*100`

`var y=(k+1)*100`

`ctx.fillRect(x,y,1,1);`

`}`

`}//2nd for`

`}//1st for`

`}//function`

`</script>`

`<body onload='mandel()'>`

`<canvas id='canvas' height='400' width='400'> does not support</canvas>`

`</body>`

You can run it, if you’d like. Just copy it and save it as a .html document and load it in a browser; you don’t even have to be connected to the Internet (but if you’re reading this, you are already, OMG!) Not the perfect program, but hey, I can’t believe that it works at all.

It relies on the canvas tag, which is total HTML5 butter. You’ll need a fairly modern browser, but, as Meyer puts it, we’re all freaks, so I’ll assume you’re running Chrome 5 or something of similar ilk. Have fun! I think algebra and pre-calc students will enjoy figuring out how we splayed open the imaginary number in order to keep track of its real and imaginary parts.

I’ll explain the program more in the next post. My student is getting really fancy with it. Mouse-click zooming and everything!