Pages

18.5.12

Swing Away...


It's been a while since I've written code out of curiosity

In physics, you can do a lot with a pen and paper -- so much that in my seven years as a physics student, I've felled more than my share of trees. Many times, us physicists are trying to figure out how something moves -- so "solving a system" means writing down the equation that tells you where something is at different points in time.

So, you'd think that something as simple as a pendulum could be solved in a few lines of math... and you'd be wrong. Turns out, the equations that tell us where a pendulum is at any point in time are easy to write down, but you can't solve them without the help of a computer.

So, what did we do before we had computers? Same thing we do now -- make approximations to make progress. If I don't pull the pendulum back very far -- the small angle approximation -- the system can be solved on paper. In my undergraduate days, I was happy to accept the approximation and move on. But last night, I got curious and wrote a computer program that gives me the real answer (or, rather, as close as a computer can get to the real answer.)

The results are pretty interesting! In my simulation, the pendulum is pulled back 45 degrees and released from rest -- too far for the small angle approximation to "work." In the graph, you can see the non-linear solution that has to be done with a computer, and the approximate solution which is done on paper. The two are pretty close for the first couple of seconds, but the gap widens as time passes.
So, is our approximation garbage? When it's not appropriate -- yes. But let's see what happens when I only pull the pendulum back about 11 degrees:
That's better. When the angle is small, the small angle approximation works really well!

In high school and undergraduate physics, you spend most of your time coming up with exact solutions to approximate systems -- like we do with the small-angle pendulum. However, in graduate physics and research you have to make a massive shift in thinking. You look for approximate solutions to the real system -- like I did when I wrote my computer program. It takes a while to get used to this shift, and I think we can do more in high school and college to prepare students for it. A lot of that preparation involves learning how to use computers to solve problems -- something I wish I'd done far more of in years past.

So, if you are a high school or undergraduate student and you think you might want to make physics into a career -- learn to code. Learn to solve problems with computers in as many ways, and in as many languages, as you can. It is the single most useful skill that I have (and I don't even do it very well.)

3 comments:

  1. Anonymous21/5/12 22:46

    Just for fun, if you want to make the simulation for physical add an anharmonic term, plot the phase space diagram. They are pretty.

    ReplyDelete
  2. Sounds like fun! If I get around to it, I'll be sure to post it here.

    ReplyDelete