Wednesday, February 8, 2012

Numerical Analysis on a Calculator

Today in my differential equations class, we ended up trying to solve the equation x=cos x. And couldn't. Well, I'm not sure everyone was trying very hard, but I had scribbled trig identities all over my page without making any progress whatsoever. Eventually the lecturer took pity on us (or decided that giving us any longer was a waste of his time, perhaps!) and told us to take out our calculators. Oh! So all that analytical fiddling wasn't helpful. It's quite easy to solve the equation numerically on a pretty standard scientific calculator, though, and quite a pretty technique too, I think. I thought I'd share it.

Pick any number you like. If you pick it close to the right answer, the process will be a little quicker, but it doesn't really matter. From the picture below (drawn with Gnuplot), 1 seems like a reasonable starting point.



Now you put cos(1) into your calculator. You don't get 1 back out, so that's not your solution. But if you take cos of that answer, and then cos of that answer and so on for a little while (you can probably do something like just hitting '=' over and over) the answer eventually stops changing. You've found a value which - at least to the accuracy your calculator displays - is it's own cosine. That's the solution. Quite neat! (I think that method is the numerical form of Picard integration, but I could be quite wrong.)

Having started playing with Gnuplot, I don't want to stop, so before I go back to work, why don't I show you a picture of the probability densities we're calculating for the particle-in-a-box problem? It's pretty, at least.
Probabilities of finding an electron at different points in an infinite potential well for five different energy states. (I hope.)

2 comments:

  1. Hi, I was just looking at your Particle in a Box plots,
    and I was wondering: where are the labels for the x and y axes? Where is the title? In addition to this, where is the key? How do we know which energy state is which? Have you read your checklist for graphs?

    ReplyDelete
    Replies
    1. Hi Anonymous -- do bear in mind that this was just an image I put up to show my friends and family what I was working on, not a full academic report. Labelling is obviously very important in general, but not so much where I'm just generating some pretty-looking lines. ;)

      Delete