D02 Chapter Contents
D02 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentD02KEF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

## 1  Purpose

D02KEF finds a specified eigenvalue of a regular or singular second-order Sturm–Liouville system on a finite or infinite interval, using a Pruefer transformation and a shooting method. It also reports values of the eigenfunction and its derivatives. Provision is made for discontinuities in the coefficient functions or their derivatives.

## 2  Specification

 SUBROUTINE D02KEF ( XPOINT, M, MATCH, COEFFN, BDYVAL, K, TOL, ELAM, DELAM, HMAX, MAXIT, MAXFUN, MONIT, REPORT, IFAIL)
 INTEGER M, MATCH, K, MAXIT, MAXFUN, IFAIL REAL (KIND=nag_wp) XPOINT(M), TOL, ELAM, DELAM, HMAX(2,M) EXTERNAL COEFFN, BDYVAL, MONIT, REPORT

## 3  Description

D02KEF has essentially the same purpose as D02KDF with minor modifications to enable values of the eigenfunction to be obtained after convergence to the eigenvalue has been achieved.
It first finds a specified eigenvalue $\stackrel{~}{\lambda }$ of a Sturm–Liouville system defined by a self-adjoint differential equation of the second-order
 $px y′ ′ + q x;λ y=0 , a
together with appropriate boundary conditions at the two, finite or infinite, end points $a$ and $b$. The functions $p$ and $q$, which are real-valued, are defined by COEFFN. The boundary conditions must be defined by BDYVAL, and, in the case of a singularity at $a$ or $b$, take the form of an asymptotic formula for the solution near the relevant end point.
When the final estimate $\lambda =\stackrel{~}{\lambda }$ of the eigenvalue has been found, the routine integrates the differential equation once more with that value of $\lambda$, and with initial conditions chosen so that the integral
 $S=∫aby x 2 ∂q ∂λ x;λdx$
is approximately one. When $q\left(x;\lambda \right)$ is of the form $\lambda w\left(x\right)+q\left(x\right)$, which is the most common case, $S$ represents the square of the norm of $y$ induced by the inner product
 $f,g = ∫ab fx gx wx dx ,$
with respect to which the eigenfunctions are mutually orthogonal. This normalization of $y$ is only approximate, but experience shows that $S$ generally differs from unity by only one or two per cent.
During this final integration the REPORT is called at each integration mesh point $x$. Sufficient information is returned to permit you to compute $y\left(x\right)$ and ${y}^{\prime }\left(x\right)$ for printing or plotting. For reasons described in Section 8.2, D02KEF passes across to REPORT, not $y$ and ${y}^{\prime }$, but the Pruefer variables $\beta$, $\varphi$ and $\rho$ on which the numerical method is based. Their relationship to $y$ and ${y}^{\prime }$ is given by the equations
 $px y′ = β expρ2 cosϕ2 , y=1β expρ2 sinϕ2 .$
A specimen REPORT is given in Section 9 below.
For the theoretical basis of the numerical method to be valid, the following conditions should hold on the coefficient functions:
 (a) $p\left(x\right)$ must be nonzero and must not change sign throughout the interval $\left(a,b\right)$; and, (b) $\frac{\partial q}{\partial \lambda }$ must not change sign throughout the interval $\left(a,b\right)$ for all relevant values of $\lambda$, and must not be identically zero as $x$ varies, for any $\lambda$.
Points of discontinuity in the functions $p$ and $q$ or their derivatives are allowed, and should be included as ‘break points’ in the array XPOINT.
A good account of the theory of Sturm–Liouville systems, with some description of Pruefer transformations, is given in Chapter X of Birkhoff and Rota (1962). An introduction to the use of Pruefer transformations for the numerical solution of eigenvalue problems arising from physics and chemistry is given in Bailey (1966).
The scaled Pruefer method is described in a short note by Pryce and Hargrave (1977) and in some detail in the technical report by Pryce (1981).

## 4  References

Abramowitz M and Stegun I A (1972) Handbook of Mathematical Functions (3rd Edition) Dover Publications
Bailey P B (1966) Sturm–Liouville eigenvalues via a phase function SIAM J. Appl. Math. 14 242–249
Banks D O and Kurowski I (1968) Computation of eigenvalues of singular Sturm–Liouville Systems Math. Comput. 22 304–310
Birkhoff G and Rota G C (1962) Ordinary Differential Equations Ginn & Co., Boston and New York
Pryce J D (1981) Two codes for Sturm–Liouville problems Technical Report CS-81-01 Department of Computer Science, Bristol University
Pryce J D and Hargrave B A (1977) The scaled Prüfer method for one-parameter and multi-parameter eigenvalue problems in ODEs IMA Numerical Analysis Newsletter 1(3)

## 5  Parameters

1:     XPOINT(M) – REAL (KIND=nag_wp) arrayInput
On entry: the points where the boundary conditions computed by BDYVAL are to be imposed, and also any break points, i.e., ${\mathbf{XPOINT}}\left(1\right)$ to ${\mathbf{XPOINT}}\left(m\right)$ must contain values ${x}_{1},\dots ,{x}_{m}$ such that
 $x1≤x2
with the following meanings:
(a) ${x}_{1}$ and ${x}_{m}$ are the left- and right-hand end points, $a$ and $b$, of the domain of definition of the Sturm–Liouville system if these are finite. If either $a$ or $b$ is infinite, the corresponding value ${x}_{1}$ or ${x}_{m}$ may be a more-or-less arbitrarily ‘large’ number of appropriate sign.
(b) ${x}_{2}$ and ${x}_{m-1}$ are the Boundary Matching Points (BMPs), that is the points at which the left and right boundary conditions computed in BDYVAL are imposed.
If the left-hand end point is a regular point then you should set ${x}_{2}={x}_{1}$ $\left(=a\right)$, while if it is a singular point you must set ${x}_{2}>{x}_{1}$. Similarly ${x}_{m-1}={x}_{m}$ ($\text{}=b$) if the right-hand end point is regular, and ${x}_{m-1}<{x}_{m}$ if it is singular.
(c) The remaining $m-4$ points ${x}_{3},\dots ,{x}_{m-2}$, if any, define ‘break points’ which divide the interval $\left[{x}_{2},{x}_{m-1}\right]$ into $m-3$ sub-intervals
 $i1=x2,x3,…,im-3=xm-2,xm-1.$
Numerical integration of the differential equation is stopped and restarted at each break point. In simple cases no break points are needed. However, if $p\left(x\right)$ or $q\left(x;\lambda \right)$ are given by different formulae in different parts of the interval, then integration is more efficient if the range is broken up by break points in the appropriate way. Similarly points where any jumps occur in $p\left(x\right)$ or $q\left(x;\lambda \right)$, or in their derivatives up to the fifth-order, should appear as break points.
Examples are given in Sections 8 and 9. XPOINT determines the position of the Shooting Matching Point (SMP), as explained in Section 8.3.
Constraint: ${\mathbf{XPOINT}}\left(1\right)\le {\mathbf{XPOINT}}\left(2\right)<\cdots <{\mathbf{XPOINT}}\left({\mathbf{M}}-1\right)\le {\mathbf{XPOINT}}\left({\mathbf{M}}\right)$.
2:     M – INTEGERInput
On entry: the number of points in the array XPOINT.
Constraint: ${\mathbf{M}}\ge 4$.
3:     MATCH – INTEGERInput/Output
On entry: must be set to the index of the ‘break point’ to be used as the matching point (see Section 8.3). If MATCH is set to a value outside the range $\left[2,m-1\right]$ then a default value is taken, corresponding to the break point nearest the centre of the interval $\left[{\mathbf{XPOINT}}\left(2\right),{\mathbf{XPOINT}}\left(m-1\right)\right]$.
On exit: the index of the break point actually used as the matching point.
4:     COEFFN – SUBROUTINE, supplied by the user.External Procedure
COEFFN must compute the values of the coefficient functions $p\left(x\right)$ and $q\left(x;\lambda \right)$ for given values of $x$ and $\lambda$. Section 3 states the conditions which $p$ and $q$ must satisfy. See Sections 8.4 and 9 for examples.
The specification of COEFFN is:
 SUBROUTINE COEFFN ( P, Q, DQDL, X, ELAM, JINT)
 INTEGER JINT REAL (KIND=nag_wp) P, Q, DQDL, X, ELAM
1:     P – REAL (KIND=nag_wp)Output
On exit: the value of $p\left(x\right)$ for the current value of $x$.
2:     Q – REAL (KIND=nag_wp)Output
On exit: the value of $q\left(x;\lambda \right)$ for the current value of $x$ and the current trial value of $\lambda$.
3:     DQDL – REAL (KIND=nag_wp)Output
On exit: the value of $\frac{\partial q}{\partial \lambda }\left(x;\lambda \right)$ for the current value of $x$ and the current trial value of $\lambda$. However DQDL is only used in error estimation and, in the rare cases where it may be difficult to evaluate, an approximation (say to within $20%$) will suffice.
4:     X – REAL (KIND=nag_wp)Input
On entry: the current value of $x$.
5:     ELAM – REAL (KIND=nag_wp)Input
On entry: the current trial value of the eigenvalue parameter $\lambda$.
6:     JINT – INTEGERInput
On entry: the index $j$ of the sub-interval ${i}_{j}$ (see specification of XPOINT) in which $x$ lies.
COEFFN must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which D02KEF is called. Parameters denoted as Input must not be changed by this procedure.
5:     BDYVAL – SUBROUTINE, supplied by the user.External Procedure
BDYVAL must define the boundary conditions. For each end point, BDYVAL must return (in YL or YR) values of $y\left(x\right)$ and $p\left(x\right){y}^{\prime }\left(x\right)$ which are consistent with the boundary conditions at the end points; only the ratio of the values matters. Here $x$ is a given point (XL or XR) equal to, or close to, the end point.
For a regular end point ($a$, say), $x=a$, a boundary condition of the form
 $c1ya+c2y′a=0$
can be handled by returning constant values in YL, e.g., ${\mathbf{YL}}\left(1\right)={c}_{2}$ and ${\mathbf{YL}}\left(2\right)=-{c}_{1}p\left(a\right)$.
For a singular end point however, ${\mathbf{YL}}\left(1\right)$ and ${\mathbf{YL}}\left(2\right)$ will in general be functions of XL and ELAM, and ${\mathbf{YR}}\left(1\right)$ and ${\mathbf{YR}}\left(2\right)$ functions of XR and ELAM, usually derived analytically from a power-series or asymptotic expansion. Examples are given in Sections 8.5 and 9.
The specification of BDYVAL is:
 SUBROUTINE BDYVAL ( XL, XR, ELAM, YL, YR)
 REAL (KIND=nag_wp) XL, XR, ELAM, YL(3), YR(3)
1:     XL – REAL (KIND=nag_wp)Input
On entry: if $a$ is a regular end point of the system (so that $a={x}_{1}={x}_{2}$), then XL contains $a$. If $a$ is a singular point (so that $a\le {x}_{1}<{x}_{2}$), then XL contains a point $x$ such that ${x}_{1}.
2:     XR – REAL (KIND=nag_wp)Input
On entry: if $b$ is a regular end point of the system (so that ${x}_{m-1}={x}_{m}=b$), then XR contains $b$. If $b$ is a singular point (so that ${x}_{m-1}<{x}_{m}\le b$), then XR contains a point $x$ such that ${x}_{m-1}\le x<{x}_{m}$.
3:     ELAM – REAL (KIND=nag_wp)Input
On entry: the current trial value of $\lambda$.
4:     YL($3$) – REAL (KIND=nag_wp) arrayOutput
On exit: ${\mathbf{YL}}\left(1\right)$ and ${\mathbf{YL}}\left(2\right)$ should contain values of $y\left(x\right)$ and $p\left(x\right){y}^{\prime }\left(x\right)$ respectively (not both zero) which are consistent with the boundary condition at the left-hand end point, given by $x={\mathbf{XL}}$. ${\mathbf{YL}}\left(3\right)$ should not be set.
5:     YR($3$) – REAL (KIND=nag_wp) arrayOutput
On exit: ${\mathbf{YR}}\left(1\right)$ and ${\mathbf{YR}}\left(2\right)$ should contain values of $y\left(x\right)$ and $p\left(x\right){y}^{\prime }\left(x\right)$ respectively (not both zero) which are consistent with the boundary condition at the right-hand end point, given by $x={\mathbf{XR}}$. ${\mathbf{YR}}\left(3\right)$ should not be set.
BDYVAL must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which D02KEF is called. Parameters denoted as Input must not be changed by this procedure.
6:     K – INTEGERInput
On entry: $k$, the index of the required eigenvalue when the eigenvalues are ordered
 $λ0 < λ1 < λ2 < ⋯ < λk < ⋯ .$
Constraint: ${\mathbf{K}}\ge 0$.
7:     TOL – REAL (KIND=nag_wp)Input
On entry: the tolerance parameter which determines the accuracy of the computed eigenvalue. The error estimate held in DELAM on exit satisfies the mixed absolute/relative error test
 $DELAM≤TOL×max1.0,ELAM,$ (1)
where ELAM is the final estimate of the eigenvalue. DELAM is usually somewhat smaller than the right-hand side of (1) but not several orders of magnitude smaller.
Constraint: ${\mathbf{TOL}}>0.0$.
8:     ELAM – REAL (KIND=nag_wp)Input/Output
On entry: an initial estimate of the eigenvalue $\stackrel{~}{\lambda }$.
On exit: the final computed estimate, whether or not an error occurred.
9:     DELAM – REAL (KIND=nag_wp)Input/Output
On entry: an indication of the scale of the problem in the $\lambda$-direction. DELAM holds the initial ‘search step’ (positive or negative). Its value is not critical, but the first two trial evaluations are made at ELAM and ${\mathbf{ELAM}}+{\mathbf{DELAM}}$, so the routine will work most efficiently if the eigenvalue lies between these values. A reasonable choice (if a closer bound is not known) is half the distance between adjacent eigenvalues in the neighbourhood of the one sought. In practice, there will often be a problem, similar to the one in hand but with known eigenvalues, which will help one to choose initial values for ELAM and DELAM.
If ${\mathbf{DELAM}}=0.0$ on entry, it is given the default value of $0.25×\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1.0,\left|{\mathbf{ELAM}}\right|\right)$.
On exit: if ${\mathbf{IFAIL}}={\mathbf{0}}$, DELAM holds an estimate of the absolute error in the computed eigenvalue, that is $\left|\stackrel{~}{\lambda }-{\mathbf{ELAM}}\right|\simeq {\mathbf{DELAM}}$. (In Section 8.2 we discuss the assumptions under which this is true.) The true error is rarely more than twice, or less than a tenth, of the estimated error.
If ${\mathbf{IFAIL}}\ne {\mathbf{0}}$, DELAM may hold an estimate of the error, or its initial value, depending on the value of IFAIL. See Section 6 for further details.
10:   HMAX($2$,M) – REAL (KIND=nag_wp) arrayInput/Output
On entry: ${\mathbf{HMAX}}\left(1,\mathit{j}\right)$ should contain a maximum step size to be used by the differential equation code in the $\mathit{j}$th sub-interval ${\mathit{i}}_{\mathit{j}}$ (as described in the specification of parameter XPOINT), for $\mathit{j}=1,2,\dots ,m-3$. If it is zero the routine generates a maximum step size internally.
It is recommended that ${\mathbf{HMAX}}\left(1,j\right)$ be set to zero unless the coefficient functions $p$ and $q$ have features (such as a narrow peak) within the $j$th sub-interval that could be ‘missed’ if a long step were taken. In such a case ${\mathbf{HMAX}}\left(1,j\right)$ should be set to about half the distance over which the feature should be observed. Too small a value will increase the computing time for the routine. See Section 8 for further suggestions.
The rest of the array is used as workspace.
On exit: ${\mathbf{HMAX}}\left(1,m-1\right)$ and ${\mathbf{HMAX}}\left(1,m\right)$ contain the sensitivity coefficients ${\sigma }_{l},{\sigma }_{r}$, described in Section 8.6. Other entries contain diagnostic output in the case of an error exit (see Section 6).
11:   MAXIT – INTEGERInput/Output
On entry: a bound on ${n}_{r}$, the number of root-finding iterations allowed, that is the number of trial values of $\lambda$ that are used. If ${\mathbf{MAXIT}}\le 0$, no such bound is assumed. (See also MAXFUN.)
Suggested value: ${\mathbf{MAXIT}}=0$.
On exit: will have been decreased by the number of iterations actually performed, whether or not it was positive on entry.
12:   MAXFUN – INTEGERInput
On entry: a bound on ${n}_{f}$, the number of calls to COEFFN made in any one root-finding iteration. If ${\mathbf{MAXFUN}}\le 0$, no such bound is assumed.
Suggested value: ${\mathbf{MAXFUN}}=0$.
MAXFUN and MAXIT may be used to limit the computational cost of a call to D02KEF, which is roughly proportional to ${n}_{r}×{n}_{f}$.
13:   MONIT – SUBROUTINE, supplied by the NAG Library or the user.External Procedure
MONIT is called by D02KEF at the end of each root-finding iteration and allows you to monitor the course of the computation by printing out the parameters (see Section 9 for an example).
If no monitoring is required, the dummy (sub)program D02KAY may be used. (D02KAY is included in the NAG Library.)
The specification of MONIT is:
 SUBROUTINE MONIT ( NIT, IFLAG, ELAM, FINFO)
 INTEGER NIT, IFLAG REAL (KIND=nag_wp) ELAM, FINFO(15)
1:     NIT – INTEGERInput
On entry: the current value of the parameter MAXIT of D02KEF, this is decreased by one at each iteration.
2:     IFLAG – INTEGERInput
On entry: describes what phase the computation is in.
${\mathbf{IFLAG}}<0$
An error occurred in the computation at this iteration; an error exit from D02KEF with ${\mathbf{IFAIL}}=-{\mathbf{IFLAG}}$ will follow.
${\mathbf{IFLAG}}=1$
The routine is trying to bracket the eigenvalue $\stackrel{~}{\lambda }$.
${\mathbf{IFLAG}}=2$
The routine is converging to the eigenvalue $\stackrel{~}{\lambda }$ (having already bracketed it).
3:     ELAM – REAL (KIND=nag_wp)Input
On entry: the current trial value of $\lambda$.
4:     FINFO($15$) – REAL (KIND=nag_wp) arrayInput
On entry: information about the behaviour of the shooting method, and diagnostic information in the case of errors. It should not normally be printed in full if no error has occurred (that is, if ${\mathbf{IFLAG}}>0$), though the first few components may be of interest to you. In case of an error (${\mathbf{IFLAG}}<0$) all the components of FINFO should be printed.
The contents of FINFO are as follows:
${\mathbf{FINFO}}\left(1\right)$
The current value of the ‘miss-distance’ or ‘residual’ function $f\left(\lambda \right)$ on which the shooting method is based. (See Section 8.2 for further information.) ${\mathbf{FINFO}}\left(1\right)$ is set to zero if ${\mathbf{IFLAG}}<0$.
${\mathbf{FINFO}}\left(2\right)$
An estimate of the quantity $\partial \lambda$ defined as follows. Consider the perturbation in the miss-distance $f\left(\lambda \right)$ that would result if the local error in the solution of the differential equation were always positive and equal to its maximum permitted value. Then $\partial \lambda$ is the perturbation in $\lambda$ that would have the same effect on $f\left(\lambda \right)$. Thus, at the zero of $f\left(\lambda \right),\left|\partial \lambda \right|$ is an approximate bound on the perturbation of the zero (that is the eigenvalue) caused by errors in numerical solution. If $\partial \lambda$ is very large then it is possible that there has been a programming error in COEFFN such that $q$ is independent of $\lambda$. If this is the case, an error exit with ${\mathbf{IFAIL}}={\mathbf{5}}$ should follow. ${\mathbf{FINFO}}\left(2\right)$ is set to zero if ${\mathbf{IFLAG}}<0$.
${\mathbf{FINFO}}\left(3\right)$
The number of internal iterations, using the same value of $\lambda$ and tighter accuracy tolerances, needed to bring the accuracy (that is, the value of $\partial \lambda$) to an acceptable value. Its value should normally be $1.0$, and should almost never exceed $2.0$.
${\mathbf{FINFO}}\left(4\right)$
The number of calls to COEFFN at this iteration.
${\mathbf{FINFO}}\left(5\right)$
The number of successful steps taken by the internal differential equation solver at this iteration. A step is successful if it is used to advance the integration.
${\mathbf{FINFO}}\left(6\right)$
The number of unsuccessful steps used by the internal integrator at this iteration.
${\mathbf{FINFO}}\left(7\right)$
The number of successful steps at the maximum step size taken by the internal integrator at this iteration.
${\mathbf{FINFO}}\left(8\right)$
Not used.
${\mathbf{FINFO}}\left(9\right)$ to ${\mathbf{FINFO}}\left(15\right)$
Set to zero, unless ${\mathbf{IFLAG}}<0$ in which case they hold the following values describing the point of failure:
${\mathbf{FINFO}}\left(9\right)$
The index of the sub-interval where failure occurred, in the range $1$ to $m-3$. In case of an error in BDYVAL, it is set to $0$ or $m-2$ depending on whether the left or right boundary condition caused the error.
${\mathbf{FINFO}}\left(10\right)$
The value of the independent variable, $x$, the point at which the error occurred. In case of an error in BDYVAL, it is set to the value of XL or XR as appropriate (see the specification of BDYVAL).
${\mathbf{FINFO}}\left(11\right)$, ${\mathbf{FINFO}}\left(12\right)$, ${\mathbf{FINFO}}\left(13\right)$
The current values of the Pruefer dependent variables $\beta$, $\varphi$ and $\rho$ respectively. These are set to zero in case of an error in BDYVAL.
${\mathbf{FINFO}}\left(14\right)$
The local-error tolerance being used by the internal integrator at the point of failure. This is set to zero in the case of an error in BDYVAL.
${\mathbf{FINFO}}\left(15\right)$
The last integration mesh point. This is set to zero in the case of an error in BDYVAL.
MONIT must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which D02KEF is called. Parameters denoted as Input must not be changed by this procedure.
14:   REPORT – SUBROUTINE, supplied by the user.External Procedure
REPORT provides the means by which you may compute the eigenfunction $y\left(x\right)$ and its derivative at each integration mesh point $x$. (See Section 8 for an example.)
The specification of REPORT is:
 SUBROUTINE REPORT ( X, V, JINT)
 INTEGER JINT REAL (KIND=nag_wp) X, V(3)
1:     X – REAL (KIND=nag_wp)Input
On entry: the current value of the independent variable $x$. See Section 8.3 for the order in which values of $x$ are supplied.
2:     V($3$) – REAL (KIND=nag_wp) arrayInput
On entry: ${\mathbf{V}}\left(1\right)$, ${\mathbf{V}}\left(2\right)$, ${\mathbf{V}}\left(3\right)$ hold the current values of the Pruefer variables $\beta$, $\varphi$, $\rho$ respectively.
3:     JINT – INTEGERInput
On entry: indicates the sub-interval between break points in which X lies exactly as for COEFFN, except that at the extreme left-hand end point (when $x={\mathbf{XPOINT}}\left(2\right)$) JINT is set to $0$ and at the extreme right-hand end point (when $x={x}_{r}={\mathbf{XPOINT}}\left(m-1\right)$) JINT is set to $m-2$.
REPORT must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which D02KEF is called. Parameters denoted as Input must not be changed by this procedure.
15:   IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value $-1\text{​ or ​}1$ is recommended. If the output of error messages is undesirable, then the value $1$ is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is $0$. When the value $-\mathbf{1}\text{​ or ​}\mathbf{1}$ is used it is essential to test the value of IFAIL on exit.
On exit: ${\mathbf{IFAIL}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6  Error Indicators and Warnings

If on entry ${\mathbf{IFAIL}}={\mathbf{0}}$ or $-{\mathbf{1}}$, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Errors or warnings detected by the routine:
${\mathbf{IFAIL}}=1$
A parameter error. All parameters (except IFAIL) are left unchanged. The reason for the error is shown by the value of ${\mathbf{HMAX}}\left(2,1\right)$ as follows:
 ${\mathbf{HMAX}}\left(2,1\right)=1$: ${\mathbf{M}}<4$; ${\mathbf{HMAX}}\left(2,1\right)=2$: ${\mathbf{K}}<0$; ${\mathbf{HMAX}}\left(2,1\right)=3$: ${\mathbf{TOL}}\le 0.0$; ${\mathbf{HMAX}}\left(2,1\right)=4$: ${\mathbf{XPOINT}}\left(1\right)$ to ${\mathbf{XPOINT}}\left(m\right)$ are not in ascending order. ${\mathbf{HMAX}}\left(2,2\right)$ gives the position $i$ in XPOINT where this was detected.
${\mathbf{IFAIL}}=2$
At some call to BDYVAL, invalid values were returned, that is, either ${\mathbf{YL}}\left(1\right)={\mathbf{YL}}\left(2\right)=0.0$, or ${\mathbf{YR}}\left(1\right)={\mathbf{YR}}\left(2\right)=0.0$ (a programming error in BDYVAL). See the last call of MONIT for details.
This error exit will also occur if $p\left(x\right)$ is zero at the point where the boundary condition is imposed. Probably BDYVAL was called with XL equal to a singular end point $a$ or with XR equal to a singular end point $b$.
${\mathbf{IFAIL}}=3$
At some point between XL and XR the value of $p\left(x\right)$ computed by COEFFN became zero or changed sign. See the last call of MONIT for details.
${\mathbf{IFAIL}}=4$
${\mathbf{MAXIT}}>0$ on entry, and after MAXIT iterations the eigenvalue had not been found to the required accuracy.
${\mathbf{IFAIL}}=5$
The ‘bracketing’ phase (with parameter IFLAG of the MONIT equal to $1$) failed to bracket the eigenvalue within ten iterations. This is caused by an error in formulating the problem (for example, $q$ is independent of $\lambda$), or by very poor initial estimates of ELAM and DELAM.
On exit, ELAM and ${\mathbf{ELAM}}+{\mathbf{DELAM}}$ give the end points of the interval within which no eigenvalue was located by the routine.
${\mathbf{IFAIL}}=6$
${\mathbf{MAXFUN}}>0$ on entry, and the last iteration was terminated because more than MAXFUN calls to COEFFN were used. See the last call of MONIT for details.
${\mathbf{IFAIL}}=7$
To obtain the desired accuracy the local error tolerance was set so small at the start of some sub-interval that the differential equation solver could not choose an initial step size large enough to make significant progress. See the last call of MONIT for diagnostics.
${\mathbf{IFAIL}}=8$
At some point inside a sub-interval the step size in the differential equation solver was reduced to a value too small to make significant progress (for the same reasons as with ${\mathbf{IFAIL}}={\mathbf{7}}$). This could be due to pathological behaviour of $p\left(x\right)$ and $q\left(x;\lambda \right)$ or to an unreasonable accuracy requirement or to the current value of $\lambda$ making the equations ‘stiff’. See the last call of MONIT for details.
${\mathbf{IFAIL}}=9$
TOL is too small for the problem being solved and the machine precision is being used. The final value of ELAM should be a very good approximation to the eigenvalue.
${\mathbf{IFAIL}}=10$
C05AZF, called by D02KEF, has terminated with the error exit corresponding to a pole of the residual function $f\left(\lambda \right)$. This error exit should not occur, but if it does, try solving the problem again with a smaller value for TOL.
${\mathbf{IFAIL}}=11$
${\mathbf{IFAIL}}=12$
A serious error has occurred in an internal call. Check all (sub)program calls and array dimensions. Seek expert help.
Note: error exits with ${\mathbf{IFAIL}}={\mathbf{2}}$, ${\mathbf{3}}$, ${\mathbf{6}}$, ${\mathbf{7}}$, ${\mathbf{8}}$ or ${\mathbf{11}}$ are caused by being unable to set up or solve the differential equation at some iteration and will be immediately preceded by a call of MONIT giving diagnostic information. For other errors, diagnostic information is contained in ${\mathbf{HMAX}}\left(2,\mathit{j}\right)$, for $\mathit{j}=1,2,\dots ,m$, where appropriate.

## 7  Accuracy

See the discussion in Section 8.2.

### 8.1  Timing

The time taken by D02KEF depends on the complexity of the coefficient functions, whether they or their derivatives are rapidly changing, the tolerance demanded, and how many iterations are needed to obtain convergence. The amount of work per iteration is roughly doubled when TOL is divided by $16$. To make the most economical use of the routine, one should try to obtain good initial values for ELAM and DELAM, and, where appropriate, good asymptotic formulae. Also the boundary matching points should not be set unnecessarily close to singular points. The extra time needed to compute the eigenfunction is principally the cost of one additional integration once the eigenvalue has been found.

### 8.2  General Description of the Algorithm

A shooting method, for differential equation problems containing unknown parameters, relies on the construction of a ‘miss-distance function’, which for given trial values of the parameters measures how far the conditions of the problem are from being met. The problem is then reduced to one of finding the values of the parameters for which the miss-distance function is zero, that is to a root-finding process. Shooting methods differ mainly in how the miss-distance is defined.
D02KEF defines a miss-distance $f\left(\lambda \right)$ based on the rotation about the origin of the point ${\mathbf{P}}\left(x\right)=\left(p\left(x\right){y}^{\prime }\left(x\right),y\left(x\right)\right)$ in the Phase Plane as the solution proceeds from $a$ to $b$. The boundary conditions define the ray (i.e., two-sided line through the origin) on which $p\left(x\right)$ should start, and the ray on which it should finish. The eigenvalue $k$ defines the total number of half-turns it should make. Numerical solution is actually done by ‘shooting forward’ from $x=a$ and ‘shooting backward’ from $x=b$ to a matching point $x=c$. Then $f\left(\lambda \right)$ is taken as the angle between the rays to the two resulting points ${P}_{a}\left(c\right)$ and ${P}_{b}\left(c\right)$. A relative scaling of the $p{y}^{\prime }$ and $y$ axes, based on the behaviour of the coefficient functions $p$ and $q$, is used to improve the numerical behaviour.
Figure 1
The resulting function $f\left(\lambda \right)$ is monotonic over $-\infty <\lambda <\infty$, increasing if $\frac{\partial q}{\partial \lambda }>0$ and decreasing if $\frac{\partial q}{\partial \lambda }<0$, with a unique zero at the desired eigenvalue $\stackrel{~}{\lambda }$. The routine measures $f\left(\lambda \right)$ in units of a half-turn. This means that as $\lambda$ increases, $f\left(\lambda \right)$ varies by about $1$ as each eigenvalue is passed. (This feature implies that the values of $f\left(\lambda \right)$ at successive iterations – especially in the early stages of the iterative process – can be used with suitable extrapolation or interpolation to help the choice of initial estimates for eigenvalues near to the one currently being found.)
The routine actually computes a value for $f\left(\lambda \right)$ with errors, arising from the local errors of the differential equation code and from the asymptotic formulae provided by you if singular points are involved. However, the error estimate output in DELAM is usually fairly realistic, in that the actual error $\left|\stackrel{~}{\lambda }-{\mathbf{ELAM}}\right|$ is within an order of magnitude of DELAM.
We pass the values of $\beta$, $\varphi$, $\rho$ across through REPORT rather than converting them to values of $y$, ${y}^{\prime }$ inside D02KEF, for the following reasons. First, there may be cases where auxiliary quantities can be more accurately computed from the Pruefer variables than from $y$ and ${y}^{\prime }$. Second, in singular problems on an infinite interval $y$ and ${y}^{\prime }$ may underflow towards the end of the range, whereas the Pruefer variables remain well-behaved. Third, with high-order eigenvalues (and therefore highly oscillatory eigenfunctions) the eigenfunction may have a complete oscillation (or more than one oscillation) between two mesh points, so that values of $y$ and ${y}^{\prime }$ at mesh points give a very poor representation of the curve. The probable behaviour of the Pruefer variables in this case is that $\beta$ and $\rho$ vary slowly whilst $\varphi$ increases quickly: for all three Pruefer variables linear interpolation between the values at adjacent mesh points is probably sufficiently accurate to yield acceptable intermediate values of $\beta$, $\varphi$, $\rho$ (and hence of $y,{y}^{\prime }$) for graphical purposes.
Similar considerations apply to the exponentially decaying ‘tails’ of the eigenfunctions that often occur in singular problems. Here $\varphi$ has approximately constant value whilst $\rho$ increases rapidly in the direction of integration, though the step length is generally fairly small over such a range.
If the solution is output through REPORT at $x$ values which are too widely spaced, the step length can be controlled by choosing HMAX suitably, or, preferably, by reducing TOL. Both these choices will lead to more accurate eigenvalues and eigenfunctions but at some computational cost.

### 8.3  The Position of the Shooting Matching Point $c$

This point is always one of the values ${x}_{i}$ in array XPOINT. It may be specified using the parameter MATCH. The default value is chosen to be the value of that ${x}_{i}$, $2\le i\le m-1$, that lies closest to the middle of the interval $\left[{x}_{2},{x}_{m-1}\right]$. If there is a tie, the rightmost candidate is chosen. In particular if there are no break points, then $c={x}_{m-1}$ ($\text{}={x}_{3}$); that is, the shooting is from left to right in this case. A break point may be inserted purely to move $c$ to an interior point of the interval, even though the form of the equations does not require it. This often speeds up convergence especially with singular problems.
Note that the shooting method used by the code integrates first from the left-hand end ${x}_{l}$, then from the right-hand end ${x}_{r}$, to meet at the matching point $c$ in the middle. This will of course be reflected in printed or graphical output. The diagram shows a possible sequence of nine mesh points ${\tau }_{1}$ through ${\tau }_{9}$ in the order in which they appear, assuming there are just two sub-intervals (so $m=5$).
Figure 2
Since the shooting method usually fails to match up the two ‘legs’ of the curve exactly, there is bound to be a jump in $y$, or in $p\left(x\right){y}^{\prime }$ or both, at the matching point $c$. The code in fact ‘shares’ the discrepancy out so that both $y$ and $p\left(x\right){y}^{\prime }$ have a jump. A large jump does not imply an inaccurate eigenvalue, but implies either
 (a) a badly chosen matching point: if $q\left(x;\lambda \right)$ has a ‘humped’ shape, $c$ should be chosen near the maximum value of $q$, especially if $q$ is negative at the ends of the interval; (b) an inherently ill-conditioned problem, typically one where another eigenvalue is pathologically close to the one being sought. In this case it is extremely difficult to obtain an accurate eigenfunction.
In Section 9, we find the 11th eigenvalue and corresponding eigenfunction of the equation
 $y′′+λ-x-2/x2y=0 on 0
the boundary conditions being that $y$ should remain bounded as $x$ tends to $0$ and $x$ tends to $\infty$. The coding of this problem is discussed in detail in Section 8.5.
The choice of matching point $c$ is open. If we choose $c=30.0$ as in D02KDF example program we find that the exponentially increasing component of the solution dominates and we get extremely inaccurate values for the eigenfunction (though the eigenvalue is determined accurately). The values of the eigenfunction calculated with $c=30.0$ are given schematically in Figure 3.
Figure 3
If we choose $c$ as the maximum of the hump in $q\left(x;\lambda \right)$ (see item (a) above) we instead obtain the accurate results given in Figure 4
Figure 4

### 8.4  Examples of Coding the COEFFN

Coding COEFFN is straightforward except when break points are needed. The examples below show:
 (a) a simple case, (b) a case in which discontinuities in the coefficient functions or their derivatives necessitate break points, and (c) a case where break points together with the HMAX parameter are an efficient way to deal with a coefficient function that is well-behaved except over one short interval.
(Some of these cases are among the examples in Section 9.)
Example A
The modified Bessel equation
 $x xy′ ′ + λx2-ν2 y=0 .$
Assuming the interval of solution does not contain the origin and dividing through by $x$, we have $p\left(x\right)=x$ and $q\left(x;\lambda \right)=\lambda x-{\nu }^{2}/x$. The code could be
```SUBROUTINE COEFFN (P,Q,DQDL,X,ELAM,JINT)
...
P = X
Q = ELAM*X - NU*NU/X
DQDL = X
RETURN
END
```
where NU (standing for $\nu$) is a real variable that might be defined in a DATA statement, or might be in user-declared COMMON so that its value could be set in the main program.
Example B
The Schroedinger equation
 $y′′+λ+qxy=0,$
where
 $qx = x2- 10 x≤ 4, 6x x> 4,$
over some interval ‘approximating to $\left(-\infty ,\infty \right)$’, say $\left[-20,20\right]$. Here we need break points at $±4$, forming three sub-intervals ${i}_{1}=\left[-20,-4\right]$, ${i}_{2}=\left[-4,4\right]$, ${i}_{3}=\left[4,20\right]$. The code could be
```SUBROUTINE COEFFN(P,Q,DQDL,X,ELAM,JINT)
...
IF (JINT.EQ.2) THEN
Q = ELAM + X*X - 10.0E0
ELSE
Q = ELAM + 6.0E0/ABS(X)
ENDIF
P = 1.0E0
DQDL = 1.0E0
RETURN
END
```
The array XPOINT would contain the values ${x}_{1}$, $-20.0$, $-4.0$, $+4.0$, $+20.0$, ${x}_{6}$ and $m$ would be $6$. The choice of appropriate values for ${x}_{1}$ and ${x}_{6}$ depends on the form of the asymptotic formula computed by BDYVAL and the technique is discussed in Section 8.5.
Example C
 $y′′+λ1-2⁢e-100⁢x2y=0, -10≤x≤10.$
Here $q\left(x;\lambda \right)$ is nearly constant over the range except for a sharp inverted spike over approximately $-0.1\le x\le 0.1$. There is a danger that the routine will build up to a large step size and ‘step over’ the spike without noticing it. By using break points – say at $±0.5$ – one can restrict the step size near the spike without impairing the efficiency elsewhere.
The code for COEFFN could be
```SUBROUTINE COEFFN(P,Q,DQDL,X,ELAM,JINT)
...
P = 1.0E0
DQDL = 1.0E0 - 2.0E0*EXP(-100.0E0*X*X)
Q = ELAM*DQDL
RETURN
END
```
XPOINT might contain $-10.0$, $-10.0$, $-0.5$, $0.5$, $10.0$, $10.0$ (assuming $±10$ are regular points) and $m$ would be $6$. ${\mathbf{HMAX}}\left(1,\mathit{j}\right)$, for $\mathit{j}=1,2,3$, might contain $0.0$, $0.1$ and $0.0$.

### 8.5  Examples of Boundary Conditions at Singular Points

Quoting from page 243 of Bailey (1966): ‘Usually ... the differential equation has two essentially different types of solution near a singular point, and the boundary condition there merely serves to distinguish one kind from the other. This is the case in all the standard examples of mathematical physics.’
In most cases the behaviour of the ratio $p\left(x\right){y}^{\prime }/y$ near the point is quite different for the two types of solution. Essentially what you provide through the BDYVAL is an approximation to this ratio, valid as $x$ tends to the singular point (SP).
You must decide (a) how accurate to make this approximation or asymptotic formula, for example how many terms of a series to use, and (b) where to place the boundary matching point (BMP) at which the numerical solution of the differential equation takes over from the asymptotic formula. Taking the BMP closer to the SP will generally improve the accuracy of the asymptotic formula, but will make the computation more expensive as the Pruefer differential equations generally become progressively more ill-behaved as the SP is approached. You are strongly recommended to experiment with placing the BMPs. In many singular problems quite crude asymptotic formulae will do. To help you avoid needlessly accurate formulae, D02KEF outputs two ‘sensitivity coefficients’ ${\sigma }_{l},{\sigma }_{r}$ which estimate how much the errors at the BMPs affect the computed eigenvalue. They are described in detail in Section 8.6.
Example of coding BDYVAL:
The example below illustrates typical situations:
 $y′′+λ-x-2x2 y=0, 0
the boundary conditions being that $y$ should remain bounded as $x$ tends to $0$ and $x$ tends to $\infty$.
At the end $x=0$ there is one solution that behaves like ${x}^{2}$ and another that behaves like ${x}^{-1}$. For the first of these solutions $p\left(x\right){y}^{\prime }/y$ is asymptotically $2/x$ while for the second it is asymptotically $-1/x$. Thus the desired ratio is specified by setting
 $YL1=x and YL2=2.0.$
At the end $x=\infty$ the equation behaves like Airy's equation shifted through $\lambda$, i.e., like ${y}^{\prime \prime }-ty=0$ where $t=x-\lambda$, so again there are two types of solution. The solution we require behaves as
 $exp-23t32/t4$
and the other as
 $exp+23t32/t4.$
Hence, the desired solution has $p\left(x\right){y}^{\prime }/y\sim -\sqrt{t}$ so that we could set ${\mathbf{YR}}\left(1\right)=1.0$ and ${\mathbf{YR}}\left(2\right)=-\sqrt{x-\lambda }$. The complete subroutine might thus be
```SUBROUTINE BDYVAL (XL,XR,ELAM,YL,YR)
real XL, XR, ELAM, YL(3), YR(3)
YL(1) = XL
YL(2) = 2.0E0
YR(1) = 1.0E0
YR(2) = -SQRT(XR-ELAM)
RETURN
END
```
Clearly for this problem it is essential that any value given by D02KEF to XR is well to the right of the value of ELAM, so that you must vary the right-hand BMP with the eigenvalue index $k$. One would expect ${\lambda }_{k}$ to be near the $k$th zero of the Airy function $\mathrm{Ai}\left(x\right)$, so there is no problem estimating ELAM.
More accurate asymptotic formulae are easily found: near $x=0$ by the standard Frobenius method, and near $x=\infty$ by using standard asymptotics for $\mathrm{Ai}\left(x\right)$, ${\mathrm{Ai}}^{\prime }\left(x\right)$, (see page 448 of Abramowitz and Stegun (1972)).
For example, by the Frobenius method the solution near $x=0$ has the expansion
 $y=x2c0+c1x+c2x2+⋯$
with
 $c0= 1,c1= 0, c2=-λ10, c3=118,⋯, cn=cn- 3-λ cn- 2 nn+ 3 .$
This yields
 $pxy′y=2-25λx2+⋯ x 1-λ10x2+⋯ .$

### 8.6  The Sensitivity Parameters ${\sigma }_{l}$ and ${\sigma }_{r}$

The sensitivity parameters ${\sigma }_{l}$, ${\sigma }_{r}$ (held in ${\mathbf{HMAX}}\left(1,m-1\right)$ and ${\mathbf{HMAX}}\left(1,m\right)$ on output) estimate the effect of errors in the boundary conditions. For sufficiently small errors $\Delta y$, $\Delta p{y}^{\prime }$ in $y$ and $p{y}^{\prime }$ respectively, the relations
 $Δλ≃y.Δpy′-py′.Δylσl Δλ≃y.Δpy′-py′.Δyrσr$
are satisfied, where the subscripts $l$, $r$ denote errors committed at the left- and right-hand BMPs respectively, and $\Delta \lambda$ denotes the consequent error in the computed eigenvalue.

### 8.7  ‘Missed Zeros’

This is a pitfall to beware of at a singular point. If the BMP is chosen so far from the SP that a zero of the desired eigenfunction lies in between them, then the routine will fail to ‘notice’ this zero. Since the index of $k$ of an eigenvalue is the number of zeros of its eigenfunction, the result will be that
 (a) the wrong eigenvalue will be computed for the given index $k$ – in fact some ${\lambda }_{k+{k}^{\prime }}$ will be found where ${k}^{\prime }\ge 1$; (b) the same index $k$ can cause convergence to any of several eigenvalues depending on the initial values of ELAM and DELAM.
It is up to you to take suitable precautions – for instance by varying the position of the BMPs in the light of knowledge of the asymptotic behaviour of the eigenfunction at different eigenvalues.

## 9  Example

This example finds the 11th eigenvalue and eigenfunction of the example of Section 8.5, using the simple asymptotic formulae for the boundary conditions.
Comparison of the results from this example program with the corresponding results from D02KDF example program shows that similar output is produced from MONIT, followed by the eigenfunction values from REPORT, and then a further line of information from MONIT (corresponding to the integration to find the eigenfunction). Final information is printed within the example program exactly as with D02KDF.
Note the discrepancy at the matching point $c$ ($\text{}=\sqrt[3]{4}$, the maximum of $q\left(x;\lambda \right)$, in this case) between the solutions obtained by integrations from left- and right-hand end points.

### 9.1  Program Text

Program Text (d02kefe.f90)

### 9.2  Program Data

Program Data (d02kefe.d)

### 9.3  Program Results

Program Results (d02kefe.r)