d02gaf solves a two-point boundary value problem for a system of differential equations in the interval . The system is written in the form:
and the derivatives are evaluated by fcn. Initially, boundary values of the variables must be specified, some at and some at . You must supply estimates of the remaining boundary values and all the boundary values are used in constructing an initial approximation to the solution. This approximate solution is corrected by a finite difference technique with deferred correction allied with a Newton iteration to solve the finite difference equations. The technique used is described fully in Pereyra (1979). The Newton iteration requires a Jacobian matrix and this is calculated by numerical differentiation using an algorithm described in Curtis et al. (1974).
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.
Curtis A R, Powell M J D and Reid J K (1974) On the estimation of sparse Jacobian matrices J. Inst. Maths. Applics.13 117–119
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: – Real (Kind=nag_wp) arrayInput
On entry: must be set to the known or estimated value of at and must be set to the known or estimated value of at , for .
2: – Real (Kind=nag_wp) arrayInput
On entry: must be set to if is a known value and to if is an estimated value, for and .
precisely of the must be set to , i.e., precisely of the must be known values, and these must not be all at or all at .
3: – IntegerInput
On entry: , the number of equations.
4: – Real (Kind=nag_wp)Input
On entry: , the left-hand boundary point.
5: – Real (Kind=nag_wp)Input
On entry: , the right-hand boundary point.
6: – Real (Kind=nag_wp)Input
On entry: a positive absolute error tolerance. If
is the final mesh, is the th component of the approximate solution at , and is the th component of the true solution of equation (1) (see Section 3) and the boundary conditions, then, except in extreme cases, it is expected that
7: – Subroutine, supplied by the user.External Procedure
fcn must evaluate the functions
(i.e., the derivatives ), for , at a general point .
In the description of the arguments of d02gaf below, denotes the actual value of n in the call of d02gaf.
1: – Real (Kind=nag_wp)Input
On entry: , the value of the argument.
2: – Real (Kind=nag_wp) arrayInput
On entry: , for , the value of the argument.
3: – Real (Kind=nag_wp) arrayOutput
On exit: the values of
, for .
fcn must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which d02gaf is called. Arguments denoted as Input must not be changed by this procedure.
Note:fcn should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by d02gaf. If your code inadvertently does return any NaNs or infinities, d02gaf is likely to produce unexpected results.
8: – IntegerInput
On entry: the maximum permitted number of mesh points.
9: – Real (Kind=nag_wp) arrayInput/Output
On entry: if (see np), the first np elements must define an initial mesh. Otherwise the elements of x need not be set.
On exit: define the final mesh (with the returned value of np) satisfying the relation (3).
10: – Real (Kind=nag_wp) arrayOutput
On exit: the approximate solution satisfying (2), on the final mesh, that is
where np is the number of points in the final mesh.
On entry: determines whether a default or user-supplied mesh is used.
A default value of for np and a corresponding equispaced mesh are used.
You must define an initial mesh using the array x as described.
On exit: the number of points in the final (returned) mesh.
12: – Real (Kind=nag_wp) arrayWorkspace
13: – IntegerInput
On entry: the dimension of the array w as declared in the (sub)program from which d02gaf is called.
14: – Integer arrayWorkspace
15: – IntegerInput
On entry: the dimension of the array iw as declared in the (sub)program from which d02gaf is called.
16: – 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.4 in How to Use the NAG Library and its Documentation).
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).
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 arguments n, tol, np, mnp, lw or liw has been incorrectly set, or , or the condition (3) on x is not satisfied, or the number of known boundary values (specified by v) is not n.
The Newton iteration has failed to converge. This could be due to there being too few points in the initial mesh or to the initial approximate solution being too inaccurate. If this latter reason is suspected you should use d02raf instead. If the warning ‘Jacobian matrix is singular’ is printed this could be due to specifying zero estimated boundary values and these should be varied. This warning could also be printed in the unlikely event of the Jacobian matrix being calculated inaccurately. If you cannot make changes to prevent the warning then d02raf should be used.
The Newton iteration has reached round-off level. It could be, however, that the answer returned is satisfactory. This error might occur if too much accuracy is requested.
A finer mesh is required for the accuracy requested; that is mnp is not large enough.
A serious error has occurred in a call to d02gaf. Check all array subscripts and subroutine argument lists in calls to d02gaf. Seek expert help.
An unexpected error has been triggered by this routine. Please
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
Your licence key may have expired or may not have been installed correctly.
See Section 3.8 in How to Use the NAG Library and its Documentation for further information.
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.
The solution returned by the routine will be accurate to your tolerance as defined by the relation (2) 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.
Parallelism and Performance
d02gaf is not thread safe and should not be called from a multithreaded user program. Please see Section 3.12.1 in How to Use the NAG Library and its Documentation for more information on thread safety.
d02gaf makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.
The time taken by d02gaf depends on the difficulty of the problem, the number of mesh points (and meshes) used, the number of Newton iterations 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 unit numbers on which this output is to appear by calls of x04aaf (for error messages) or x04abf (for monitoring information) – see Section 10 for an example. Otherwise the default unit numbers will be used, as specified in the Users' Note.
A common cause of convergence problems in the Newton iteration is that you have specified too few points in the initial mesh. Although the routine adds points to the mesh to improve accuracy it is unable to do so until the solution on the initial mesh has been calculated in the Newton iteration.
If you specify zero known and estimated boundary values, the routine constructs a zero initial approximation and in many cases the Jacobian is singular when evaluated for this approximation, leading to the breakdown of the Newton iteration.
You may be unable to provide a sufficiently good choice of initial mesh and estimated boundary values, and hence the Newton iteration may never converge. In this case the continuation facility provided in d02raf is recommended.
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 differential equation
with boundary conditions
for and to an accuracy specified by . We solve first the simpler problem with using an equispaced mesh of points and then we solve the problem with using the final mesh from the first problem.
Note the call to x04abf prior to the call to d02gaf.