Computational Activity: Sinusoidal basis set

Computational Physics Lab II 2022
Students compute inner products to expand a wave function in a sinusoidal basis set. This activity introduces the inner product for wave functions, and the idea of approximating a wave function using a finite set of basis functions.

Essential goals for this week

  1. The coefficients \(C_n\) are a representation of a quantum state.
  2. An expansion in a basis can be approximated by summing over only a few basis states, with the approximation getting better as we sum over more.

Learning goals for this week

  1. For wave functions, the inner product is an integral.
  2. The coefficients in an expansion in a basis are inner products \(C_n = \langle n|\psi\rangle\).
  3. An expansion in a basis requires summing over all possible basis states (\(n=1\rightarrow \infty\) in our case).

Possibly delayed goals, which depend on \(\psi(x)\)

  1. Functions can be orthogonal.
  2. Sometimes a wave function is orthogonal to a basis state, esp. when they have different symmetry.
  3. If we inexactly compute a number that is zero, we often get a result that is nonzero, but small.
  4. \(\langle n|m\rangle = \delta_{nm}\) for an orthonormal basis.

Basis sets and basis functions

A basis set is a choice of orthonormal vectors to use as a representation. The basis set you're probably most familiar with is the cartesian basis in three dimensions, consisting of \(\hat x\), \(\hat y\), and \(\hat z\). The basis allows us, for instance, to represent states as a column vector: \begin{align} \vec v &= v_x \hat x + v_y \hat y + v_z \hat z \\ &\,\dot= \begin{pmatrix}v_x\\v_y\\v_z\end{pmatrix} &\text{where }v_x &= \hat x\cdot \vec v\text{ etc.} \end{align} We can express same concept in bra-ket notation a bit more generally \begin{align} |v\rangle &= \sum_n v_n|n\rangle &\text{where }v_n &= \langle n | v\rangle\text{ etc.} \end{align} where the sum runs over all possible basis vectors.

In the same way that we express a vector as a linear combination of basis vectors, we can use a linear combination of basis functions to describe the state of a particle in space. When we use Dirac notation, the math in fact looks identical to what you will be doing with spins: \begin{align} |\psi\rangle &= \sum_n C_n |n\rangle & C_n &= \langle n|\psi\rangle \end{align} where \(\left|{n}\right\rangle \) represents a basis state. To compute these expansion coefficients, you will need to know how to compute the inner product between wavefunctions.

Inner product

The inner product between wave functions in one dimension is given by \begin{align} \langle \phi|\psi\rangle &= \int \phi(x)^*\psi(x) dx \end{align} where \(\phi(x)\) is the wavefunction representation of \(\left|{\phi}\right\rangle \), and \(\psi(x)\) is the wavefunction representation of \(\left|{\psi}\right\rangle \). The integral goes over the domain of the problem (in our case from \(0\rightarrow L\)). This inner product is similar to the inner product you are accustomed to in spin systems, with the summation turned into an integration due to the fact that there are an infinite number of positions possible.

Our basis set

The basis set we will use is a sinusoidal basis set, defined by \begin{align} |n\rangle \,\,\dot=\,\, \phi_n(x) = \sqrt{\frac{2}{L}}\sin(n\pi x/L) \end{align} where \(n\) is a positive integer. Note that when we use “integer-sounding” variables in a ket (like \(\left|{n}\right\rangle \) or \(\left|{m}\right\rangle \)), we mean basis states, and their wavefunction representation is denoted by \(\phi_n(x)\) or \(\phi_m(x)\).

Over time you'll get to discover some fun and interesting properties of this basis, and you'll also be using it a lot for classical physics in Oscillations and Waves next quarter.

Expansion in a basis

One way that we frequently represent states in quantum mechanics is as a sum of basis states. This hearkens back to classical mechanics (and Static Fields) where you learned to write a vector in terms of basis vectors \begin{align} \vec r &= x\hat x + y \hat y + z\hat z \end{align} where you may recall that \(x = \vec r\cdot\hat x\), etc. In bra-ket language, we can write this relationship as \begin{align} |\psi\rangle &= \langle 1|\psi\rangle\, |1\rangle + \langle 2|\psi\rangle\, |2\rangle + \langle 3|\psi\rangle\, |3\rangle + \cdots \\ &= \sum_{n=1}^{\infty} \langle n|\psi\rangle\, |n\rangle \\ &= \sum_{n=1}^{\infty} C_n |n\rangle \end{align} Now this infinite sum doesn't look so convenient. Fortunately, we can approximate the sum by summing over a finite number of basis functions, and check that we are approaching the limit by seeing how our result changes when we increase the number of terms retained in the sum.

Your task

You will be given one of the following wave functions: \begin{align} \psi_1(x) &= \frac{\sqrt{30}}{L^2\sqrt{L}}x(x-L) & \psi_2(x) &= \frac{x^6\sin(\pi x/L)}{0.07931977085 L^6\sqrt{L}} \\ \psi_3(x) &= \frac{\sqrt{105}}{L^3\sqrt{L}}x^2(x-L) & \psi_4(x) &= \frac{\left(e^{x/L}-1\right)\left(e^{(x-L)/L}-1\right)}{0.1937570896322709\sqrt{L}} \\ \psi_5(x) &= \frac{\sqrt{495}}{L^5\sqrt{L}}x(x-L)^4 \end{align}

  1. Write a python function that returns \(\psi(x)\) for your given wavefunction.
  2. Plot \(\psi(x)\) as well as a few of the sinusoidal basis functions.
    I want students to learn to plot things "automatically" as part of checking whether their code is even working, but for now I still ask them to do so, since I expect that with this being quantum mechanics they might have more trouble activating their usual sense-making skills.
  3. Write another python function that given \(n\) returns \(C_n = \langle n|\psi\rangle\).
  4. Compute the first eight \(C_n\) as well as \(|C_n|^2\). What patterns do you see in their values, if any? Can you explain them based on the properties of your wavefunction? Raise your hand or ask for help!
    We have commonly seen students making \(x\) an input to their function to compute \(C_n\). They aren't yet clear on what an inner product is, and it can help to remind them of the definition of the inner product.
  5. Compute and plot the following approximation for your wavefunction: \begin{align} \psi_{\text{approx}}(x) &= \sum_{n=1}^{4} C_n\phi_n(x) \end{align} On the same plot show \(\psi(x)\). How well do the two curves agree? How does the agreement change if you change the number of terms in the sum?
Extra fun
Repeat the above with one of the other wavefunctions.
Crazy fun
Try expanding one or more of the following functions in our sinusoidal basis: \begin{align} \psi_A(x) &= \sqrt{\frac{3}{L}}\left(1-\left|\frac{2x}{L}-1\right|\right) \\ \psi_B(x) &= \frac{4\sqrt{3}}{L^2\sqrt{L}}x(L-x)\left(1 - \frac{\Theta(x/L-\tfrac12)}{2}\right) \end{align} where \(\Theta\) is the Heaviside step function. How does the number of coefficients you need to include in order to get a good match to the wave function differ for these less smooth functions?

There is commented out here another version of this activity that we tried after students attempted the above.

Davide Lazzati in Winter 2023 added the following to keep advanced groups busy while working with those still learning the main part of the activity

Challenging Fun
The process you worked on, decomposing an arbiraty function that has value 0 at the extremes has important implications for music. The vibration of a string is made by the superposition of the vibration of "modes", i.e., the elements of the sinusoidal basis that you have used. Each mode has a set vibration frequency, and the temporal evolution of the string position is given by (I simplified things a bit here, ask me if you want to know how and why): \begin{equation} \psi(x,t)=\sum_{n=1}^\infty C_n |n\rangle \cos(\omega_n t) \end{equation} where \(\omega_n \propto n\). Your task is to produce an animation of the moving string. I suggest, as a starting point: \(L=2\), \(\psi(x,0)=\psi_3\), \(\omega_n=n\), \(\Delta t=0.01\).
A guide on how to animate in jupyter can be found at (e.g.)
https://towardsdatascience.com/matplotlib-animations-in-jupyter-notebook-4422e4f0e389


Keywords
inner product wave function quantum mechanics particle in a box
Learning Outcomes