Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Physicists LOVE the harmonic oscillator potential. It is one of our favorites for two very important reasons: 1) It is one of handful of potentials that we can solve exactly and 2) any restoring force potential can be approximated as a harmonic oscillator near the equilibrium point. This is why we often approximate solid matter as a collection of ball-and-springs; the molecular bonds between atoms behave like springs if you don't compress the solid too much.
The harmonic potential energy equation is (U=\frac{1}{2}m \omega^2 x^2). Plugging this into Schrodinger's equation gives
[\frac{-\hbar^2}{2m} \frac{d^2}{dx^2}\psi(x) + \frac{1}{2}m \omega^2 x^2 \psi(x) = E \psi(x)]
Solving differential equations
When solving differential equations it helps to specify which variables are real and which are positive using the
assume()
command.You need to specify the independent variable of your function. In this case we specify that is a function of .
The differential equation is defined using the Python
def
method.This creates a function which we can differential, integrate, or solve using the differential equation solver.
Use
desolve()
to solve the differential equation. The arguments ofdesolve()
are the differential equation to solve, the dependent variable ( in this case), and the independent variable x (specified usingivar=x
to indicate the independent variable). In this case,desolve()
with encounter an issue unless you specifycontrib_ode=True
, in which case a slightly different solver is used to handle the differential equation.
The Kummer functions are confluent hypergeometric functions. At present SageMath cannot evaluate these functions so I'll enter the first few wave functions for you manually below.
In general, the quantum harmonic oscillator wave function can be found from the following relationships:
[\psi_n(x) = \left( \frac{1}{2^n n!} \right) \left( \frac{\alpha}{\pi} \right) H_n(\alpha^{1/2}x) e^{-\alpha x^2/2} ]
where the Hermite polynomial is found from
[H_n(x) = (-1)^n e^{x^2} \frac{d^n}{dx^n} e^{-x^2} ]
For You To Try:
Prove that the quantum harmonic oscillator wave functions are normalized
Fancier 2D Plotting
You can add titles, label axes, change label size, and move the title of plots
You can specify different line styles:
Solid lines '-'
Dashed lines '--'
Dash dot '-.'
Dotted ':'
If you assign a plot to a variable name, you can add on additional plots and features.
In Python,
P+=text...
is the same asP=P+text...
. This is called in-place additionText can be added to a plot using
text('something profound', (x,y), color='red)
wherex
andy
are the location of the midpoint of the text.Arrows can be added to point out features by specifying the location of the head and tail of the arrow
arrow2d((x1,y1),(x2,y2))
Multiple plots can be combined into a single graph by adding
plot()
commands toP
Plot the ground state wavefunction of the one-dimensional harmonic oscillator
For You To Try:
Plot the , , and wave functions for the quantum harmonic oscillator on the same plot
Describe how the number of nodes in the wave function relates to the value of n
Draw arrows to indicate the location of the nodes of the wave function
Calculate harmonic oscillator energy from Schrodinger equation and wave function
We can check that the wave functions satisfy Schrodinger's equation and give the correct energy. The equation is
[\hat{H}\psi(x) = E \psi(x).]
Since is a number (unlike , which is an operator), we can divide both sides of the equation by and cancel the terms on the right hand side to get an equation for the energy.
[\frac{\hat{H}\psi(x)}{\psi(x)} = E.]
Simplify Symbolic Expressions
The
.expand()
command will distribute terms and expand powers in an expressionUseful for getting terms to cancel out
The
.canonicalize_radical()
command returns the canonical form of logs and exponentsOther simplification commands include:
.combine()
,.simplify_fill()
,.simplify_trig()
,.reduce_trig()
,.simplify_log()
,.trig_expand()
This result does not look like what we would expect. However, computer algebra systems like Maxima (the heart of SageMath computer algebra) sometimes have issues with non-integer powers. One trick is to raise this function to the nth power (in this case it would be to the 4th power) to get rid of non-integer powers, simplify the equation, then take the nth root to get the final result. Let's try this:
For you to try:
Use the Hamiltonian to find the energies of the (n=1), (n=2), and (n=3) states.
Remember that (E = \frac{H \psi(x)}{\psi(x)})
If your resulting equation is a huge mess, try squaring, expanding, then simplifying the equation
Check that your results are correct by using the function
E_n(n,omega)
Calculate the commutator
We can define the momentum operator using def p:
. The operator is just multiplication by the variable so we don't need to define a separate operator. One thing to keep in mind is that we must explicitly apply the operators (i.e. All terms that the operator operates on must be inside the parentheses as an argument to the operator function)
Raising and Lowering Operators
The raising and lowering operators are powerful tools for exploring the quantum harmonic oscillator. Most quantum physics texts will cover these in detail. The following cells will explore a few things you can do in SageMath with the raising and lowering operators. The cell below defines the operators.
Note: The output from the cell below includes a term . This is SageMath notation for the derivative with respect to the first variable in the function (remember that Python starts numbering at zero). If was a function of and , then the derivative of with respect to would be denoted .
Demonstrate that
Any easy way to show two equations are equal is to divide one equation by the other and show the result is equal to 1
This cuts down on manipulation of equations to put them in the same format
To get all terms to cancel we will raise everything to the 4th power and then take the 4th root
The
.canonicalize_radical()
command is used to expand the exponent terms
Show that
Demonstrate that
In addition to
.canonicalize_radical()
we also have to use.combine()
to collect terms over a common denominator, and.expand()
.
Show that
For You To Try
Show that Show that
Projects and Problem Ideas
Use to generate higher quantum harmonic oscillator wave functions and then use to determine the energy of those states.
Rewrite and in terms of and and use the raising and lowering operators to calculate the expectation values and . Compare your results to what you get from and .