D02GAF (PDF version)
D02 Chapter Contents
D02 Chapter Introduction
NAG Library Manual

NAG Library Routine Document


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
    7  Accuracy

1  Purpose

D02GAF solves a two-point boundary value problem with assigned boundary values for a system of ordinary differential equations, using a deferred correction technique and a Newton iteration.

2  Specification

REAL (KIND=nag_wp)  U(N,2), V(N,2), A, B, TOL, X(MNP), Y(N,MNP), W(LW)

3  Description

D02GAF solves a two-point boundary value problem for a system of n differential equations in the interval [a,b]. The system is written in the form:
yi=fix,y1,y2,,yn,  i=1,2,,n (1)
and the derivatives fi are evaluated by FCN. Initially, n boundary values of the variables yi must be specified, some at a and some at b. You must supply estimates of the remaining n 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 fi yj  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.

4  References

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

5  Arguments

1:     UN2 – REAL (KIND=nag_wp) arrayInput
On entry: Ui1 must be set to the known or estimated value of yi at a and Ui2 must be set to the known or estimated value of yi at b, for i=1,2,,n.
2:     VN2 – REAL (KIND=nag_wp) arrayInput
On entry: Vij must be set to 0.0 if Uij is a known value and to 1.0 if Uij is an estimated value, for i=1,2,,n and j=1,2.
Constraint: precisely n of the Vij must be set to 0.0, i.e., precisely n of the Uij must be known values, and these must not be all at a or all at b.
3:     N – INTEGERInput
On entry: n, the number of equations.
Constraint: N2.
4:     A – REAL (KIND=nag_wp)Input
On entry: a, the left-hand boundary point.
5:     B – REAL (KIND=nag_wp)Input
On entry: b, the right-hand boundary point.
Constraint: B>A.
6:     TOL – REAL (KIND=nag_wp)Input
On entry: a positive absolute error tolerance. If
is the final mesh, zjxi is the jth component of the approximate solution at xi, and yjx is the jth component of the true solution of equation (1) (see Section 3) and the boundary conditions, then, except in extreme cases, it is expected that
zjxi-yjxiTOL,  i=1,2,,NP​ and ​j=1,2,,n. (2)
Constraint: TOL>0.0.
7:     FCN – SUBROUTINE, supplied by the user.External Procedure
FCN must evaluate the functions fi (i.e., the derivatives yi), for i=1,2,,n, at a general point x.
The specification of FCN is:
REAL (KIND=nag_wp)  X, Y(*), F(*)
In the description of the arguments of D02GAF below, n denotes the actual value of N in the call of D02GAF.
1:     X – REAL (KIND=nag_wp)Input
On entry: x, the value of the argument.
2:     Y* – REAL (KIND=nag_wp) arrayInput
On entry: yi, for i=1,2,,n, the value of the argument.
3:     F* – REAL (KIND=nag_wp) arrayOutput
On exit: the values of fi, for i=1,2,,n.
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.
8:     MNP – INTEGERInput
On entry: the maximum permitted number of mesh points.
Constraint: MNP32.
9:     XMNP – REAL (KIND=nag_wp) arrayInput/Output
On entry: if NP4 (see NP), the first NP elements must define an initial mesh. Otherwise the elements of X need not be set.
A=X1<X2<<XNP=B,   NP4.(3)
On exit: X1,X2,,XNP define the final mesh (with the returned value of NP) satisfying the relation (3).
10:   YNMNP – REAL (KIND=nag_wp) arrayOutput
On exit: the approximate solution zjxi satisfying (2), on the final mesh, that is
Yji=zjxi,  i=1,2,,NP​ and ​j=1,2,,n,  
where NP is the number of points in the final mesh.
The remaining columns of Y are not used.
11:   NP – INTEGERInput/Output
On entry: determines whether a default or user-supplied mesh is used.
A default value of 4 for NP and a corresponding equispaced mesh X1,X2,,XNP are used.
You must define an initial mesh using the array X as described.
Constraint: NP=0 or 4NPMNP.
On exit: the number of points in the final (returned) mesh.
12:   WLW – REAL (KIND=nag_wp) arrayWorkspace
13:   LW – INTEGERInput
On entry: the dimension of the array W as declared in the (sub)program from which D02GAF is called.
Constraint: LWMNP×3N2+6N+2+4N2+4N.
14:   IWLIW – INTEGER arrayWorkspace
15:   LIW – INTEGERInput
On entry: the dimension of the array IW as declared in the (sub)program from which D02GAF is called.
Constraint: LIWMNP×2N+1+N2+4N+2.
16:   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.4 in How to Use the NAG Library and its Documentation).
On entry: IFAIL must be set to a value with the decimal expansion cba, where each of the decimal digits c, b and a must have a value of 0 or 1.
a=0 specifies hard failure, otherwise soft failure;
b=0 suppresses error messages, otherwise error messages will be printed (see Section 6);
c=0 suppresses warning messages, otherwise warning messages will be printed (see Section 6).
The recommended value for inexperienced users is 110 (i.e., hard failure with all messages printed).
On exit: IFAIL=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6  Error Indicators and Warnings

If on entry IFAIL=0 or -1, 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 BA, 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 contact NAG.
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.

7  Accuracy

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.

8  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 is not threaded in any implementation.

9  Further Comments

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.

10  Example

This example solves the differential equation
with boundary conditions
y0=y0= 0,   y10=1  
for β=0.0 and β=0.2 to an accuracy specified by TOL=1.0E−3. We solve first the simpler problem with β=0.0 using an equispaced mesh of 26 points and then we solve the problem with β=0.2 using the final mesh from the first problem.
Note the call to X04ABF prior to the call to D02GAF.

10.1  Program Text

Program Text (d02gafe.f90)

10.2  Program Data

Program Data (d02gafe.d)

10.3  Program Results

Program Results (d02gafe.r)

GnuplotProduced by GNUPLOT 4.6 patchlevel 3 0 1 2 3 4 5 6 7 8 9 10 0 2 4 6 8 10 Solution x Example Program Two-point Boundary-value Problem using Deferred Correction Technique (β = 0.0) y y' y'' gnuplot_plot_1 gnuplot_plot_2 gnuplot_plot_3
GnuplotProduced by GNUPLOT 4.6 patchlevel 3 0 1 2 3 4 5 6 7 8 9 10 0 2 4 6 8 10 Solution x Two-point Boundary-value Problem using Deferred Correction Technique (β = 0.2) y y' y'' gnuplot_plot_1 gnuplot_plot_2 gnuplot_plot_3

D02GAF (PDF version)
D02 Chapter Contents
D02 Chapter Introduction
NAG Library Manual

© The Numerical Algorithms Group Ltd, Oxford, UK. 2016