Skip to content

Visualizing a quantum wavefunction with macOS’s Grapher.app

2018 June 15

I’ve been slowly but steadily teaching myself quantum mechanics from a variety of sources: books, YouTube videos, etc.. The book I’m currently making the most headway through is Griffiths’ Introduction to Quantum Mechanics. The paperback edition is an incredible deal at less than $20, and it’s the first book I’ve found that has the right combination of minimal prerequisites and hand-holding. I highly recommend it. In general, to do QM, you’re going to need pretty good calculus and linear algebra. I haven’t studied math since high school, so I’ve needed a lot of supplemental googling to figure out things like the Gaussian integral. Also, Wolfram Alpha has been somewhat helpful in reducing some terms and grinding through the homework problems.

Anyway, while working through Section 2 (the time-independent Schrödinger equation), I decided to finally start graphing these increasingly complex functions to help me understand what’s really going on. Although there are a number of online graphing apps, none of them seem to handle both 3D graphing and complex numbers (correct me if I’m wrong!).

So I turned to one of my all-time favorite underdog applications ever, macOS’s Grapher.app. It continues to blow my mind that more people don’t know about this app. It’s been around since OS X 10.4 and has an INSANE amount of functionality for a free, bundled app. And, this being Apple, of course it renders equations really beautifully.

But while I’d used Grapher plenty over the years for fairly mundane things, I’d never used it for either complex numbers, or particularly delved into 3D graphs—but I’m extremely excited to say that I figured it the fuck out:

qm-wavefunction-1

A Little Dose of Theory

But before going further, let me back up to the larger context. Quantum particles are “fuzzy.” They don’t have well-defined edges, the way we commonly think of, say, a ping pong ball as having. (If you zoom in enough on the surface of a ping pong ball you’re going to start to wonder what the edge actually is.) Think of the clear definition of a ping pong ball as one state. You know where it is and where it’s going.

Quantum particles are “fuzzy” because they’re a combination of lots of different states. It’s essentially a bajillion different ping pong balls all superimposed on each other, and we just call the whole thing one particle. (This analogy pairs very nicely with the often-misunderstood Many Worlds Interpretation.)

Anyway, the wave function is that crazy wad of superimposed ping pong balls. It takes in position and time and gives you a complex number. Why complex and not just real? The phase of that number is what gives you, for instance, the destructive interference you see in the famous double-slit experiment. More on complex numbers in this terrific article.

This is a rendering of the wavefunction for the first 10 energy levels of single, 1-dimensional quantum particle in an “infinite square potential well.” It’s the quantum equivalent of a ball bouncing back and forth between two walls (with no friction). The wavefunction (blue) is a complex-valued function of position (x usually, but u here to make Grapher work) and time (t) that contains all the information about a particle, such as probabilities of position and momentum. The output of the wavefunction is also known as the probability amplitude. The red line is the probability density, Screen Shot 2018-06-13 at 4.20.49 PMwhich gives you the actual final probability that a measurement at x will show a particle.  If you’ve never studied any of this stuff, check out this really terrific overview.

So let’s take a closer look at the wavefunction (next time, I promise I’ll set up mathjax for this blog).

Screen Shot 2018-06-13 at 2.47.51 PM

(This is equation [2.35], on page 35 of Griffiths, slightly modified to work for Grapher)

  • A (for amplitude) is an overall scaling factor to make the graph easier to see
  • u acts like x (position); to be perfectly honest I’m not sure why you can’t just use x, but Grapher requires you do it this way. It’s set to stretch from 0 to 4, which is:
  • a, the width of the well (4 units)
  • nmax is the number of energy levels to graph (1, the ground state, plus 3 “excited” states)
  • c(n) is the coefficient of each energy level. I just made this one up so that each energy level is contributing an increasingly smaller amount to the total function.

Here’s a helpful way to break this apart. The wavefunction is actually two factors:

Screen Shot 2018-06-13 at 3.57.34 PMLowercase psi is the actual wavefunction: a function of position only that gives you the probability amplitude. (Remember that throughout, n refers to the energy level in question.)

Screen Shot 2018-06-13 at 3.57.28 PMLowercase phi is a function of time only that lends a complex phase to psi, causing it to rotate around the x axis in this visualization. Phi for phase, get it?!

OK, the last thing I’ll say about the physics here is that the square well demonstrates the “quantum” in quantum mechanics: When a particle like an electron is closed in a box on the order of nanometers wide, the particle can only have certain, discrete energy levels, because the wave function is trapped at zero on the boundaries, and only standing waves can fit into it. Seriously, this is THE entire underlying conceptual foundation of all of quantum mechanics. Nuts!

Grappling With Grapher

The main challenge I had in getting all this in Grapher was figuring out how to represent the complex curve in 3D. The key is to use column vectors and extract the real & imaginary parts:

Screen Shot 2018-06-13 at 5.03.01 PM

This maps u to the x axis, the real component of psi to the y axis, and the imaginary component to the z axis. Voilà, a lovely little curve snaking through space. For more information on the tricks and caveats to wielding complex numbers in Grapher, look here.

Then, you can do “Animate Parameter” on t to get a sweet animation of the wavefunction over time:

On the left, the graph is rotated, showing how the amplitude (blue) rotates around the x axis with its components out of phase with each other, creating a wiggly spiraling. The right is a straight-on view that clearly shows how the peak of the probability density (red) “bounces” back and forth. For a higher-quality, more elaborate demonstration of these concepts, look no further than Eugene Khutoryansky’s amazing physics videos.

Here’s the Grapher file I built for your enjoyment. It’s evolved a bit since the screenshots here. By all means download this and play around with it, it’s SO much more educational to start fiddling with parameters than to scan through some equations in a book and assume you know what they do.

The one major, major drawback to Grapher is its infamous lack of documentation. It’s often quite difficult to figure out exactly how to do certain things or why you’re getting an error on a formula. Nonetheless, it’s so beloved, it has a gigantic, 83-page unofficial manual replete with known bugs and workarounds.

Have fun, and let me know if I’ve made any mistakes with my math or explanations! And if you’re interested in this book, absolutely pick it up:

Introduction to Quantum Mechanics (2nd Edition) Paperback Economy edition by. David J. Griffiths

One thing in particular that’s nifty about this text is that it doesn’t introduce Dirac notation until Chapter 3, so you start out with more-or-less familiar looking equations that explicitly describe the phenomena. Then once you’ve gotten used to what the math is and how it works, the Dirac notation comes along to make everything much easier to read and work with.

Related Posts:

  • No Related Posts


Comments are closed.