NAG FL Interface
d02kaf (sl2_reg_finite)
1
Purpose
d02kaf finds a specified eigenvalue of a regular second-order Sturm–Liouville system defined on a finite range, using a Pruefer transformation and a shooting method.
2
Specification
Fortran Interface
Integer, Intent (In) |
:: |
k |
Integer, Intent (Inout) |
:: |
ifail |
Real (Kind=nag_wp), Intent (In) |
:: |
xl, xr, tol |
Real (Kind=nag_wp), Intent (Inout) |
:: |
bcond(3,2), elam, delam |
External |
:: |
coeffn, monit |
|
C Header Interface
#include <nag.h>
void |
d02kaf_ (const double *xl, const double *xr, void (NAG_CALL *coeffn)(double *p, double *q, double *dqdl, const double *x, const double *elam, const Integer *jint), double bcond[], const Integer *k, const double *tol, double *elam, double *delam, void (NAG_CALL *monit)(const Integer *nit, const Integer *iflag, const double *elam, const double finfo[]), Integer *ifail) |
|
C++ Header Interface
#include <nag.h> extern "C" {
void |
d02kaf_ (const double &xl, const double &xr, void (NAG_CALL *coeffn)(double &p, double &q, double &dqdl, const double &x, const double &elam, const Integer &jint), double bcond[], const Integer &k, const double &tol, double &elam, double &delam, void (NAG_CALL *monit)(const Integer &nit, const Integer &iflag, const double &elam, const double finfo[]), Integer &ifail) |
}
|
The routine may be called by the names d02kaf or nagf_ode_sl2_reg_finite.
3
Description
d02kaf finds a specified eigenvalue
of a Sturm–Liouville system defined by a self-adjoint differential equation of the second-order
together with boundary conditions of the form
at the two, finite, end points
and
. The functions
and
, which are real-valued, are defined by
coeffn.
For the theoretical basis of the numerical method to be valid, the following conditions should hold on the coefficient functions:
-
(a) must be nonzero and must not change sign throughout the closed interval ;
-
(b) must not change sign and must be nonzero throughout the open interval and for all relevant values of , and must not be identically zero as varies, for any relevant value ; and,
-
(c) and should (as functions of ) have continuous derivatives, preferably up to the fourth-order, on . The differential equation code used will integrate through mild discontinuities, but probably with severely reduced efficiency. Therefore, if and violate this condition, d02kdf should be used.
The eigenvalue
is determined by a shooting method based on a Pruefer transformation of the differential equations. Providing certain assumptions are met, the computed value of
will be correct to within a mixed absolute/relative error specified by
tol.
d02kaf is a driver routine for the more complicated routine
d02kdf whose specification provides more details of the techniques used.
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).
4
References
Bailey P B (1966) Sturm–Liouville eigenvalues via a phase function SIAM J. Appl. Math. 14 242–249
Birkhoff G and Rota G C (1962) Ordinary Differential Equations Ginn & Co., Boston and New York
5
Arguments
-
1:
– Real (Kind=nag_wp)
Input
-
2:
– Real (Kind=nag_wp)
Input
-
On entry: the left- and right-hand end points and respectively, of the interval of definition of the problem.
Constraint:
.
-
3:
– Subroutine, supplied by the user.
External Procedure
-
coeffn must compute the values of the coefficient functions
and
for given values of
and
.
Section 3 states the conditions which
and
must satisfy.
The specification of
coeffn is:
Fortran Interface
Integer, Intent (In) |
:: |
jint |
Real (Kind=nag_wp), Intent (In) |
:: |
x, elam |
Real (Kind=nag_wp), Intent (Out) |
:: |
p, q, dqdl |
|
C Header Interface
void |
coeffn_ (double *p, double *q, double *dqdl, const double *x, const double *elam, const Integer *jint) |
|
C++ Header Interface
#include <nag.h> extern "C" {
void |
coeffn_ (double &p, double &q, double &dqdl, const double &x, const double &elam, const Integer &jint) |
}
|
-
1:
– Real (Kind=nag_wp)
Output
-
On exit: the value of for the current value of .
-
2:
– Real (Kind=nag_wp)
Output
-
On exit: the value of for the current value of and the current trial value of .
-
3:
– 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:
– Real (Kind=nag_wp)
Input
-
On entry: the current value of .
-
5:
– Real (Kind=nag_wp)
Input
-
On entry: the current trial value of the eigenvalue argument .
-
6:
– Integer
Input
-
This argument is included for compatibility with the more complex routine
d02kdf (which is called by
d02kaf).
On entry: need not be set.
coeffn must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which
d02kaf is called. Arguments denoted as
Input must
not be changed by this procedure.
Note: coeffn should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by
d02kaf. If your code inadvertently
does return any NaNs or infinities,
d02kaf is likely to produce unexpected results.
-
4:
– Real (Kind=nag_wp) array
Input/Output
-
On entry:
and
must contain the numbers
,
specifying the left-hand boundary condition in the form
where
.
and
must contain
,
such that
where
.
Note the occurrence of , in these formulae.
On exit:
and
hold values
estimating the sensitivity of the computed eigenvalue to changes in the boundary conditions. These values should only be of interest if the boundary conditions are, in some sense, an approximation to some ‘true’ boundary conditions. For example, if the range [
xl,
xr] should really be
but instead
xr has been given a large value and the boundary conditions at infinity applied at
xr, the sensitivity argument
may be of interest. Refer to
Section 9.5 in
d02kdf, for the actual meaning of
and
.
-
5:
– Integer
Input
-
On entry:
, the index of the required eigenvalue when the eigenvalues are ordered
Constraint:
.
-
6:
– Real (Kind=nag_wp)
Input
-
On entry: the tolerance argument 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.
Constraint:
.
-
7:
– 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:
– 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 about 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
, where
is the true eigenvalue.
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:
– Subroutine, supplied by the NAG Library or the user.
External Procedure
-
monit is called by
d02kaf at the end of each iteration for
and allows you to monitor the course of the computation by printing out the arguments (see
Section 10 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:
Fortran Interface
Integer, Intent (In) |
:: |
nit, iflag |
Real (Kind=nag_wp), Intent (In) |
:: |
elam, finfo(15) |
|
C Header Interface
void |
monit_ (const Integer *nit, const Integer *iflag, const double *elam, const double finfo[]) |
|
C++ Header Interface
#include <nag.h> extern "C" {
void |
monit_ (const Integer &nit, const Integer &iflag, const double &elam, const double finfo[]) |
}
|
-
1:
– Integer
Input
-
On entry: 15 minus the number of iterations used so far in the search for . (Up to iterations are permitted.)
-
2:
– Integer
Input
-
On entry: describes what phase the computation is in.
- An error occurred in the computation at this iteration; an error exit from d02kaf will follow.
- The routine is trying to bracket the eigenvalue .
- The routine is converging to the eigenvalue (having already bracketed it).
Normally, the iteration will terminate after a sequence of iterates with , but occasionally the bracket on thus determined will not be sufficiently small and the iteration will be repeated with tighter accuracy control.
-
3:
– Real (Kind=nag_wp)
Input
-
On entry: the current trial value of .
-
4:
– Real (Kind=nag_wp) array
Input
-
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 contents of
finfo are as follows:
- The current value of the ‘miss-distance’ or ‘residual’ function on which the shooting method is based. in theory. This 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 calls to coeffn at this iteration.
- 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.
- Not used.
- to
- Set to zero, unless in which case they hold the following values describing the point of failure:
- 1 or depending on whether integration was in a forward or backward direction at the time of failure.
- The value of the independent variable, , the point at which the error occurred.
- , ,
- The current values of the Pruefer dependent variables , and respectively. See Section 3 in d02kef for a description of these variables.
- The local-error tolerance being used by the internal integrator at the point of failure.
- The last integration mesh point.
monit must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which
d02kaf is called. Arguments denoted as
Input must
not be changed by this procedure.
-
10:
– Integer
Input/Output
-
On entry:
ifail must be set to
,
. If you are unfamiliar with this argument you should refer to
Section 4 in the Introduction to the NAG Library FL Interface 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 argument, 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:
-
On entry, .
Constraint: .
On entry, .
Constraint: .
-
The constraint on the left- or right-hand boundary condition has been violated.
-
The function became zero or changed sign in the interval .
-
After iterations the eigenvalue had not been found to the required accuracy.
-
The bracketing phase failed to bracket the eigenvalue within ten iterations. This may be due to an error in formulating the problem (for example, is independent of ), or by very poor initial estimates for the eigenvalue and search step.
On exit, and give the end points of the interval within which no eigenvalue was located by the routine.
-
Too small a step size was required at the start of a sub-interval to obtain the desired accuracy.
-
Too small a step size was required during solution in a sub-interval to obtain the desired accuracy.
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.
-
The tolerance set is too small for the problem being solved and the machine precision being used. The local eigenvalue estimate returned is likely to be a very good approximation.
-
An internal error has occurred corresponding to a pole of the matching function. Try solving the problem again with a smaller tolerance.
An unexpected error has been triggered by this routine. Please
contact
NAG.
See
Section 7 in the Introduction to the NAG Library FL Interface for further information.
Your licence key may have expired or may not have been installed correctly.
See
Section 8 in the Introduction to the NAG Library FL Interface for further information.
Dynamic memory allocation failed.
See
Section 9 in the Introduction to the NAG Library FL Interface for further information.
7
Accuracy
The absolute accuracy of the computed eigenvalue is usually within a mixed absolute/relative bound defined by
tol (as defined above).
8
Parallelism and Performance
d02kaf is not threaded in any implementation.
The time taken by
d02kaf 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.
See
Section 9 in
d02kdf for a discussion of the technique used.
10
Example
This example finds the fourth eigenvalue of Mathieu's equations
with boundary conditions
and
. We use a starting value
and a step
. We illustrate the effect of varying
tol by choosing
and
(note the change in the output value of the error estimate
delam). The range of integration and initial estimates are read from a data file.
10.1
Program Text
10.2
Program Data
10.3
Program Results