D02KDF 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. Provision is made for discontinuities in the coefficient functions or their derivatives.
D02KDF finds a specified eigenvalue of a Sturm–Liouville system defined by a self-adjoint differential equation of the second-order
together with appropriate boundary conditions at the two, finite or infinite, end points and . The functions and , which are real-valued, are defined by COEFFN. The boundary conditions must be defined by BDYVAL, and, in the case of a singularity at or , take the form of an asymptotic formula for the solution near the relevant end point.
For the theoretical basis of the numerical method to be valid, the following conditions should hold on the coefficient functions:
must be nonzero and must not change sign throughout the interval ; and,
must not change sign throughout the interval for all relevant values of , and must not be identically zero as varies, for any .
Points of discontinuity in the functions and or their derivatives are allowed, and should be included as ‘break points’ in the array XPOINT.
The eigenvalue is determined by a shooting method based on the Scaled Pruefer form of the differential equation as described in Pryce (1981), with certain modifications. The Pruefer equations are integrated by a special internal routine using Merson's Runge–Kutta formula with automatic control of local error. Providing certain assumptions (see Section 8.1) are met, the computed value of will be correct to within a mixed absolute/relative error specified by TOL.
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).
On entry: the points where the boundary conditions computed by BDYVAL are to be imposed, and also any break points, i.e., to must contain values such that
with the following meanings:
and are the left- and right-hand end points, and , of the domain of definition of the Sturm–Liouville system if these are finite. If either or is infinite, the corresponding value or may be a more-or-less arbitrarily ‘large’ number of appropriate sign.
and 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 , while if it is a singular point you must set . Similarly () if the right-hand end point is regular, and if it is singular.
The remaining points , if any, define ‘break points’ which divide the interval into sub-intervals
Numerical integration of the differential equation is stopped and restarted at each break point. In simple cases no break points are needed. However, if or 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 or , or in their derivatives up to the fifth-order, should appear as break points.
On exit: the value of for the current value of and the current trial value of .
3: DQDL – REAL (KIND=nag_wp)Output
On exit: the value of for the current value of and the current trial value of . 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 ) will suffice.
4: X – REAL (KIND=nag_wp)Input
On entry: the current value of .
5: ELAM – REAL (KIND=nag_wp)Input
On entry: the current trial value of the eigenvalue parameter .
6: JINT – INTEGERInput
On entry: the index of the sub-interval (see specification of XPOINT) in which lies.
COEFFN must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which D02KDF is called. Parameters denoted as Input must not be changed by this procedure.
4: 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 and which are consistent with the boundary conditions at the end points; only the ratio of the values matters. Here is a given point (XL or XR) equal to, or close to, the end point.
For a regular end point (, say), , a boundary condition of the form
can be handled by returning constant values in YL, e.g., and .
For a singular end point however, and will in general be functions of XL and ELAM, and and functions of XR and ELAM, usually derived analytically from a power-series or asymptotic expansion. Examples are given in Sections 8.5 and 9.
On entry: if is a regular end point of the system (so that ), then XL contains . If is a singular point (so that ), then XL contains a point such that .
2: XR – REAL (KIND=nag_wp)Input
On entry: if is a regular end point of the system (so that ), then XR contains . If is a singular point (so that ), then XR contains a point such that .
3: ELAM – REAL (KIND=nag_wp)Input
On entry: the current trial value of .
4: YL() – REAL (KIND=nag_wp) arrayOutput
On exit: and should contain values of and respectively (not both zero) which are consistent with the boundary condition at the left-hand end point, given by . should not be set.
5: YR() – REAL (KIND=nag_wp) arrayOutput
On exit: and should contain values of and respectively (not both zero) which are consistent with the boundary condition at the right-hand end point, given by . should not be set.
BDYVAL must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which D02KDF is called. Parameters denoted as Input must not be changed by this procedure.
5: K – INTEGERInput
On entry: , the index of the required eigenvalue when the eigenvalues are ordered
6: 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
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.
7: ELAM – REAL (KIND=nag_wp)Input/Output
On entry: an initial estimate of the eigenvalue .
On exit: the final computed estimate, whether or not an error occurred.
8: DELAM – REAL (KIND=nag_wp)Input/Output
On entry: an indication of the scale of the problem in the -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 , 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 on entry, it is given the default value of .
On exit: if , DELAM holds an estimate of the absolute error in the computed eigenvalue, that is . (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 , DELAM may hold an estimate of the error, or its initial value, depending on the value of IFAIL. See Section 6 for further details.
9: HMAX(,M) – REAL (KIND=nag_wp) arrayInput/Output
On entry: should contain a maximum step size to be used by the differential equation code in the th sub-interval (as described in the specification of parameter XPOINT), for . If it is zero the routine generates a maximum step size internally.
It is recommended that be set to zero unless the coefficient functions and have features (such as a narrow peak) within the th sub-interval that could be ‘missed’ if a long step were taken. In such a case 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: and contain the sensitivity coefficients , described in Section 8.6. Other entries contain diagnostic output in the case of an error exit (see Section 6).
10: MAXIT – INTEGERInput/Output
On entry: a bound on , the number of root-finding iterations allowed, that is the number of trial values of that are used. If , no such bound is assumed. (See also MAXFUN.)
On exit: will have been decreased by the number of iterations actually performed, whether or not it was positive on entry.
11: MAXFUN – INTEGERInput
On entry: a bound on , the number of calls to COEFFN made in any one root-finding iteration. If , no such bound is assumed.
MAXFUN and MAXIT may be used to limit the computational cost of a call to D02KDF, which is roughly proportional to .
12: MONIT – SUBROUTINE, supplied by the NAG Library or the user.External Procedure
MONIT is called by D02KDF 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.)
On entry: the current value of the parameter MAXIT of D02KDF, this is decreased by one at each iteration.
2: IFLAG – INTEGERInput
On entry: describes what phase the computation is in.
An error occurred in the computation at this iteration; an error exit from D02KDF with will follow.
The routine is trying to bracket the eigenvalue .
The routine is converging to the eigenvalue (having already bracketed it).
3: ELAM – REAL (KIND=nag_wp)Input
On entry: the current trial value of .
4: FINFO() – 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 ), though the first few components may be of interest to you. In case of an error () all the components of FINFO should be printed.
The current value of the ‘miss-distance’ or ‘residual’ function on which the shooting method is based. (See Section 8.2 for further information.) is set to zero if .
An estimate of the quantity defined as follows. Consider the perturbation in the miss-distance 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 is the perturbation in that would have the same effect on . Thus, at the zero of is an approximate bound on the perturbation of the zero (that is the eigenvalue) caused by errors in numerical solution. If is very large then it is possible that there has been a programming error in COEFFN such that is independent of . If this is the case, an error exit with should follow. is set to zero if .
The number of internal iterations, using the same value of and tighter accuracy tolerances, needed to bring the accuracy (that is, the value of ) to an acceptable value. Its value should normally be , and should almost never exceed .
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.
The number of unsuccessful steps used by the internal integrator at this iteration.
The number of successful steps at the maximum step size taken by the internal integrator at this iteration.
Set to zero, unless in which case they hold the following values describing the point of failure:
The index of the sub-interval where failure occurred, in the range to . In case of an error in BDYVAL, it is set to or depending on whether the left or right boundary condition caused the error.
The value of the independent variable, , 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).
The current values of the Pruefer dependent variables , and respectively. These are set to zero in case of an error in BDYVAL. (See D02KEF for a description of these variables.)
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.
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 D02KDF is called. Parameters denoted as Input must not be changed by this procedure.
13: IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to , . 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 is recommended. If the output of error messages is undesirable, then the value is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is . When the value is used it is essential to test the value of IFAIL on exit.
On exit: unless the routine detects an error or a warning has been flagged (see Section 6).
6 Error Indicators and Warnings
If on entry or , explanatory error messages are output on the current error message unit (as defined by X04AAF).
Errors or warnings detected by the routine:
A parameter error. All parameters (except IFAIL) are left unchanged. The reason for the error is shown by the value of as follows:
to are not in ascending order. gives the position in XPOINT where this was detected.
At some call to BDYVAL, invalid values were returned, that is, either , or (a programming error in BDYVAL). See the last call of MONIT for details.
This error exit will also occur if is zero at the point where the boundary condition is imposed. Probably BDYVAL was called with XL equal to a singular end point or with XR equal to a singular end point .
At some point between XL and XR the value of computed by COEFFN became zero or changed sign. See the last call of MONIT for details.
on entry, and after MAXIT iterations the eigenvalue had not been found to the required accuracy.
The ‘bracketing’ phase (with parameter IFLAG of the MONIT equal to ) failed to bracket the eigenvalue within ten iterations. This is caused by an error in formulating the problem (for example, is independent of ), or by very poor initial estimates of ELAM and DELAM.
On exit, ELAM and give the end points of the interval within which no eigenvalue was located by the routine.
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.
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.
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 ). This could be due to pathological behaviour of and or to an unreasonable accuracy requirement or to the current value of making the equations ‘stiff’. See the last call of MONIT for details.
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.
C05AZF, called by D02KDF, has terminated with the error exit corresponding to a pole of the residual function . This error exit should not occur, but if it does, try solving the problem again with a smaller value for TOL.
A serious error has occurred in an internal call. Check all (sub)program calls and array dimensions. Seek expert help.
Note: error exits with , , , , or 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
, for , where appropriate.
The time taken by D02KDF 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 . 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.
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.
D02KDF defines a miss-distance based on the rotation about the origin of the point in the Phase Plane as the solution proceeds from to . The boundary conditions define the ray (i.e., two-sided line through the origin) on which should start, and the ray on which it should finish. The eigenvalue defines the total number of half-turns it should make. Numerical solution is actually done by ‘shooting forward’ from and ‘shooting backward’ from to a matching point . Then is taken as the angle between the rays to the two resulting points and . A relative scaling of the and axes, based on the behaviour of the coefficient functions and , is used to improve the numerical behaviour.
The resulting function is monotonic over , increasing if and decreasing if , with a unique zero at the desired eigenvalue . The routine measures in units of a half-turn. This means that as increases, varies by about as each eigenvalue is passed. (This feature implies that the values of 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 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 is within an order of magnitude of DELAM.
8.3 The Position of the Shooting Matching Point
This point is always one of the values in array XPOINT. It is chosen to be the value of that , , that lies closest to the middle of the interval . If there is a tie, the rightmost candidate is chosen. In particular if there are no break points, then (); that is, the shooting is from left to right in this case. A break point may be inserted purely to move 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.
Coding COEFFN is straightforward except when break points are needed. The examples below show:
a simple case,
a case in which discontinuities in the coefficient functions or their derivatives necessitate break points, and
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.)
The modified Bessel equation
Assuming the interval of solution does not contain the origin and dividing through by , we have and . The code could be
SUBROUTINE COEFFN (P,Q,DQDL,X,ELAM,JINT)
P = X
Q = ELAM*X - NU*NU/X
DQDL = X
NU (standing for ) 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.
The Schroedinger equation
over some interval ‘approximating to ’, say . Here we need break points at , forming three sub-intervals , , . The code could be
IF (JINT.EQ.2) THEN
Q = ELAM + X*X - 10.0E0
Q = ELAM + 6.0E0/ABS(X)
P = 1.0E0
DQDL = 1.0E0
The array XPOINT would contain the values , , , , , and would be . The choice of appropriate values for and depends on the form of the asymptotic formula computed by BDYVAL and the technique is discussed in Section 8.5.
Here is nearly constant over the range except for a sharp inverted spike over approximately . 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 – one can restrict the step size near the spike without impairing the efficiency elsewhere.
P = 1.0E0
DQDL = 1.0E0 - 2.0E0*EXP(-100.0E0*X*X)
Q = ELAM*DQDL
XPOINT might contain , , , , , (assuming are regular points) and would be . , for , might contain , and .
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 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 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, D02KDF outputs two ‘sensitivity coefficients’
which estimate how much the errors at the BMPs affect the computed eigenvalue. They are described in detail in Section 8.6.
the boundary conditions being that should remain bounded as tends to and tends to .
At the end there is one solution that behaves like and another that behaves like . For the first of these solutions is asymptotically while for the second it is asymptotically . Thus the desired ratio is specified by setting
At the end the equation behaves like Airy's equation shifted through , i.e., like where , so again there are two types of solution. The solution we require behaves as
and the other as
Hence, the desired solution has so that we could set and . The complete subroutine might thus be
Clearly for this problem it is essential that any value given by D02KDF 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 . One would expect to be near the th zero of the Airy function , so there is no problem estimating ELAM.
More accurate asymptotic formulae are easily found: near by the standard Frobenius method, and near by using standard asymptotics for , , (see page 448 of Abramowitz and Stegun (1972)).
For example, by the Frobenius method the solution near has the expansion
8.6 The Sensitivity Parameters and
The sensitivity parameters , (held in and on output) estimate the effect of errors in the boundary conditions. For sufficiently small errors , in and respectively, the relations
are satisfied, where the subscripts , denote errors committed at the left- and right-hand BMPs respectively, and 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 of an eigenvalue is the number of zeros of its eigenfunction, the result will be that
the wrong eigenvalue will be computed for the given index – in fact some will be found where ;
the same index 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.
This example finds the 11th eigenvalue of the example of Section 8.5, using the simple asymptotic formulae for the boundary conditions. The results exhibit slow convergence, mainly because XPOINT is set so that the shooting matching point is at the right-hand end . The example results for D02KEF show that much faster convergence is obtained if XPOINT is set to contain an additional break point at or near the maximum of the coefficient function , which in this case is at .