Algebra and Programming with VPython

Computer programming is the place where algebra comes to life. Students seem to get really excited when they write even the simplest instructions and see the output on the screen. I’m not sure exactly why this is the case, but I suspect it has something to do with being able to see the transition from abstract programming instructions to “concrete” results.

So I’ve decided to supplement my Algebra classes with an introduction to programming. I’m using the Python programming language, or, more specifically, the VPython variant of the language.

Why VPython? Because it’s free, it’s an easy-to-use high-level language, and it’s designed for 3d output, which seems to be somewhat popular these days. The oohs and aahs of seeing the computer print the result of a+b turn into wows when they create their first box. I’ve used the language quite a bit myself, and there are a lot of other interesting applications available if you search the web.

VPython was created to help with undergraduate physics classes, but since it was made to be usable by non-science majors, it’s really easy for middle and high school students to pick up. In fact, NCSU also has a distance education course for high school physics teachers. They also have some instructional videos available on YouTube that provide a basic introduction.

Image from a game created by middle school student Ryan W.

I use VPython models for demonstrations in my science classes, I’ve had middle school students use it for science projects, and I’ve just started my middle school algebra/pre-algebra students learning it as a programming language and they’re doing very well so far.

What I hope to document here is the series of lessons I’m putting together to tie, primarily, into my middle school algebra class, but should be useful as a general introduction to programming using VPython.

Getting VPython

You’ll need to install Python and VPython on your system. They can be directly downloaded from the VPython website’s download page for Windows, Macintosh or LINUX.

Running a Python program.

Once they’re installed, you’ll have the IDLE (or VIDLE) program somewhere on your system; a short-cut is usually put on the desktop of your Windows system. Run (double-click) this program and the VPython programming editor will pop up any you’re ready to go. You can test it by typing in something simple like:

a = 1
b = 2
c = a + b
print c

Then you run the program by going through the Run–>Run Module in the menu bar.

Which should cause a new window to pop up with:

Python 2.7.1 (r271:86882M, Nov 30 2010, 09:39:13) 
[GCC 4.0.1 (Apple Inc. build 5494)] on darwin
Type "copyright", "credits" or "license()" for more information.
>>> ================================ RESTART ================================
>>> 
3
>>> 

Even better might be to test the 3d rendering, which you can do with the following program:

from visual import *

box()

which creates the following exciting image:

A box created with VPython. It looks much more interesting if you rotate it to see it in perspective.

To rotate the view, hold down and drag the right mouse button. To zoom in or out, hold down the right and left buttons together and drag in and out.

A rotated, zoomed-out view of a box.

Lessons

Lesson 1: Variables, Basic Operations, Real and Integer Numbers and the First Box.

Lesson 2: Creating a graphical calculator: Coordinates, lists, loops and arrays: A Study in Linear Equations

The CoolMath Website

A colleague recommended the Cool Math website as something she uses as a supplement for her students. There are some games for the younger kids, and lessons in pre-algebra through algebra for secondary students. I’ve glanced through a few of the pre-algebra lessons, and like them. They’re short, fairly clearly written, and have good diagrams.

Algebra lessons at Coolmath.com

The site is also friendly to homeschoolers and their parents, with a decent teacher’s area that outlines the author’s perspective on teaching math.

Their Survivor Algebra is an interesting approach to encouraging peer teaching by breaking the class into “tribes” and giving bonus points on tests if all members of the tribe do well. I’m not sure I like the extrinsic motivation of the prizes and test score bonuses but I think there might be some good aspects of this type of classroom organization in very large classes.

It’s a very interesting site that’s worth investigating.

Concept Maps of Math

Introduction to algebra.

While it’s nice to have the math concepts arranged nicely based on their presentation in the textbook. Since my plan is to give just a few overview lessons and let students discover the details I’ll be presenting things a little differently based on my own conceptual organization. So I’ve created a second graphic map, which looks a bit disorganized, but gives links things by concept, at least in the way I see it.

Concept map for an introduction to pre-Algebra based on the first chapter of the textbook, Pre-Algebra an Accelerated Course, by Dolciani et al., (1996).

This morning I presented just the first branch, about equations, expressions and variables. The general discussion covered enough to give the students a good overview of the introduction to Algebra. Tomorrow the pre-Algebra and Algebra topics will start to diverge, but I think today went pretty well.

We’ll see how it goes as we fill in the rest of the map.

Interactive Model showing the Kinetic Energy of a Gas

I really like this little video because it’s relatively dense with information but its visual cues complement each other quite nicely; the interactive model it comes from is great for demonstrations, but even better for inquiry-based learning. The model and video both show the motion of gas molecules in a confined box.

In the video, the gas starts off at a constant temperature. Temperature is a measure of how fast the particles are moving, but you can see the molecules bouncing around at different rates because the temperature depends on the average velocity (via Kinetic Energy), not the individual rates of motion. And if you look carefully, you notice the color of the particles depends on how fast they’re moving. A few seconds into the video, the gas begins to cool, and you can see the particles slow down and gradually the average color changes from blue (fast) to red and then some even fade out entirely.

In the interactive, VPython model I’ve put in a slider bar so you can control the temperature and observe the changes yourself. The model is nicely set up for introducing students to a few physics concepts and to the scientific method itself via inquiry-based learning: you can sit them down in front of the program, tell them it’s gas molecules in a box, have them observe carefully, record what they see, and then explain their observations. From there you can branch off into a lot of different places depending on the students’ interests.

Temperature (T) – a measure of the average kinetic energy (KEaverage) of the substance. In fact, it’s proportional to the kinetic energy, giving a nice linear equation in case you want to tie it into algebra:
! T = c {KE}_{average}
where c is a constant.

Of course, you have to know what kinetic energy is to use this equation.
! KE = \frac{1}{2} m v^2
Which is a simple parabolic curve with m being the mass and v the velocity of the object.

The color changes in the model are a bit more metaphoric, but they come from Wein’s Displacement Law, which relates the temperature of an object, like a star, to the color of light it emits (different colors of light are just different wavelengths of light).

! T = \frac{b}{l}

where b is another constant and l is the wavelength of light. This is one of the ways astronomers can figure out the temperature of different types of stars.

Notes

The original VPython model, from Chabay and Sherwood’s (2002) physics text, Matter and Interactions, comes as a demo when you install their 3D modeling program VPython.

I’ve posted about this model before, but I though it was worth another try now that I have the video up on YouTube.

93 Ways to Prove Pythagoras’ Theorem

Geometric proof of the Pythagorean Theorem by rearrangemention from Wikimedia Commons' user Joaquim Alves Gat. Animaspar.

Elegant in its simplicity but profound in its application, the Pythagorean Theorem is one of the fundamentals of geometry. Mathematician Alexander Bogomolny has dedicated a page to cataloging 93 ways of proving the theorem (he also has, on a separate page, six wrong proofs).

Some of the proofs are simple and elegant. Others are quite elaborate, but the page is a nice place to skim through, and Bogomolny has some neat, interactive applets for demonstrations. The Wikipedia article on the theorem also has some nice animated gifs that are worth a look.

Cut the Knot is also a great website to peruse. Bogomolny is quite distraught about the state of math education, and this is his attempt to do something about it. He lays this out in his manifesto. Included in this remarkable window into the mind of a mathematician are some wonderful anecdotes about free vs. pedantic thinking and a collection of quotes that address the question, “Is math beautiful?”

Mathematics, rightly viewed, possesses not only truth, but supreme beauty — a beauty cold and austere, like that of sculpture, without appeal to any part of our weaker nature, without the gorgeous trappings of painting or music, yet sublimely pure, and capable of a stern perfection such as only the greatest art can show.

Bertrand Russell (1872-1970), The Study of Mathematics via Cut the Knot.

Adding Positive and Negative Numbers with Dice

We want students to become as involved as possible with their work, but a lot of math is going to be repetitively working similar questions. I believe that giving students any additional degree of control over the questions they’re answering will be helpful to some degree. So, for working with addition of positive and negative integers on a timeline, letting students generate their own problems might add a little interest, and be a little more engaging than just answering the questions in the text. There are a number of ways of doing this, but using two sets of differently colored dice might be fairly easy to put together and appeal to the more tactile-oriented students.

So give each student a set of dice, say six, of two different colors, say red and wooden-colored. Have them roll them then organize them in a line. Your red dice are positive integers and your wooden dice are negative integers.

Set of positive (red) and negative (wood) dice. Dice images assembled from Wikipedia user AlexanderDreyer.

The dice in the image above would produce the expression:

5 + (-1) + 3 + (-4) + (-6) + 1 =

It might make sense to start with two then move up to four and six (or even use odd numbers as long as you include different colors). You could use a more specialized dice with different numbers of sides, but I think the standard six-sided ones would be sufficient for this exercise.

Match Stick Rockets

A great, simple, and slightly dangerous way of making rockets. There are a number of variations. I like NASA’s because they have a very nice set of instructions.

How to make a match stick rocket. By Steve Cullivan via NASA.

With a stable launch platform that maintains consistent but changeable launch angles, these could be a great source of simple science experiments that look at the physics of ballistics and the math of parabolas (a nice video camera would be a great help here too) and statistics (matchsticks aren’t exactly precision instruments).

How to Think Like a Mathematician

The epistemological approach to education suggests that the best way to learn a subject is to learn how to think like the experts in the field: how to think like a scientist; how to think like an historian; how to think like an engineer; etc.

How to think like a mathematician is Kevin Houston‘s attempt to explain how one mathematician at least approaches problems. To whet your appetite, he has a free pamphlet, 10 Ways To Think Like a Mathematician, which starts off with:

  1. Question everything, and
  2. Write in sentences

Logic is, apparently, quite important.

If you want to understand mathematics and to think clearly, then the discipline of writing in sentences forces you to think very carefully about your arguments.

— Kevin Houston: 10 Ways To Think Like a Mathematician

It’s an interesting introduction to how mathematicians see the world, and its a useful reminder that many of the ways of thought that apply to any field can be useful in other places, or even in life in general.