PDA

View Full Version : Need some massive help in Python...


RowdyScot
2006-10-10, 00:08
So for my modern physics class, I'm supposed to create a program in Python to demonstrate a simple harmonic oscillator based off of the Schroedinger equation for n=0, n=1, and n=2. Mind you, NOBODY in this class has any programming knowledge, other than some HTML and bits and pieces of Java. I do not know Python well at all. The program should find the probabilty of the particle's location in the interval -x to x (can presumably be -1 to 1) and also give the energy. So...ummm...yeah. I understand enough to know what to use for xmin and xmax, and dx can just be a step to whatever suits the needs, but I'm not sure what equations I should be using. I know that the energy is (n + 1/2)*hbar*omega, where hbar is h/(2*pi) or 1.054*10**-34, and omega can just be set to 1 radian/second. I'm not sure how to get the probability because of some massive math issues. I can make things easier by defining a bunch of things to cancel out, such as setting k and m as 1.054*10**-34, and so on for the variables in Schroedinger's. My issue mathematically is when I have to solve Schroedinger's for modes n=0, 1, and 2. This gives me a ton of ugly, which I'm not sure how to code. So my question is, does anyone understand what I'm trying to do enough to help, and is anyone willing to help? I know when completely scripted, the code really shouldn't be more than 20 lines. Easy enough, right? This is unfortunately due Wednesday the 11th, so I'm already on a strict timetable. If somebody can give me an example, or help me understand mathematically what I should be doing, I think I can get the rest from there. Honestly, I'm not sure if this is where this thread should belong, but I figured as much since I am trying to make an application. If it should be in AppleOutsider, my humble apologies. I'm currently running on VPython in X11. Thanks for any help that I can get. It is extremely appreciated.

Kickaha
2006-10-10, 00:13
Oy - I'm more help with the Python than the math, it's been years since I did any QM... :/

What are the massive math issues you're having? Precision problems?

RowdyScot
2006-10-10, 00:32
Arg...well, I've started out by deriving the Schroedinger equation in order to get energy. Solving through all of that is how I get the value in my above post of E = (n + 1/2)*hbar*omega. However, I'm not sure how I should be getting probability. Wait...maybe I've just realized something. If I derived the Schroedinger equation to get E, I should just be coding for ∫[(n + 1/2)*hbar*omega], right? How do I go about setting that up with limits from -x to x, which I can just say are -1 and 1, respectively? The whole integration in Python still throws me a bit.

Kickaha
2006-10-10, 00:38
Unless you can find an intergration package, you're going to have to code up an approximation algorithm like Runge-Kutta or Newton's approximation. If you go with R-K, a 4th order method gives you a good convergence with pretty good performance. (Wow, I hope you know this is hitting some neurons in my skull that have cobwebs...)

RowdyScot
2006-10-10, 00:51
Hopefully these aren't too unpleasant memories :) Some quick looking around at R-K might do that which I'm looking for, and I think I know how to set everything up. I think I wasn't seeing something that was obvious the entire time, which is a normal thing for me :) If anything else comes up, I'll ask with something hopefully a little more specific. Thanks a lot for your help, Kick. Dunno that I'd have been able to find that without knowing what to look for.