3 - Computational Physics Group

d2y
 k 2 xy  S x,
2
dx
d 2
 4r
2
dr
(3.1)
(3.4)
3.1 The Numerov algorithm
There is a particularly simple and efficient method for integrating second-order
differential equations having the form of (3.1). To derive this method, commonly called
the Numerov or Cowling’s method, we begin by approximating the second derivative in
(3.1) by the three-point difference formula ,
 
yn 1  2 yn  yn 1
h2
4






,
(3.6)

y

y

O
h
n
n
2
12
h
2
where we have written out explicitly the O h “error” term, which is derived easily
 
from the Taylor expansion (1.1, 1.2a, or 1,2, in classfiles/dif.html). From the differential
equation itself, we have

 

d2
yn 2  k 2 y  S
x x
dx
k 2 y n 1  2 k 2 y n  k 2 y n 1

h2
S  2Sn  Sn 1
2
.
 n 1

O
h
2
h
   
n
(3.7)
 
When this is substituted into (3.6), we can write, after some rearrangement,
 h2 2 
 5h 2 2 
 h2 2 
1  kn 1  yn 1  21 
kn  yn  1  kn 1  yn 1
 12


12




 12

h2
 Sn 1  10Sn  Sn 1   O h6 . (3.8)
12
Solving this linear equation for either yn 1 or yn 1 then provides a recursion relation
 
 6
for integrating either forward or backward in x, with a local error O h . Note that this
is one order more accurate that the fourth-order Runge-Kutta method (2.25), which might
be used to integrate the problem as two coupled first-order equations. The Numerov
scheme is also more efficient, as each step requires the computation of
only the lattice points.
k 2 and S
at
 Exercise 3.1 Apply the Numerov algorithm to the problem
d2y
2


4

y ; y 0  1 , y0   0 .
2
dx
x  0 to x  1 with various step sizes and compare the efficiency and
Integrate from
accuracy with some of the methods discussed in Chapter 2. Note that you will have to use
some special procedure (e.g., a Taylor series) to generate the value of
needed to start the three-term recursion relation.
y1  yh 
3.2 Direct integration of boundary value problems
As a concrete illustration of boundary value problems, consider trying to solve Poisson’s
equation (3.4) when the charge distribution is
 r  
which has a total charge
1 r
e ,
8
(3.9)

Q    r d r    r 4r 2 dr  1
3
0
The exact solution to this problem is
1
2
 r   1  r  2e  r ,
(3.10)
  r 1 follows immediately. This solution has the expected behavior
1
at large r ,  1, which corresponds to   r , the Coulomb potential from a
from which
unit charge.
Suppose that we try to solve this example as an ordinary initial value problem.
Since
has no singular behavior at the origin (e.g., there is no point charge),  is

regular there, which implies that   r vanishes at r  0; this is indeed the case
for the explicit solution (3.10). We could then integrate (3.4) outward from the origin
using the appropriate rearrangement of (3.8) (recall
k 2  0 here):
h2
n 1  2n  n 1  Sn 1  10Sn  Sn 1 ,
12
with
(3.11)
1
S  4r   re r .
2

However, to do so we must know the value of 1 (or, equivalently,
d / dr   at
r  0 ) in addition to 0  0 . This is not a very happy situation, since 1 is a part of
the very function we’re trying to find, and so is not known a priori. We will discuss
below what to do in the general case, but in the present example, since we have an



analytical solution, we can find 1 
r  h from (3.10). The following
FORTRAN program does the outward integration to r  20 , storing the solution in an
array and printing the exact result and error as it goes along.
C chap3a.for
DIMENSION PHI(0:200)
EXACT(R)=1.–(R+2)*EXP(-R)/2
SOURCE(R)=-R*EXP(-R)/2
H=.1
NSTEP=20./H
CONST=H**2/12
SM=0.
SZ=SOURCE(H)
PHI(0)=0
PHI(1)=EXACT(H)
DO 10 IR=1,NSTEP-1
R=(IR+1)*H
SP=SOURCE(R)
10
!array for the solution
!exact solution
!source function
!radial step
!number of points to R=20
!constant in Numerov method
!source at R=0
!source at R=H
!boundary condition ar R=0
!exact value at first point
!loop for outward integration
!radius at next point
!source at next point
!Eq. 3.11
PHI(IR+1)=2*PHI(IR)-PHI(IR-1)+CONST*(SP+10.*SZ+SM)
SM=SZ
!roll value
SZ=SP
CONTINUE
STOP
 Table 3.1 Errors in solving the Poisson problem defined by Eqs. (3.4, 3.9)
r
2
4
6
8
10
12
14
16
18
20
Exact
 r 
Analytical
0.729330
0.945053
0.990085
0.998323
0.999728
0.999957
0.999993
0.999999
1.000000
1.000000
-0.000003
-0.000006
-0.000005
0.000001
0.000010
0.000022
0.000036
0.000052
0.000065
0.000077
5% Error
 h 
 
in  h
0.049919
0.099838
0.149762
0.199690
0.249622
0.299556
0.349493
0.399431
0.449366
0.499301
Linear
correction
-0.000016
-0.000011
-0.000007
-0.000003
-0.000001
0.000002
0.000003
0.000000
0.000000
0.000000
Note that computation is minimized by keeping track of the values of S at the current and
adjacent lattice points (SZ, SM, and SP) and by computing the constant h2/12 appearing
in the Numerov formula (3.11) outside of the integration loop.
Results generated by this program are given in the first three columns of Table
3.1, which show that the numerical solution is rather accurate for small r. All is not well,
however. The error per step gets larger at large r (the error after the 20 step from r  0
r  2 is 3  106 , while during the 20 steps from r  18 to r  20 , it grows
5
by 1.2  10 , 4 times as much), and the solution will become quite inaccurate if
to
continued to even larger radii. This behavior is quite surprising because the errors in the
Numerov integration should be getting smaller at large r as  becomes a constant.
Further symptoms of a problem can be found by considering a more general case.
We then have no analytical formula to give us  near the origin, which we need to get
the three-term recursion relation started. One way to proceed is find
numerical quadrature of the Coulomb potential,
0   
 r 
r
0 by direct

d r  4  rdr ,
3
0
perhaps using Simpson’s rule. There will, however, always be some error associated with
the value obtained. We can simulate such an error in the code above (suppose it is 5%) by
inserting the line (just before the DO loop)
PHI(1)=.95*PHI(1)
The code then gives the errors listed in the fourth column of Table 3.1. Evidently
disaster has struck, for a 5% change in the initial conditions has induced a 50% error in
the solution at large r.
It is simple to understand what has happened. Solutions to the homogeneous
version of (3.4),
d 2
 0,
2
dr
can be added to any particular solution of (3.4) to give yet another solution. There are two
linearly independent homogenous solutions,
 ~ r ;  ~ const ,
and
 ~ const
1
; ~r .
The general solution to (3.4) in the asymptotic region ( where
vanishes and the
equation is homogeneous) can be written as linear combination of these two functions,
but the latter, sub-dominant solution is the physical one, since we know the potential at
large r is given by   1 / r . Imprecision in the specification of  at the origin or
any numerical round-off error in the integration process can introduce a small admixture
of the   r solution, which eventually dominates at large r.
The cure for this difficulty is straightforward: subtract a multiple of the “bad”,
unphysical solution to the homogeneous equation from the numerical result to guarantee
the physical behavior in the asymptotic region. It is easy to see that the “bad” results
shown in the fourth column of Table 3.1 vary linearly with r for large r. The following
lines of code (which can be inserted just before the STOP statement) then fit the last 10
points of the numerical solution to the form

  mr  b
and subtract mr from the numerical results to guarantee the appropriate large-r behavior.
20
SLOPE=(PHI(NSTEP)-PHI(NSTEP-10))/(10*H)
DO 20 IR=1,NSTEP
R=IR*H
PHI(IR)=PHI(IR)-SLOPE*R
DIFF=EXACT(R)-PHI(IR)
PRINT *, R,EXACT(R),PHI(IR),DIFF
CONTINUE
The errors in  so obtained are shown in the final column of Table 3.1; the solution is
even more accurate at large r than the uncorrected one found when the exact value of
PHI(1) is used to start the integration.
In this simple example, the instabilities are not too severe; satisfactory results for
moderate values of r are obtained with outward integration when the exact (or reasonably
accurate approximate) value of PHI(1) is used. Alternatively, it is also feasible to
integrate inward, starting at large r with   Q , independent of r. This results in a
solution that often satisfies accurately the boundary condition at r  0 and avoids
having to perform a quadrature to determine the (approximate) starting value of PHI(1).
 Exercise 3.2 Solve the problem defined by Eqs. (3.4, 3.9) by Numerov integration
inward from large r using the known asymptotic behavior of  for the starting values.
How well does your solution satisfy the boundary condition 
r  0  0 ?
3.3 Green’s function solution of boundary value problems
When the two solutions to the homogeneous equation have very different behaviors,
some extra precautions must be taken. For example, in describing the potential from a
charge distribution of a multiply order l  0 , the monopole equation (3.4) is modified
to
 d 2 l l  1
  4r ,
 2
2 
r 
 dr
(3.12)
which has the two homogeneous solutions
 ~ r l 1
l
;  ~r .
For large r, the first of these solutions is much larger than the second, so that ensuring the
correct asymptotic behavior by subtracting a multiple of this dominant homogeneous
solution from a particular solution we have found by outward integration is subject to
large round-off errors. Inward integration is also unsatisfactory, in that the unphysical
r 1 solution is likely to dominate at small r.
One possible way to generate an accurate solution is by combining the two
methods. Inward integration can be used to obtain the potential for r grater than some
intermediate radius, rm , and outward integration can be used for the potential when
r  rm . As long as rm is chosen so that neither homogenous solution is dominant, the
outer and inner potentials obtained respectively from these two integrations will match at
rm and, together, describe the entire solution. Of course, if the inner and outer potentials
don’t quite match, a multiple of the homogenous solution can be added to the former to


correct for any deficiencies in our knowledge of   r  0 .
Sometimes the two homogenous solutions have much different behaviors that it is
impossible to find a value of rm that permits satisfactory integration of the inner and
outer potentials. Such cases can be solved by the Green’s function of the homogenous
equation. To illustrate, let us consider Eq. (3.1) with the boundary condition
  x  0    x     0 .
Since the problem is linear, we can write the solution as

  x    G  x, xS  xdx ,
0
where G is the Green’s function satisfying
(3.13)
 d2

2
(3.14)
 2  k  x G  x, x    x  x.
 dx

It is clear that G satisfies the homogenous equation for x  x . However, the derivative
of G is discontinues at x  x , as can be seen by integrating (3.14) from x  x  
to x  x   , where  is an infinitesimal:
dG
dG

 1.
(3.15)
dx x  x dx x  x 
The problem, of course, is to find G. This can be done by considering two
solutions to the homogenous problem,
 and  , satisfying the boundary conditions at
x  0 and x   , respectively, and normalized that their Wronskian,
d
d
W       ,
dx
dx
(3.16)
is unity. (It is easy to use the homogenous equation to show that W is independent of x).
Then the Green’s function is given by
(3.17)
Gx, x   x  x ,
x are the smaller and larger of x and x , respectively. It is evident
where x and
that this expression for G satisfies the homogenous equation and the discontinuity
condition (3.15). From (3.13), we then have the explicit solution
x

0
x
  x     x    xS  xdx    x     xS  xdx . (3.18)
This expression can be evaluated by a numerical quadrature and is not subject to any of
the stability problems we have seen associated with a direct integration of the
homogenous equation.
2


In the case of arbitrary k , the homogenous solutions  and  can be found
numerically by outward and inward integrations, respectively, of initial value problems
2
 
and then normalized to satisfy (3.16). However, for simple forms of k x , they are
known analytically. For example, for the problem defined by Eq. (3.12), it is easy to
show that
 r   r l 1 ;  r   
1 l
r
2l  1
are one possible set of homogenous solutions satisfying the appropriate boundary
conditions and Eq. (3.16).