CITE THIS NOTEBOOK: Quantum harmonic oscillator: an educational exploration by Mads Bahrami. Wolfram Community DEC 7 2022.
Learning quantum theory is challenging for many students. Part of this problem is due to the abstract nature of quantum (compared to any other theory). However, a big portion of the problem is the way that quantum is being taught. I think one important missing element in the formal education of quantum theory (and also many other topics) is the lack of computational exploration. For example, computational exploration of DEs/PDEs and playing around them is NOT part of formal curriculums. Students should learn very concrete [boring] theorems etc,try to build everything from first principles. The sad irony is that those great equations were almost always discovered through some [random] explorations by leading scientists (and many times, fun/random explorations, without knowing where it may end up); and those concrete theorems/principles were developed later. In this short computational essay, I will show a simple exploration that I usually represents when teaching harmonic oscillator as part of an undergrad quantum course.
As I said in the abstract, my teaching style is usually non-conventional (that is why many times, I had lots of complaints from colleagues, and funny-enough almost nothing from students). In my classes, I emphasize a lot on computational explorations, guessing and problem-solving, rather introducing theorems, first principles etc and trying to explain everything based on them. Do not get me wrong; of course learning first principles and fundamental theorems is crucial. Having said that, the least I do is assigning the same amount of time to learn first principles, as I do computational explorations in my classes. And of course, my swiss knife tool has been always the Wolfram Language; most because it provides as an integrated environment where I/students can do almost any computational explorations, with the least requirement to be a full-scale coder! (eg try to read a Python code in a classroom where most students do not know programming, and then try a Wolfram Language code).
There are many interesting material on application of WL/Mathematica for learning/teaching quantum. I have adapted and borrowed ideas from some of them. Here is my take on the concept of harmonic oscillator and how to find eigenstates.

Harmonic oscillator

Tell students what is the potential energy and what DE they should solve (for time-independent Schrodinger equation). Remind them that whatever the solution (wave function), it should be a well-behaved function (do not been too rigorous, let them learn it later, only remind them at this point).
DSolve is a built-in function in the Wolfram Language for solving a differential equation.
In[]:=
DSolve-
2
ℏ
2m
D[ψ[x],{x,2}]+
1
2
m
2
ω
2
x
ψ[x]==ℰψ[x],ψ[x],x
Out[]=
ψ[x]

2
ParabolicCylinderD
-2ℰ-ωℏ
2ωℏ
,

2
m
x
ω
ℏ
+

1
ParabolicCylinderD
2ℰ-ωℏ
2ωℏ
,
2
m
x
ω
ℏ

which, as you see, there are two terms. If you look at the 2nd term, it has  x in the formula. Note
c
1
and
c
2
are two parameters, yet to be determined.
Let's look at the solution formula in more details, using FunctionExpand (another built-in function of the Wolfram Language). Note that instead of those complicated parameters (that depend on energy, mass etc), I only replace them with two parameters
In[]:=
FunctionExpand[ParabolicCylinderD[n,y]]
Out[]=
-n/2
2
-
2
y
4

HermiteHn,
y
2

which has two terms: an exponential (
-
2
y
4

) and a Hermite polynomial (
HermiteHn,
y
2

).
If you look at the formula for the solution
ψ[x]
, only the terms  x in the formula. What I am going to claim (try to convince yourself) is that for that term
c
2
must be zero because that term is not well-behaved.
In[]:=
Plot[Abs[ParabolicCylinderD[1,y]],{y,-10,10}]
Out[]=
-10
-5
5
10
1×
8
10
2×
8
10
3×
8
10
4×
8
10
5×
8
10
For a special case, for example the limit goes to infinity:
In[]:=
Limit[ParabolicCylinderD[1,y],y->∞]
Out[]=
∞
So the solution reduces to only one term (the well-behaving term).
ψ[x]

1
ParabolicCylinderD
2ℰ-ωℏ
2ωℏ
,
2
m
x
ω
ℏ

However, the remaining term will be well-behaving only if the first parameter (
2ℰ-ωℏ
2ωℏ
) is a positive integer. For example, when
2ℰ-ωℏ
2ωℏ
=1
In[]:=
Plot[Abs[ParabolicCylinderD[1,y]],{y,-10,10}]
Out[]=
-10
-5
5
10
0.2
0.4
0.6
0.8
or when
2ℰ-ωℏ
2ωℏ
=0.1
In[]:=
Plot[Abs[ParabolicCylinderD[.1,y]],{y,-10,10}]
Out[]=
-10
-5
5
10
500
1000
1500
2000
2500
3000
As one can see, that solution will be well-behaved only if the term
2ℰ-ωℏ
2ωℏ
is an integer positive number. Let’s denote that integer by n, and solve for energy ℰ:
In[]:=
Solve
2ℰ-ωℏ
2ωℏ
==n
Out[]=
ℰ
1
2
(1+2n)ωℏ
These are quantized energy levels (ie energy eigenvalues) of a harmonic oscillator.
So, the eigenfunctions reduces to:
In[]:=
ParabolicCylinderD
2ℰ-ωℏ
2ωℏ
,
2
m
x
ω
ℏ
/.ℰ
1
2
(1+2n)ωℏ//FullSimplify
Out[]=
ParabolicCylinderDn,
2
m
x
ω
ℏ

Now, let’s denote the eigenfunctions as follows:
In[]:=
ψ[n_,x_]:=ParabolicCylinderDn,
2mω/ℏ
x
where  represents the normalization constant, yet to be determined.
For
n=0,1,...,10
, let’s find the integration of probability function over all the space (
∫
ψ
n
(x)
2
|
x
):
In[]:=
TableIntegrateParabolicCylinderDn,
2mω/ℏ
x^2,{x,-∞,∞},Assumptions->mωℏ>0,{n,5}
Out[]=

π
ℏ
mω
,2
π
ℏ
mω
,6
π
ℏ
mω
,24
π
ℏ
mω
,120
π
ℏ
mω

Now let’s see if we can get an analytical formula out of that, as a function n
In[]:=
=FindSequenceFunction[%,n]
Out[]=
π
ℏ
mω
Pochhammer[1,n]
So if I divide the solution we got before by

, I will get a normalized eigenfunction:
In[]:=
1

ParabolicCylinderDn,
2mω/ℏ
x//FunctionExpand//FullSimplify
Out[]=
-n/2
2
-
m
2
x
ω
2ℏ

HermiteHn,x
mω
ℏ

1/4
π
ℏ
mω
Gamma[1+n]
In[]:=
ϕ[n_,x_]:=
-n/2
2
-
m
2
x
ω
2ℏ

HermiteHn,x
mω
ℏ

1/4
π
ℏ
mω
Gamma[1+n]
For example, let’s double-check that the eigenfunctions are normalized:
In[]:=
Table[Integrate[ϕ[n,x]^2,{x,-∞,∞},Assumptions->mω/ℏ>0],{n,0,5}]
Out[]=
{1,1,1,1,1,1}
So we managed to find the normalized eigenstates of a quantum harmonic oscillator. Make sure to refer your students to the Wolfram Demonstration Project, which contains many neat examples on harmonic oscillators.