Wednesday, September 7, 2016

Mathy Motivation

There's a lot of talk in math education circles about creating and maintaining student motivation and engagement in math courses which normal people find too abstract. Finding out what x is a thousand times is the opposite of what most people find motivating and the fact that something might be useful years in the future is also of limited interest.

My method is to hook students by showing them something visual and engaging (or in other STEM classes, hands-on and interactive) and they'll do a lot of work if they're sold on the result.

For example, teaching students polar coordinates in precalculus is a challenge, when they are already comfortable with the perfectly useful Cartesian (x-y) coordinate system. The Processing graphics package is a great way to approach this and other topics, because it was created by and for artists. The master of cool Processing sketches is "Bees and Bombs" creator David Whyte, who posted something like this:

See the Pen Rainbow Dots by Peter Farrell (@peterfarrell66) on CodePen.
It's a beautiful work of dynamic art, but it's also a graph of a trigonometric function in polar coordinates! If you can motivate students to try to recreate the work of art, they might learn how to use a few supposedly hard math tools along the way.

Students I've shown this to at The Coder School say, "Wow, cool!" And they're motivated to learn to make it themselves. The beginner question is, "How do we get one dot on the screen?" A valuable lesson to students is "Read the documentation!" The p5.js website has a lot of helpful explanations and examples on everything you can do with shapes and transformations.


And once you can put one dot on the screen, it's simple to get a lot of them on the screen: you use a loop. Of course, you have to rotate a bit so they're in different locations:



Now we have as many dots as we want on the screen, but they're all the same distance from the center, so they make a circle:




Trig to the rescue

How do we make them oscillate? This would be a difficult proposition, except there's a math tool that can help tremendously! Sines and cosines are usually introduced as the ratios of sides in right triangles, but by far their biggest application is modeling oscillating behavior. If we change the "ellipse" line in the code above to include a time variable, we can make the dots move in and out of the circle. This would be an excellent precalculus project for working with the equation of waves!

ellipse(0,100*cos((frameCount/15)),15,15);

Unfortunately, we want each dot to move in and out in a slightly different way, and we already have a variable for "shift" we can use. Introduce that into the code and each dot will "lag" a little behind the previous one:

ellipse(0,130+100*cos((frameCount/15)+3*shift),15,15);

It's hard to tell at first that each "dot" is simply oscillating from the center outwards. The rotation is an illusion. Students show off this project proudly, with good reason! Not only is it a cool-looking programming project, but they learned to use a bunch of math tools at the same time.

Tuesday, September 6, 2016

Teaching the Computer to Save You Time

I just talked with a math department head who said her school couldn't fit any programming into her already full math curriculum. "We're strapped for time just to get to everything in our current curriculum," she said. I would suggest that far from being one more thing to add to the pile of things you have to teach in a year, programming would actually reduce the workload and free up time for deeper exploration of topics. Let me give you an example.
A big idea in algebra (and programming) is functions. You put a number in to a function (the input, x) and you get a number out (output, y). In math notation
y = f(x)
There's a time in algebra when they stop using y and just use f(x), and it's never explained why. For example, if the function is "multiply the input by two and add 5," the function looks like this:
f(x) = 2x + 5
So if your input is 3, your output is
f(3) = 2(3) + 5 = 6 + 5 = 11
That's not so hard to do by hand, but pretty soon you start dealing with quadratics and cubics and higher. This is from an Algebra textbook:
The problems above want you to replace x in the function with the number in the parentheses and go through the arithmetic to find the output. You're expected to do this with a calculator, but if you need to input another number, you have to go through it all again! This can be done more effectively with Python. For example, the function in problem #4 translates to
The applet above is interactive! When you press the "Run" button (it looks like an arrow) Python will instantly evaluate the function for x = -7 and print the output (5) in the window on the right. You can evaluate the function for any number by typing a different number in the parentheses.
In problems involving compound interest, falling objects and cost of materials, it's the answer we're interested in, and not the student's ability to evaluate ugly functions like this by hand. Press the Run button and you'll see the answer.
In math class variables are all named with single letters, and it can get confusing. In programming it's possible (and advisable) to use more descriptive variable names, like this:
Now you can understand the formula just by reading it, and it proves the student understands what's going on in the function. Run it to solve problem #4 above.
Using programming tests your knowledge of a topic because you have to teach the computer how to solve a problem! It also tests your ability to be precise and it frees up a lot of time which students would otherwise spend evaluating the same functions over and over. That way they can get deeper into math topics.