An Introduction to Numerical Modeling

Every once and a while, I like to add new ways to do numerical calculations. In this case, it is with Khan Academy’s new computer science module. First, a couple of notes about the Khan Academy Computer Science programs. Each tutorial shows a code window along side an output window. The code is essentially java […]

Every once and a while, I like to add new ways to do numerical calculations. In this case, it is with Khan Academy's new computer science module. First, a couple of notes about the Khan Academy Computer Science programs.

  • Each tutorial shows a code window along side an output window.
  • The code is essentially java script type stuff.
  • For each tutorial, there is a narration to go along with it. The narration leads the user through the development of each concept. In the few tutorials I looked at, I didn't find any problems with the content.
  • At any point in the tutorial, the user can pause the narration and modify the code as it was left by the narrator. Pressing play resumes the tutorial and puts the code back the way it was.

I decided to use this to make my own tutorial. The format isn't the same as Khan Academy since I don't have access to the narration tools. Instead, you can go directly to the code I created. Here is a screencast showing the different parts of the program.

Not the best platform for physics, but maybe it will work nicely as an introduction. Just as another test, I made a different version for projectile motion (plus I fixed the whole inverted y coordinate).

How could it be better? First, I would write the platform so that it uses python instead of javascript. Why? Why not. I just like python better - mostly because I hate semicolons. Honestly, once you know what you are doing it doesn't matter too much at this level. Python vs. javascript is like using Mac OS X or Windows. If you know what you are doing, there isn't a huge difference. Of course, for beginners, small differences in operating systems can seem like a big deal.

The other thing I would suggest is to open up the platform to other users. Give users the ability to make these animated tutorials on their own. That would be cool. Oh, and embedding the program in other sites would be nice also.

Glowscript

There is another excellent alternative to numerical calculations - and it also runs in a browser. Honestly, Vpython is still my favorite, but Glowscript doesn't require students to install anything on their computer (well, nothing other than WebGL). Ok, let me go ahead and show the same projectile motion calculation in Glowscript. There is supposed to be a way to embed these applets, but I couldn't get it to work. Here is a link to the program along with a screenshot below.

Glow Script ide

Here is the code (which you can see if you click on the link above).

Glow Script ide 1

I cut off the end of the line 23 just to make things fit better - it wasn't anything important. But what is important? Here are some notes (by line number).

  • 5: I am not exactly sure how this scene control works. I guess this has something to do with where the "camera" is.
  • 7: Glowscript has a built in vector class. That's nice. Notice how easier it is to write a program with vectors than without (as in the Khan Academy platform). Of course, you could do this problem with or without vectors.
  • 9: This creates the "sphere" object - which is a built in object in Glowscript. In the object, I define the ball's position, size and color.
  • 13: Once you create an object like a sphere, you can give it other properties like ball.v which is the initial velocity of the ball. Sure, you could have just made another variable called vball or something, but this way is a little cleaner.
  • 17: This is the main loop. It is like the draw function in the Khan Academy platform.
  • 18: The rate() function tells the program how fast to run. This way you can get the output to run in real time. Notice that the KA platform doesn't have this built in.
  • 20: Update velocity calculation.
  • 21: Update position calculation. Notice that I can reference the position of the ball (which is a sphere object) by calling ball.pos. Also notice that ball.pos.y is just the y-coordinate of the position.
  • 22: Update time.
  • 23: This just prints out the values of t, y, and v at the bottom of the display window.

There is something else super cool about Glowscript. If you right click on the output window, you can rotate it around. You can also zoom in and zoom out with the scroll wheel. It is a 3 dimensional output.

Conclusion

Let me summarize. I like the Khan Academy computer science tutorials. They are nifty. Maybe they would work well for an introduction to numerical calculations. Glowscript is pretty nice too. Oh, there is also CoffeeScript in Glowscript. This makes Glowscript so that you can write stuff that looks more like python. Useful.

Oh, maybe you want to see how to do a similar calculation in a spreadsheet? Boom. There you go. It's an older video, but it checks out.