A, B, TOL, C(N,N), D(N,N), GAM(N), X(MNP), Y(N,MNP), W(LW)
D02GBF solves a linear two-point boundary value problem for a system of ordinary differential equations in the interval . The system is written in the form
and the boundary conditions are written in the form
Here , and are by matrices, and and are -component vectors. The approximate solution to (1) and (2) is found using a finite difference method with deferred correction. The algorithm is a specialization of that used in subroutine D02RAF which solves a nonlinear version of (1) and (2). The nonlinear version of the algorithm is described fully in Pereyra (1979).
You supply an absolute error tolerance and may also supply an initial mesh for the construction of the finite difference equations (alternatively a default mesh is used). The algorithm constructs a solution on a mesh defined by adding points to the initial mesh. This solution is chosen so that the error is everywhere less than your tolerance and so that the error is approximately equidistributed on the final mesh. The solution is returned on this final mesh.
If the solution is required at a few specific points then these should be included in the initial mesh. If, on the other hand, the solution is required at several specific points, then you should use the interpolation routines provided in Chapter E01 if these points do not themselves form a convenient mesh.
Pereyra V (1979) PASVA3: An adaptive finite-difference Fortran program for first order nonlinear, ordinary boundary problems Codes for Boundary Value Problems in Ordinary Differential Equations. Lecture Notes in Computer Science (eds B Childs, M Scott, J W Daniel, E Denman and P Nelson) 76 Springer–Verlag
1: A – REAL (KIND=nag_wp)Input
On entry: , the left-hand boundary point.
2: B – REAL (KIND=nag_wp)Input
On entry: , the right-hand boundary point.
3: N – INTEGERInput
On entry: the number of equations; that is is the order of system (1).
4: TOL – REAL (KIND=nag_wp)Input
On entry: a positive absolute error tolerance. If
is the final mesh, is the approximate solution from D02GBF and is the true solution of equations (1) and (2) then, except in extreme cases, it is expected that
5: FCNF – SUBROUTINE, supplied by the user.External Procedure
FCNF must evaluate the matrix in (1) at a general point .
On entry: the arrays C and D must be set to the matrices and in (2)). GAM must be set to the vector in (2).
On exit: the rows of C and D and the components of GAM are reordered so that the boundary conditions are in the order:
conditions on only;
condition involving and ; and
conditions on only.
The routine will be slightly more efficient if the arrays C, D and GAM are ordered in this way before entry, and in this event they will be unchanged on exit.
Note that the problems (1) and (2) must be of boundary value type, that is neither nor may be identically zero. Note also that the rank of the matrix must be for the problem to be properly posed. Any violation of these conditions will lead to an error exit.
10: MNP – INTEGERInput
On entry: the maximum permitted number of mesh points.
On entry: the dimension of the array IW as declared in the (sub)program from which D02GBF is called.
18: IFAIL – INTEGERInput/Output
For this routine, the normal use of IFAIL is extended to control the printing of error and warning messages as well as specifying hard or soft failure (see Section 3.3 in the Essential Introduction).
On entry: IFAIL must be set to a value with the decimal expansion , where each of the decimal digits , and must have a value of or .
specifies hard failure, otherwise soft failure;
suppresses error messages, otherwise error messages will be printed (see Section 6);
suppresses warning messages, otherwise warning messages will be printed (see Section 6).
The recommended value for inexperienced users is (i.e., hard failure with all messages printed).
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:
One or more of the parameters N, TOL, NP, MNP, LW or LIW is incorrectly set, or the condition (4) on X is not satisfied.
There are three possible reasons for this error exit to be taken:
one of the matrices or is identically zero (that is, the problem is of initial value and not boundary value type). In this case, on exit;
a row of and the corresponding row of are identically zero (that is, the boundary conditions are rank deficient). In this case, on exit contains the index of the first such row encountered; and
more than of the columns of the by matrix are identically zero (that is, the boundary conditions are rank deficient). In this case, on exit contains minus the number of non-identically zero columns.
The routine has failed to find a solution to the specified accuracy. There are a variety of possible reasons including:
the boundary conditions are rank deficient, which may be indicated by the message that the Jacobian is singular. However this is an unlikely explanation for the error exit as all rank deficient boundary conditions should lead instead to error exits with either or ; see also (iv);
not enough mesh points are permitted in order to attain the required accuracy. This is indicated by on return from a call to D02GBF. This difficulty may be aggravated by a poor initial choice of mesh points;
the accuracy requested cannot be attained on the computer being used; and
an unlikely combination of values of has led to a singular Jacobian. The error should not persist if more mesh points are allowed.
A serious error has occurred in a call to D02GBF. Check all array subscripts and subroutine parameter lists in calls to D02GBF. Seek expert help.
There are two possible reasons for this error exit which occurs when checking the rank of the boundary conditions by reduction to a row echelon form:
at least one row of the by matrix is a linear combination of the other rows and hence the boundary conditions are rank deficient. The index of the first such row encountered is given by on exit; and
as (i) but the rank deficiency implied by this error exit has only been determined up to a numerical tolerance. Minus the index of the first such row encountered is given by on exit.
In case (ii) there is some doubt as to the rank deficiency of the boundary conditions. However even if the boundary conditions are not rank deficient they are not posed in a suitable form for use with this routine.
For example, if
and is small enough, this error exit is likely to be taken. A better form for the boundary conditions in this case would be
The solution returned by the routine will be accurate to your tolerance as defined by the relation (3) except in extreme circumstances. If too many points are specified in the initial mesh, the solution may be more accurate than requested and the error may not be approximately equidistributed.
8 Further Comments
The time taken by D02GBF depends on the difficulty of the problem, the number of mesh points (and meshes) used and the number of deferred corrections.
You are strongly recommended to set IFAIL to obtain self-explanatory error messages, and also monitoring information about the course of the computation. You may select the channel numbers on which this output is to appear by calls of X04AAF (for error messages) or X04ABF (for monitoring information) – see Section 9 for an example. Otherwise the default channel numbers will be used, as specified in the Users' Note.
In the case where you wish to solve a sequence of similar problems, the final mesh from solving one case is strongly recommended as the initial mesh for the next.
This example solves the problem (written as a first-order system)
with boundary conditions
for the cases and using the default initial mesh in the first case, and the final mesh of the first case as initial mesh for the second (more difficult) case. We give the solution and the error at each mesh point to illustrate the accuracy of the method given the accuracy request .
Note the call to X04ABF prior to the call to D02GBF.