You are on page 1of 5

# Problem Sheet 6: Python and Quantum Mechanics

## Important note: all integrals in this exercise will be calculated numerically.

This week the Python exercises relate to PH2210, the lecture course in Quantum Mechanics. Using Pythons numerical integration and plotting features the exercises below should
reinforce the concepts of orthogonality and completeness of the normalised wavefunctions.
New Python syntax that will be needed will be introduced in the first lecture of the week:
1

## from s c i p y . i n t e g r a t e import quad

# syntax
#s c i p y . i n t e g r a t e . quad ( func , a , b , a r g s =() )

11

#
#
#
#

f u n c : f u n c t i o n A Python f u n c t i o n o r method t o i n t e g r a t e .
a : Lower l i m i t o f i n t e g r a t i o n ( u s e numpy . i n f f o r i n f i n i t y ) .
b : Upper l i m i t o f i n t e g r a t i o n ( u s e numpy . i n f f o r +i n f i n i t y ) .
a r g s : t u p l e , o p t i o n a l e x t r a arguments t o p a s s

d e f f u n c ( x , n , w) :
r e t u r n nx w
i p r o d , e r r = quad ( func , 0 , 1 , a r g s =(2 ,3) )

16

p r i n t v a l u e = %.3 f % i p r o d , # t h e e v a l u a t i o n o f t h e i n t e g r a l o f 2 x 3
between x=0 and x=1
p r i n t e r r o r= {} . format ( e r r ) # t h e n u m e r i c a l u n c e r t a i n t y i n t h e i n t e g r a l
#E v a l u a t i n g i n t e g r a l g i v e s 0 . 5 x 4
p r i n t Exact s o l u t i o n = {} . format ( 0 . 5 1 . 0 4 . )

quadsyntax.py
1

from s c i p y . s p e c i a l import h e r m i t e
# This s p e c i a l f u n c t i o n r e t u r n s t h e nth h e r m i t e p o l y n o m i a l h n ( x ) , o r t h o g o n a l
o v e r ( i n f , i n f ) with w e i g t h i n g f u n c t i o n ( exp(x 2 )
s c i p y . s p e c i a l . h e r m i t e ( n ) # r e t u r n s t h e nth p o l y n o m i a l

## # The p o l y n o m i a l i s r e t u r n e d i n t h e form o f a poly1d array , a one d i m e n s i o n a l

polynomial c l a s s
# Read t h e poly1d h e l p f o r more i n f o r m a t i o n , but X42x3+4x 0.1 x+7 would
be r e t u r n e d a s
# poly1d [ 1 , 2, 4 , 0.1 , 7 ] , with c o e f f i c e i n t s g i v e n i n d e c r e a s i n g power o f x

hermitesyntax.py

## PS6 Ex1. The Infinite Square Well

The 1D infinite square well is described by the potential: V = 0 for 0 < x < L, and
= E, in lectures you have obtained the following
V = otherwise. Solving the TISE, H
1

## wavefunctions (eigenfunctions) and energies (eigenvalues):

r
 nx 
2
n (x) =
sin
L
L

(1)

~2 k 2
~2 n2 2
=
(2)
2m
2m L2
We are going to demonstrate various properties of the square well; to numerically calculate
the different integrals (orthogonalities, expectation values, etc.) you will need to set L = 1.
En =

1. Plot separately 3 (x), 4 (x) and the product 3 (x) 4 (x). Show that you would
expect the latter to integrate to zero.
2. Integrate the product 3 (x) 4 (x) between 0 and L to show that 3 and 4 are
orthogonal.
3. Choose four different values of n and m to demonstrate that the wavefunctions are
orthogonal and normalised:
Z L

m
(x) n (x) dx = n,m
0

RL
4. Show that the expectation value hxi = 0 n (x) xn (x) dx = L/2 for states with
quantum number n = 4, 7, and 9.
p
5. Calculate hx2 i and x = hx2 i hxi2 for n = 4, 7, and 100.

6. Demonstrate that as n large, x L/ 12. How does this result compare to the
classical result?

## PS6 Ex2. Completeness

An initial wavefunction in the well is given by
 x 3 11  x 2 4  x 
A(x) =

+
.
L
7 L
7 L
1. Plot A(x) and confirm that it satisfies the boundary conditions at x = 0 and L.

## 2. Show that the normalisation constant for A(x) is 735.

3. The eigenfunctions for the square well n (x) form a complete set. That is, any function f (x) defined in the same region of space and satisfying the same boundary conRL
P
ditions can be expressed as f (x) = n cn n (x), where cn = 0 n (x) f (x) dx. Taking
f (x) = A(x) and using the wavefunctions n defined above, write a program to calculate the coefficients cn . Show that c1 = 0.353298, c2 = 0.927407, c3 = 0.0130851,
c4 = 0.115926, c5 = 0.00282638, c6 = 0.0343484, and that higher coefficients are much
smaller.

4. Show that
i=
X

|ci |2 = 1.

i=1

## Choose a large number to replace in the sum.

5. Show that
i=
X

|ci |2 i2 = 3.849.

i=1

Therefore show that the expectation value for the energy is hEi = 3.849E0 , where E0
is the energy of the ground state.

## PS6 Ex3. Quantum Harmonic Oscillator

The wavefunctions in a parabolic potential,
1
1
V (x) = kx2 = m 2 x2
2
2
are given by:
x2
Hn (x/a)
e 2a2 ,
n (x) = p

2n n! a2

where
qHn (x) are the Hermite polynomials encountered in PH2130 and a is a length given by
~
a = m
. The energy of the nth quantum state is En = (n + 12 )~. Note that for the QHO
the ground state is n = 0, whereas in the infinite square well it is n = 1.
1. In Python write the code to generate the Hermite polynomials for arbitrary n. Generate
the normalised wavefunctions tabulated below for n = 0, 1, 2, 3 and 4; you will need to
take a=1.
n

n (x)
2

0
1
2
3
4

x2
1
2a

e
4
2
a
2
2 (x/a) x 2
2a
1 (x) =
e
4
a2
2
[4(x/a)2 2] x 2
2a
2 (x) = 22
e
4
a2
2
[8(x/a)3 12(x/a)] x 2
2a

3 (x) =
e
4
4 3 a2
2
[16(x/a)4 48(x/a)2 +12] x 2
2a

4 (x) =
e
4
8 6 a2

0 (x) =

## 2. If the wavefunctions are orthogonal and normalised then

Z

m
(x) n (x) dx = n,m .

Write a simple program to check this integral for the five states above. You will not
be able to integrate to , and you will have to make approximations.
3. Plot the wavefunction n (x) and the probability densities pn (x) = |n (x)|2 for n = 0
to 10, see Figure 1. For clarity the individual traces need to be vertically offset in an
appropriate manner.

Figure 1: The wave functions n (x) and probability densities pn (x) = |n (x)|2 for the lowest energy
states in a quantum harmonic oscillator

RL
4. Demonstrate that the expectation value for the displacement, hxi = L n (x) x n (x) dx,
is zero for a selection of quantum numbers n.
p
5. Calculate hx2 i and x = hx2 i hxi2 for n = 4, 7, and 10. Hence deduce for general
n that hx2 i = 2n+1
. Hence show that the uncertainty in position for the state n (x) is
2
q
x = 2n+1
.
2
6. In a classical description of oscillations in a harmonic potential, x =x0 sin(t), the
average amplitude is hxi = 0 and the rms amplitude is x = x0 / 2. Assuming
that the
classical and quantum calculations yield the same result for x, show that
x0 = 2n + 1.
4

7. Plot the quantum probability densities pn (x) = |n (x)|2 for large n (try 10, 30 and
50). On the same graph, plot the classical probability density pcl (x) derived in lectures
(see below). Comment on your results.
1
pcl (x) = p 2
x0 x2