Computer Algorithms For Solving The SCHR Odinger and Poisson Equations
Computer Algorithms For Solving The SCHR Odinger and Poisson Equations
the Schr
odinger and Poisson equations
Anders Blom
Division of Solid State Theory
Department of Physics, Lund University
Solvegatan 14 A, S223 62 Lund, Sweden
Anders.Blom@teorfys.lu.se
December 2, 2002
Introduction
One of the most important tasks within modern physics is the solution of the Schrodinger equation,
the fundamental equation of quantum mechanics. At the same time, this is a highly non-trivial
task, especially in more than one dimension. By reducing the problem, typically by symmetry
considerations, to a single dimension, the problem is however manageable by numerical methods,
and we shall in this short document discuss how the numerical calculations are carried out.
The Schr
odinger equations is actually closely related to another very important equation, the
Poisson equation. These are both are both examples of second order partial differential equations,
with the minor but highly important difference that the Schrodinger equation is an eigenvalue
equation. Because the Schr
odinger equation is an eigenvalue equation, it is not sufficient to simply
integrate the differential equation over the interval of interest, since we do not know the eigenvalue. Hence we need a way to solve both for the eigenvalue and the wavefunction (eigenfunction)
simultaneously.
In either case we need a method for integrating the differential equations, so these will be
presented first. In the one-dimensional case things are simplified in that we have ordinary differential equations instead of partial. Then we will go on to show how to use these methods to
find the eigenvalues. Finally, we will discuss what changes one has to introduce to handle cases
where the mass changes with the coordinate, which represents the important case of semiconductor
heterostructure systems.
Atomic units
Before going into the numerical algorithms, we shall briefly discuss system of units. The standard
system of units (such as CGS or SI) are developed for mechanics, not quantum mechanics. If
one tries to calculate things using the CGS values of the Planck constant h or the electron mass
me , problems with numerical accuracy will quickly arise. For computer calculations it is therefore
convenient to introduce so-called atomic units, in which the electron mass, the Planck constant
and the electron charge e are all unity:
me = h
= e2 = 1.
(In the case of MKSA units we replace e2 by e2 /40 .) This will give us a whole new set of units
for almost all physical quantities. For the problem at hand, however, only the units of length and
energy are relevant.
Unit of
Name
Length
Bohr radius
Energy
Hartree
Expression
h2
a0 =
me e2
h2
H =
me a20
Value in SI
0.529
A
27.712 eV
The Hartree is defined alternatively as twice the ionization energy of the 1s ground state of
hydrogen, or the Coulomb interaction energy between two electrons separated by the Bohr radius,
which in turn is the classical radius of the electron orbit in that same state.
In these units, the Schr
odinger and Poisson equations for an electron take the forms [1]
1
1
+
V
(x)
(x) = E(x),
(2.1)
2 x m (z) x
d2 V
4
= (x),
dx2
s
(2.2)
where is the charge density and U (z) the position-dependent potential energy of the electron.
Note the introduction of the relative effective mass m of the electron. At first we will set m to
a constant, but later we shall return to the more general case when m may change discontinuously
at certain points.
As mentioned in the Introduction, whether we are solving the Schrodinger or Poisson equation, we
need to integrate the differential equation first, before attempting to determine the eigenvalues (in
the case of the Schr
odinger equation). In this section we therefore use the eigenenergy E merely
as a parameter. We also assume that we are integrating the equation over some interval [x0 , xN ],
using N steps so that the stepsize is dx = (xN x0 )/N . This makes xi = i dx. (Note that this
requires N + 1 storage spaces!)
2
There are several general methods for integrating ordinary differential equations, which are all
based on reducing the problem to a system of first order differential equations [2]. However, for
the particular case of interest when there is no first order term, but only a second order we
need not follow that route, but can find specific algorithms. The more popular one seems to be
the Numerov algorithm [3], but there is also Stormers rule (refined by Henrici) [2].
In theory, it seems the Numerov algorithm is more accurate, if we only look to the order of the
first omitted term in the expansions. But due to the way we control the stepsize in the program (see
Section 4), the accuracy is controlled by other factors, and the Stormer rule turns out to produce
the same (or even better) accuracy in much shorter time than the Numerov scheme (c.f. Section 8).
Therefore the St
ormer rule will be the method of choice, although both will be presented here for
completeness.
3.1
The Numerov algorithm is based on a Taylor expansion of the function and its second derivative [3].
Let us write the Schr
odinger and Poisson equations in the following way:
00 (x) = 2m [V (x) E] (x) ve(x)(x),
(3.1)
(x)
00 (x) =
ve(x),
(3.2)
thus defining ve(x) for the two different cases. In the following we focus entirely on the Schrodinger
equation, since it contains more general features than the Poisson equation. Modifications for the
Poisson equation should be obvious.
Next we write down the Taylor expansions of the wavefunction and its second derivative ( is
the stepsize of the integration):
(x ) = (x) 0 (x) +
00
00
000
(x ) = (x) (x)
2 00
3 000
4 0000
2 (x) 6 (x) + 24 (x)
2
+ 2 0000 (x) + O(3 ).
+ O(5 ),
(3.3)
(3.4)
Now add the equations 00 (x + ) and 00 (x ) from (3.4) and rearrange to get
0000 (x) =
00 (x + ) 2 00 (x) + 00 (x )
+ O(2 ).
2
(3.5)
Inserting this expression into (3.3) and adding the equations in the same fashion, we get
(x + ) + (x ) =
= 2(x) + 2 00 (x) +
2 00
(x + ) 2 00 (x) + 00 (x ) + O(6 ). (3.6)
12
With this expression, given (x) at two adjacent points, we can reconstruct the entire wavefunction. However, since the function ve(x) is a function of the eigenenergy E, this must be known.
We will return to this problem shortly.
First, we write down, for reference, the most convenient way to implement (3.7). Let us define
three new quantities:
Tn 2 [V (xn ) E]/6,
Fn (1 Tn )(xn ),
(3.8)
(3.9)
Un (1 Tn )1 (2 + 10Tn ).
(3.10)
We may then write the Numerov algorithm as the following simple three-term recurrence relation
Fn+1 = Un Fn Fn1 .
(3.11)
This form is especially useful when integrating the entire range in one step using a matrix representation of the lattice [3].
As always when dealing with differential equations, the boundary conditions are important.
Without going into detailed derivations, for the Numerov algorithm we may use the following
initial conditions (boundary conditions are (x0 ) and 0 (x0 ) specified at the starting point x0 of
the integration interval1 ):
T1 = 2 [V (x0 ) E)/6
T2 = 2 [V (x0 + ) E]/6
F1 = (1 T1 )(x0 )
F2 = (1 T2 ) (1 + 6 T1 + 6 T12 )(x0 ) + (1 + 2 T1 +
3.2
6
5
T12 ) 0 (x0 )
St
ormers rule
A different, and as we will see superior, way to integrate an ordinary differential equation with only
a second order term is given by St
ormers rule [2]. This is applicable to a wide class of problems,
specified by
y 00 (x) = f (x, y)
(3.12)
with traditional boundary conditions y(x0 ) = y0 and the derivative y 0 (x0 ) given. We use h for the
stepsize in this section, since we will define a different soon; hopefully there will be no confusion.
The rule for integrating the differential equation is
yk+1 2yk + yk1 = h2 f (x0 + kh, yk ),
where the first step is performed in a slightly different way,
y1 = y0 + h y 0 (x0 ) + 21 hf (x0 , y0 ) .
1
We will soon see how we enforce boundary conditions in both ends of the interval.
(3.13)
(3.14)
Henrici showed how to reduce round-off errors by introducing k yk+1 yk , which makes
the rule
k = k1 + h2 f (x0 + kh, yk ),
yk+1 = yk + k .
Again the first step is taken differently to enforce the boundary conditions,
0 = h y 0 (x0 ) + 12 hf (x0 , y0 ) ,
y1 = y0 + 0 .
(3.15)
(3.16)
The derivative at the end-point xN of the interval we will soon show why it is necessary to
calculate this is given by
y 0 (xN ) = N 1 /h + 12 hf (xN , yN ).
(3.17)
Stepsize control
In the previous section we specified the number of steps to use when integrating over the interval.
But how do we determine what number of steps, or equivalently what stepsize, gives acceptable
accuracy? Of course, if we have access to a very fast computer, we can in principle set the stepsize to
the smallest number possible, but this may introduce truncation errors which reduce the accuracy.
A very general method for reducing the errors in any numerically calculated quantity is called
Richardsons deferred approach to the limit [2]: perform the calculation for some stepsize h, then
extrapolate to the continuum limit h = 0. Without going into any details, we shall now describe
a method to solve the problem of the unknown ideal stepsize, and at the same time get any
desired accuracy (within machine precision, obviously) of the wavefunction and its derivative at
the endpoint of the integration interval.
We state that the error series for both the Numerov algorithm and Stormers rule only contains
even powers of h, i.e. is a polynomial in h2 . This should be obvious from the derivation for
the Numerov case, but we do not give any detailed proof for either method. The reason this is
important, is that with simple polynomial interpolation, we remove two orders in the leading error
term for each step. Details are given in [2] (Sections 4.24.3), and we just state the algorithm here.
Integrate the differential equation with N =4 (ridiculously low, of course), and save the result,
viz. (xN ) and 0 (xN ). Repeat for N =8, 16, 32, . . . , and save the results in each step. After each
step, interpolate the results as polynomials of h2 , and extrapolate to h = 0. The extrapolation
algorithm should return the extrapolated values and an estimate of the error of the extrapolation.
We repeat this until these errors are smaller than some desired level of relative accuracy.
This way we get some Nfinal which is the number of steps necessary for the desired precision.
Note however that the accuracy of the extrapolated values of (xN ) and 0 (xN ) is higher than if
we just performed the integration with this number of steps, since those values are based on all
integrations (with all values of N ).
Now it is time to discuss how to find the eigenvalues of the Schrodinger equation, and also how
to apply boundary conditions at both endpoints of the integration interval. We assume that we
have a good method for integrating the differential equation over some interval [x0 , xN ], where we
specify the boundary conditions (the wavefunction and its derivative) at x0 and the routine returns
the values of the wavefunction and its derivative at xN with desired accuracy.
The idea is to divide the total integration interval [xA , xB ] into two parts, [xA , xC ] and [xC , xB ]
where xA < xC < xB . Then use the integration algorithm to integrate within the two sub-intervals
from the endpoints xA and xB towards the common matchpoint xC , using some guessed value for
the energy E. This way we immediately resolve the issue of how to apply boundary conditions at
both xA and xB .
What is the condition that E in fact is an eigenvalue? As always, when solving the Schrodinger
equation in two separate regions, we require that the wavefunction and its derivative are continuous
at the common point. If we label the solutions in the two sub-intervals A and B , the matching
condition becomes
A (xC , E) = B (xC , E)
0
0
and A
(xC , E) = B
(xC , E),
(5.1)
where we have indicated the parametrical dependence on the energy. These two conditions can be
combined into one:
0
0 (xC , E)
A
(xC , E)
= B
,
(5.2)
A (xC , E)
B (xC , E)
where the expression on each side is referred to as the logarithmic derivative. If the wavefunction
happends to have a node at the matchpoint, we can invert both sides, since it is unlikely that the
derivative is also zero. If they are, then we should shift the matchpoint2 .
This conditions holds exactly if E is an eigenvalue. But what happens if it is not? It seems
intuitively obvious that if a function is zero at some point, it should have different signs on opposite
sides of this point. It is however trivial to find counter-examples, such as f (x) = x2 around x = 0.
If we nevertheless take it as a postulate (and it is possible to prove [3]) that the function (the labels
xC and E are implied)
0
0
f (E) = A B
(5.3)
A
B
does change sign at the eigenvalue, we have an easy way for finding the eigenvalues: integrate the
differential equation for a number of different values of E (say an array covering the energy interval
of interest), and find the zeros of f (E) by for instance polynomial interpolation (if speed is desired
and precision not) or bracketing (for high precision eigenvalues).
A practical and simple way to perform this task is to study not the function f (E) but only
record whether it is positive or negative. To avoid the risk of dividing by zero, we instead study
0
0
g(E) = A
B B
A ,
(5.4)
Actually it is found from using the algorithms that the calculations take longer time if the matchpoint is at a
node of either the wavefunction or its derivative, even if in the actual implementation we do not use (5.2) but
instead a multiplicative variant to avoid the risk of dividing by zero.
which obviously also changes sign around the eigenvalue. This way we produce an array (with
entries corresponding to the relevant energy) of zeroes and ones, where zero represents g(E) < 0
and one the opposite. It is then easy to search this array and find where it changes from one to
zero.
Once the eigenvalues have been located in this way, we employ a standard routine for bracketing
the roots of the equation g(E) to desired accuracy. The method is the van WijngaardenDekker
Brent method, which uses a mix of quadratic interpolation (primary method) and simple bisection
(when the primary method gives too slow convergence). For details, see [2] (Section 9.3).
Although it may seem trivial to calculate the eigenfunction once we know the corresponding eigenvalue, there is one complication. If we only use the logarithmic derivative as a matching condition,
we do not actually ensure continuity of the wavefunction or its derivative at points where either
of them is (close to) zero. Similarly, in cases where both the wavefunction and the derivative have
different signs on either side of the matchpoint, these signs will cancel. As a consequence, we may
end up with a discontinuity in either the eigenfunction or its derivative.
A simple way to avoid this is to consider the boundary conditions at xA and xB . Here we must
specify the wavefunction and its derivative to supply initial values for the integration routines. In
practically all cases the wavefunction is chosen to vanish at the boundary, and in many cases also
the derivative. But if one looks closely at both the Numerov algorithm and Stormers rule, we see
that if we let both and 0 be zero at the boundary, we will never get anything but zero for all
points.
Hence we must specify a non-zero value for the derivative at the endpoint. But since we will
always get out unnormalized wavefunctions, this value can in fact be chosen arbitrarily. It may
then seem appealing to use some very small value, to be close to zero, but this may actually not
even work, since due to truncation errors we still only get zero for all points. Therefore it is
recommended to use some finite but not too large value, such as 1.
Even if nothing is said about the magnitude of the derivative at the endpoint (because of the
normalization ambiguity), the relative signs of the derivative at the two endpoints does matter.
Consider for example the simple case of the symmetric infinite well. The lowest eigenfunction is
a simple cos-function, with different signs of the derivative at the two endpoints (and no nodes).
But for the next lowest eigenfunction, a sin-function, we have the same signs (and a node in the
middle of the interval). If, as boundary conditions, we choose these signs in the wrong ways, we
will end up with either a discontinuous eigenfunction (in the cos case) or discontinuous derivative
(in the sin case).
It is therefore important to have the correct relative signs for 0 at the endpoints. Fortunately
there is a simple way to determine these, since to find the eigenvalues, the signs are not important.
Hence we can check during the process of finding the eigenvalues if the signs are chosen correctly,
and record whether they are or not, and use this information when finally calculating the eigenfunctions. Once the signs are chosen properly, it is a simple matter to use some large number
of steps (larger than or at least equal to Nfinal ) to get the eigenfunctions, using the integration
routines already discussed.
Naturally we also need to normalize the eigenfunctions, but this is very straightforward: first
7
integrate the absolute square of the eigenfunction over all space, and then divide the entire eigenfunction by the square-root of the result. There are very elaborate methods available for numerical
integration, which are able of producing practically any precision desired. However, these always
require the integrand to be calculated at many different points, and we only have the eigenfunctions specified in certain discrete points defined by the final number of integration steps, which of
course can be taken very large, but not too large, due to round-off errors. Alternatively one could
invent interpolation schemes which, in principle, could supply the wavefunction at any desired
point using polynomial interpolation using a number of neighboring points. But all this this is
really not necessary; acceptable precision is achieved using the simple extended Simpsons rule [2].
A final point worth mentioning regarding the wavefunctions is that by counting the number
of nodes of the found wavefunctions, we can check that we actually obtain all eigenvalues in the
intervall we are considering. This is because the ground state always has zero nodes, the first
excited state one node, and so on.
Until now, we have assumed the effective mass in the Schrodinger equation to be a constant
throughout the system, but there are certainly cases of interest most notably semiconductor
heterostructure systems where this is not the case. In this section we shall describe how this
effect rather effortlessly can be incorporated in the Stormer method for integrating the differential
equation.
Although one may in principle be interested in the case where the effective mass is an arbitrary
function m (x) of the coordinate, certainly the most commonly encountered case in practice is
that m changes abruptly (discontinuously) at certain points, but remains constant between these
points. In this case, the Schr
odinger equation can be written in the more usual form
1 2
(7.1)
2 + V (x) (x) = E(x).
2m x
The only tricky point is that in order to preserve the probability current, and hence ensure the
Hermiticity of the Schr
odinger equation, the so-called BenDanielDuke boundary condition [1]
1 0 (xm )
1 0+ (xm )
=
m (xm )
m+ (xm )
(7.2)
for the wavefunction (x) and its derivative 0 (x) must be imposed at those points xm where the
effective mass changes discontinuously. Here m is the effective mass to the right (left) of the
point xm , and 0 (x) indicate left and right derivatives. In addition, the wavefunction itself must
be continuous at xm , which is why there is no need to add any index to (xm ).
Now, to incorporate this in the St
ormer rule, we merely break the integration into several
sub-intervals in which the effective mass stays constant and impose the boundary condition
between the intervals. This is simple to accomplish, since the Stormer rule takes the derivative at
the end-point of the interval (or in this case sub-interval) as an input parameter.
To test the algorithms (and above all their implementations), it is always necessary to compare
computed values with known, preferably analytical, results. For the case of the Schrodinger equation, the simplest test case is the infinite square well, for which simple analytical results are well
known. Other candidates are the harmonic oscillator, and at least numerical solutions to arbitrary
precision may be found for the square well (finite depth).
We do not present quantitative results here, but there are important conclusions to be drawn
from the tests. When comparing the Numerov and Stormer methods, the differences are rather
small for the harmonic oscillator and square well, regarding both time and precision. But for
the infinite square well, the Numerov algorithm required over 3 minutes for the same task the
Stormer rule completed in 3 seconds! This is a remarkable difference, especially when considering
the fact that the St
ormer rule also gave greater precision. The conclusion must therefore be that
the Stormer rule is highly superior for slowly varying potentials, and otherwise at least as good as
the Numerov algorithm. Therefore the Numerov method is not recommended for real use.
As for actual numerical values, it is possible with the proper choices of program control parameters to get eigenvalues with relative precision of 1010 for the infinite well and close to 108 in most
other cases, all using St
ormers rule. Eigenfunctions have not been investigated so thoroughly, but
it seems they are at least reproduced with relative accuracy of the order 106 . Naturally there is
a trade-off between accuracy and speed.
References
[1] J. H. Davies, The physics of low-dimensional semiconductors, Cambridge University Press,
Cambridge, 1998.
[2] W. H. Press, S. A. Teukolsky, W. T. Wetterling, and B. P. Flannery, Numerical Recipes in C.
Cambridge University Press, 2nd Ed., 1992.
[3] G. Lindblad. Quantum Mechanics with MATLAB. Technical Report, Dept. of Physics, Royal
Institute of Technology, SE100 44 Stockholm, Sweden, 1999.