Computer Programming across Secondary-school STEM
(Science, Technology, Engineering, and Mathematics)

The thrust of this work is to integrate programming projects into secondary school STEM curricula [Science, Technology, Engineering, & Mathematics], projects where students program graphical simulations and dynamic models of the physical phenomena and mathematical processes they study in their classes.  These projects may range from simple exercises that comprise an in-class exercise, to an extended lab session, to more involved homework assignments, to yet more complex capstone projects.  The approach is not to teach the full breadth of an introductory programming class, but to teach enough for the students to be able to complete projects that support the pedagogy of their classes.

Goals and Objectives:

The demos on these pages are from experiments in realizing this goal with students in two contexts: a high-school physics class programming with the Vpython language, and a summer-science enrichment program where students used the language Actionscript. Without delving into Language War issues, let it be known that both languages have significantly valuable properties for introducing students to programming and visualization. We want to engage students in programming, with language-specific details taking a back seat.

The Summer Science program

A tutorial First Lesson
Dynamic Simulation: Planetary Motion
Stochastic Simulation: Buffon's Needle
Student Projects

This group of students were in a summer science enrichment program for high-school juniors. Over several weeks, they were mentored through several tutorial exercises, completed several others as assignments, and finished a capstone project based on their own interests. Programming was but one aspect These students used the ActionScript language of the Flash development environment: the syntax and semantics are close to Java, the concepts underlying object-oriented systems are simply introduced, and the environment allows students to quickly see the results of their programming constructs in action. 

The High-school Physics semester

Some demo student programs

A sequence of in-class lab assignments were developed to support the Mechanics coursework of the Fall-semester of a Physics class. These included constant-velocity motion within a frame, elastic and inelastic collisions, adding in gravity, and planetary motion. The students worked with Vpython which provides language support for 3D objects and vector mathematics, following the Matter and Interactions text of Chabay and Sherwood.

The Python language semantics are close to C and Java, the concepts underlying object-oriented systems can be simply introduced, and the interpreted development environment allows students to quickly see the results of their actions.

The graphical, dynamic simulations students develop are small-scale versions of the grand challenges of computing today such as climate modeling.  Through developing simulations on their own, students come to appreciate the role of simulations in understanding and visualizing science and mathematics today, understanding that simulations are now key tools of science that bridge physical experimentation and symbolic equations, providing key visualizations of the dynamic unfoldings of systems.


The First Lesson: In which we explore essential concepts of physics with but an hour of programming...

The examples below use the ActionScript language of Flash.

Draw a ball on the screen, and attach to it one line of code: _x = _x + 10;

And right off, something interesting happens - the ball moves across (and off!) the screen. This is a repeated assignment statement, with Flash automatically handling the repetition, with no mystery, no statements that just "have to be there, we'll explain it later"

Now add "conditional" constructs: in only 4 lines of code, we have shown assignments, conditionals, and the {}'s of block structured language...

{
     _x = _x + n;
     if ( _x > 400 ) { n = -n; }
     if ( _x < 0 ) { n = -n; }
}

Now draw more "objects" and animate them with the same lines of code, the only difference being the initializations for 'n':

b1.n = 3;
b2.n = 9;
b3.n = 5;

We've introduced the basics of objects, and by creating them graphically with Flash's drawing tools, we've avoided the messy conceptual overhead associated with the syntax and semantics of object creation through many lines of code - code distinctly NOT friendly to someone with only one hour of programming background.

NOW... simply do for 'y' coordinates what was done for 'x' - nothing new conceptually, just replicate code and change x's to y's. No new concepts.

But... WHAT HAVE WE HERE ???

Several deep concepts have emerged out of this new animation; it's up to the teacher as to where the fit in the students discovery of knowledge, but let us note:

VECTOR MOTION has emerged. Diagonal motion is a composite of independent dimensions!

ANGLE OF INCIDENCE = ANGLE OF REFLECTION. Note that the balls bouncing off the walls bounce realistically (well, realistically in the ideal sense), with the incoming angle equal to the outgoing angle. You could potentially prove this law of physics, at least intuitively, by observations of what is happenning independently in x and y. And if the cushion absorbs some energy - what would that look like? Think about it, then simulate it!

What to do with this? Well, now, that depends on the teacher and the lesson...

HOMEWORK: So far, the circles were simply sliding (translating) across the screen. Realistically, a wheel would roll, that implies a rotation.

     _rotation = _rotation + ??? ;

But how much? Make it happen realistically...


Planetary Motion: a Dynamic Simulation

In Lesson One, velocity was fixed. Let's add acceleration. In lesson one, constant velocity changes position at each time step. With acceleration in the picture, first use acceleration to change velocity, then use this new velocity to change position. I won't lead you through all the steps this time, but first make a planet orbit the sun, then make a moon orbit the planet (already orbiting the sun). Add a few new programming constructs now to make buttons:

[[ Click the start button to kick things off. Planet and moon can be dragged to different places while animation is stopped.]]

Here's a parameterized model we can explore. After watching it a bit, 'RESET' the animation, highlight the '30' , change it to 25, restart the model, and watch the new system through time.

If you've watched this for more than 10 seconds, consider yourself hooked. You are not being wow-ed by state-of-the-art animations and cool graphics. It's a bit cheesy by current visual appeal standards. So why are you watching? And if you'd created it, you'd be watching even longer!!! We've implemented some physics, developed parameterized models we can play with, and driven the solar system from it's basic laws. Impressed? Students have been. It has engaged them further in both programming and in the sciences.


Buffon's Needle: A Stochastic Simulation

Buffon's Needle is an old problem in the field of geometrical probability. First stated in 1777, it involves dropping a needle on a lined sheet of paper and determining the probability of the needle crossing one of the lines on the page - that probability is directly related to the value of π. [[For an analysis, see: George Reese's web page on Buffon's Needle, where he references Schroeder, L. (1974), “Buffon's needle problem: An exciting application of many mathematical concepts”, Mathematics Teacher, 67 (2), 183-186.]]   For a large number of repeated tosses, where the distance between lines is equal to the length of the needle, twice the total number of tosses divided by the number of tosses where the needle crosses a line provides a stochastic approximation of π.

Only three lines of code are needed to repetitively and randomly "toss" the needle onto the parallel-ruled "paper":

_rotation = 360*Math.random();
_x = 50+Math.random()*300;
_y = 50+Math.random()*200;

This coding provides an introduction to the concept of a random variate, and uses that concept to simulate a random toss, by “randomly” rotating the needle and then “randomly” placing the needle's center on the 400x300 field. To figure out if the needle has crossed a line, the hitTest method is then introduced, a method that determines whether two objects intersect (in this case, the needle and any of the parallel rules). With another few statements, statistics can be accumulated over a long number of iterations. Nine programming statements essentially does it all.

SO... Here's an application with both concept and historical interest. The implementation reinforces both, and provides a short but sweet entree to stochastic simulations. And watching the estimate over time develops intuition into the nature of statistical convergence with increasing n.

This demo version is yet further embellished, speeding up the tosses after the first few to speed up convergence, and allowing the user to restart the counters for another run. If it runs for a some time, it converges not quite to 3.14159 ... What's up? The needle and line do have an actual physical width, as opposed to the idealized lines of the analysis - a key point in contrasting abstractions vs. implementations.