It’s the beginning of a new school year—and I’ve got you covered. You want to do something with coding in your physics class, but you don’t know where to start? I’m going to give you a jump start.

I know you are nervous, but don’t worry. You don’t need to be a ‘l33t h4x0rz’ (that’s cool-speak for elite hacker). You just need to get started. Just remember, everyone had to start programing at some point. They all did it—so can you.

**What the heck do you call it?**

I like to call this stuff “numerical calculations”. I think this is the best name for it because it sort of describes what’s going on. Here’s the general idea:

- Take a physics problem (or any problem, really).
- Break the problem into a bunch of small and easier problems.
- Maybe make some approximations.
- Solve all the small problems by using numbers.

Numbers are the key. You have to use numbers in a numerical calculation. The other solution is an analytical calculation. This is the process of solving a problem in terms of known functions—like the trig functions. For an analytic solution, you don’t really have to put in the numbers until the end.

Of course, there isn’t a huge difference in these two solutions (analytical vs. numerical). A great example from Bruce Sherwood (in a discussion at the recent AAPT meeting in Utah) points out the following:

Suppose you get a solution for a mass oscillating on a spring. The analytical solution will be in terms of the cosine function. But then, how do you get values for something like ? Well, you put it in your calculator or you look it up in a table. Oh, you could find the value for cosine by summing an infinite series. But you see—we are back to a numerical calculation.

That’s not exactly what Bruce said, but that’s the basic idea.

Here are some other names for numerical calculations that you might see:

- Computational physics
- Coding in physics
- I’m drawing a blank here—there must be some other words.

But I also like numerical calculations because it doesn’t explicitly say “computer” in it.

**Why do numerical calculations in physics?**

Let me be brief and just list some points.

- Numerical calculations are just part of physics. There are countless physics problems that can only be solved numerically.
- Once students get the idea of numerical calculations, they can solve more interesting problems that would otherwise be inaccessible to them.
- What about other fields? Meteorology, digital animations, protein folding, economics…the list goes on.
- Tools. The tools for numerical calculations are both free and easy to access. You don’t need to install anything and you could even do it on a smart phone (not recommend—but possible).
- Finally, numerical calculations helps student understand physics. I’ve always been surprised that when working on a problem with students on a computer, they ask questions. But these questions are rarely about computer syntax. They are usually things about vectors or forces. It’s awesome.

**Who is this for?**

I’m going to get you started—so this tutorial is geared towards very introductory classes. I use this same stuff in a physics lab for an algebra-based physics course at that college level. I think this would be fine for high school classes also.

If you want more advanced stuff—this might also work as an introduction. For my calculus-based physics course, I start with more complicated stuff.

Also, I am careful to emphasize that students (and faculty) don’t need any prior experience with coding.

**Where to start**

I like to have a workshop format for my lab or class. I use a projector at the front of the room to go over some points and then stop and let the students work on code either individually or in groups (here is a version of my presentation—feel free to use it). I tell students to bring a computer or tablet if possible. Otherwise they will be in groups of 4 per computer (which is not ideal). Of course some students don’t want to get involved, so a 4 person group is what they want.

Here is the general outline of the workshop format lesson.

- Give an overview of numerical calculations (motivation).
- Start with an object moving at a constant velocity in one dimension. Let them solve it analytically (hopefully, this is a review).
- Next have them take this SAME PROBLEM but solve it by breaking into 7 time steps—but still solving it on paper. NO COMPUTERS YET.
- I actually give them a table to fill out. It has 7 rows with columns for time, time step, and position. After a short time, I stop them and go over the calculation for the first row (and maybe the second). Some students can finish this table very quickly, and others not so quick.

Next, they do this same set of calculations with some python code. I give them this program that runs as it is and I go over each line.

The two parts that might be new for students:

After going over the code, I send them to this page (https://trinket.io/rhettallain_gmail_com/courses/physics-python-for-mere-mortals#/beginning-numerical-calculations/using-small-pieces). It’s a trinket.io page with the code right in the browser. They don’t even need to log in or anything. It even has all the instructions there too so that they could do this on their own. The trinket site is the BEST. Oh, I also made this shortened-url (http://bit.ly/trinket-physics). That page includes everything. I make sure to tell them to click on the “using small pieces” tab on the left to get to the code.

So, the students run the code and then modify the code to answer some questions such as:

- Where will the car be at a different time? Say 2.2 seconds.
- What if you change the velocity the 0.62 m/s, where will it be after 2.2 seconds?
- What if the car starts at -0.5 meters?

Stuff like that. Really, I just want them to be able to run the code, read the output, and change the code. It’s sort of a coding ice-breaker.

I’m not going to go over the rest of the workshop—but it’s all there (and more) on the trinket.io site along with the instructor slides. After that first small activity, the students do the following:

- A similar problem but with a constant (non-zero) acceleration. This is great because you get a different final answer for the numerical calculation that depends on the size of the time step.
- How to make graphs (or at least print out values) so you can get more data.
- Solving a problem with two cars—one moving at a constant velocity and one accelerating. This is the classic “police chase” problem. I set up the program (not all the way) but I let them figure out how to change the while loop to get it to run. It’s great because students come up with their own ways of making it work. Sometimes, this is where I stop the class.
- Projectile motion.
- Mass oscillating on a spring.

**What do you need?**

If you want to do this in class, you need some computers or tablets and some time. You could probably do this in sections, just break it into 30 minute activities if you like.

Some other things to consider:

- Make sure you work through the material first. It’s important to really know what’s going on so that you can easily help students when they get stuck.
- If a group has a program that’s not running right, I really try to get them unstuck. If it’s a silly syntax error, I try to find that right away so they don’t get frustrated.
- If you have any questions or need help. let me know.

## 3 thoughts on “Jump Start Guide for Computational Physics”