NAG Library Routine Document
D02RAF
1 Purpose
D02RAF solves a twopoint boundary value problem with general boundary conditions for a system of ordinary differential equations, using a deferred correction technique and Newton iteration.
2 Specification
SUBROUTINE D02RAF ( 
N, MNP, NP, NUMBEG, NUMMIX, TOL, INIT, X, Y, LDY, ABT, FCN, G, IJAC, JACOBF, JACOBG, DELEPS, JACEPS, JACGEP, WORK, LWORK, IWORK, LIWORK, IFAIL) 
INTEGER 
N, MNP, NP, NUMBEG, NUMMIX, INIT, LDY, IJAC, LWORK, IWORK(LIWORK), LIWORK, IFAIL 
REAL (KIND=nag_wp) 
TOL, X(MNP), Y(LDY,MNP), ABT(N), DELEPS, WORK(LWORK) 
EXTERNAL 
FCN, G, JACOBF, JACOBG, JACEPS, JACGEP 

3 Description
D02RAF solves a twopoint boundary value problem for a system of
$n$ ordinary differential equations in the interval
$\left[a,b\right]$ with
$b>a$. The system is written in the form
and the derivatives
${f}_{i}$ are evaluated by
FCN. With the differential equations
(1) must be given a system of
$n$ (nonlinear) boundary conditions
where
The functions
${g}_{i}$ are evaluated by
G. The solution is computed using a finite difference technique with deferred correction allied to a Newton iteration to solve the finite difference equations. The technique used is described fully in
Pereyra (1979).
You must supply an absolute error tolerance and may also supply an initial mesh for the finite difference equations and an initial approximate solution (alternatively a default mesh and approximation are used). The approximate solution is corrected using Newton iteration and deferred correction. Then, additional points are added to the mesh and the solution is recomputed with the aim of making the error everywhere less than your tolerance and of approximately equidistributing the error 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.
The Newton iteration requires Jacobian matrices
These may be supplied through
JACOBF for
$\left(\frac{\partial {f}_{i}}{\partial {y}_{j}}\right)$ and
JACOBG for the others. Alternatively the Jacobians may be calculated by numerical differentiation using the algorithm described in
Curtis et al. (1974).
For problems of the type
(1) and
(2) for which it is difficult to determine an initial approximation from which the Newton iteration will converge, a continuation facility is provided. You must set up a family of problems
where
$f={\left[{f}_{1},{f}_{2},\dots ,{f}_{n}\right]}^{\mathrm{T}}$ etc., and where
$\epsilon $ is a continuation parameter. The choice
$\epsilon =0$ must give a problem
(3) which is easy to solve and
$\epsilon =1$ must define the problem whose solution is actually required. The routine solves a sequence of problems with
$\epsilon $ values
The number
$p$ and the values
${\epsilon}_{i}$ are chosen by the routine so that each problem can be solved using the solution of its predecessor as a starting approximation. Jacobians
$\frac{\partial f}{\partial \epsilon}$ and
$\frac{\partial g}{\partial \epsilon}$ are required and they may be supplied by you via
JACEPS and
JACGEP respectively or may be computed by numerical differentiation.
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 finitedifference 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: $\mathrm{N}$ – INTEGERInput

On entry: $\mathit{n}$, the number of differential equations.
Constraint:
${\mathbf{N}}>0$.
 2: $\mathrm{MNP}$ – INTEGERInput

On entry:
MNP must be set to the maximum permitted number of points in the finite difference mesh. If
LWORK or
LIWORK are too small then internally
MNP will be replaced by the maximum permitted by these values. (A warning message will be output if on entry
IFAIL is set to obtain monitoring information.)
Constraint:
${\mathbf{MNP}}\ge 32$.
 3: $\mathrm{NP}$ – INTEGERInput/Output

On entry: must be set to the number of points to be used in the initial mesh.
Constraint:
$4\le {\mathbf{NP}}\le {\mathbf{MNP}}$.
On exit: the number of points in the final mesh.
 4: $\mathrm{NUMBEG}$ – INTEGERInput

On entry: the number of lefthand boundary conditions (that is the number involving $y\left(a\right)$ only).
Constraint:
$0\le {\mathbf{NUMBEG}}<{\mathbf{N}}$.
 5: $\mathrm{NUMMIX}$ – INTEGERInput

On entry: the number of coupled boundary conditions (that is the number involving both $y\left(a\right)$ and $y\left(b\right)$).
Constraint:
$0\le {\mathbf{NUMMIX}}\le {\mathbf{N}}{\mathbf{NUMBEG}}$.
 6: $\mathrm{TOL}$ – REAL (KIND=nag_wp)Input

On entry: a positive absolute error tolerance. If
is the final mesh,
${z}_{j}\left({x}_{i}\right)$ is the
$j$th component of the approximate solution at
${x}_{i}$, and
${y}_{j}\left(x\right)$ is the
$j$th component of the true solution of
(1) and
(2), then, except in extreme circumstances, it is expected that
Constraint:
${\mathbf{TOL}}>0.0$.
 7: $\mathrm{INIT}$ – INTEGERInput

On entry: indicates whether you wish to supply an initial mesh and approximate solution (${\mathbf{INIT}}=1$) or whether default values are to be used, (${\mathbf{INIT}}=0$).
Constraint:
${\mathbf{INIT}}=0$ or $1$.
 8: $\mathrm{X}\left({\mathbf{MNP}}\right)$ – REAL (KIND=nag_wp) arrayInput/Output

On entry: you must set ${\mathbf{X}}\left(1\right)=a$ and ${\mathbf{X}}\left({\mathbf{NP}}\right)=b$. If ${\mathbf{INIT}}=0$ on entry a default equispaced mesh will be used, otherwise you must specify a mesh by setting
${\mathbf{X}}\left(\mathit{i}\right)={x}_{\mathit{i}}$, for $\mathit{i}=2,3,\dots ,{\mathbf{NP}}1$.
Constraints:
 if ${\mathbf{INIT}}=0$, ${\mathbf{X}}\left(1\right)<{\mathbf{X}}\left({\mathbf{NP}}\right)$;
 if ${\mathbf{INIT}}=1$, ${\mathbf{X}}\left(1\right)<{\mathbf{X}}\left(2\right)<\cdots <{\mathbf{X}}\left({\mathbf{NP}}\right)$.
On exit:
${\mathbf{X}}\left(1\right),{\mathbf{X}}\left(2\right),\dots ,{\mathbf{X}}\left({\mathbf{NP}}\right)$ define the final mesh (with the returned value of
NP) and
${\mathbf{X}}\left(1\right)=a$ and
${\mathbf{X}}\left({\mathbf{NP}}\right)=b$.
 9: $\mathrm{Y}\left({\mathbf{LDY}},{\mathbf{MNP}}\right)$ – REAL (KIND=nag_wp) arrayInput/Output

On entry: if
${\mathbf{INIT}}=0$, then
Y need not be set.
If
${\mathbf{INIT}}=1$, then the array
Y must contain an initial approximation to the solution such that
${\mathbf{Y}}\left(j,i\right)$ contains an approximation to
On exit: the approximate solution
${z}_{j}\left({x}_{i}\right)$ satisfying
(5) on the final mesh, that is
where
NP is the number of points in the final mesh. If an error has occurred then
Y contains the latest approximation to the solution. The remaining columns of
Y are not used.
 10: $\mathrm{LDY}$ – INTEGERInput

On entry: the first dimension of the array
Y as declared in the (sub)program from which D02RAF is called.
Constraint:
${\mathbf{LDY}}\ge {\mathbf{N}}$.
 11: $\mathrm{ABT}\left({\mathbf{N}}\right)$ – REAL (KIND=nag_wp) arrayOutput

On exit: ${\mathbf{ABT}}\left(\mathit{i}\right)$, for $\mathit{i}=1,2,\dots ,n$, holds the largest estimated error (in magnitude) of the $i$th component of the solution over all mesh points.
 12: $\mathrm{FCN}$ – SUBROUTINE, supplied by the user.External Procedure

FCN must evaluate the functions
${f}_{i}$ (i.e., the derivatives
${y}_{i}^{\prime}$) at a general point
$x$ for a given value of
$\epsilon $, the continuation parameter (see
Section 3).
The specification of
FCN is:
INTEGER 
N 
REAL (KIND=nag_wp) 
X, EPS, Y(N), F(N) 

 1: $\mathrm{X}$ – REAL (KIND=nag_wp)Input

On entry: $x$, the value of the independent variable.
 2: $\mathrm{EPS}$ – REAL (KIND=nag_wp)Input

On entry: $\epsilon $, the value of the continuation parameter. This is $1$ if continuation is not being used.
 3: $\mathrm{Y}\left({\mathbf{N}}\right)$ – REAL (KIND=nag_wp) arrayInput

On entry: ${y}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,\mathit{n}$, the values of the dependent variables at $x$.
 4: $\mathrm{F}\left({\mathbf{N}}\right)$ – REAL (KIND=nag_wp) arrayOutput

On exit: the values of the derivatives
${f}_{\mathit{i}}$ evaluated at $x$ given $\epsilon $, for $\mathit{i}=1,2,\dots ,\mathit{n}$.
 5: $\mathrm{N}$ – INTEGERInput

On entry: $n$, the number of equations.
FCN must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which D02RAF is called. Arguments denoted as
Input must
not be changed by this procedure.
 13: $\mathrm{G}$ – SUBROUTINE, supplied by the user.External Procedure

G must evaluate the boundary conditions in equation
(3) and place them in the array
BC.
The specification of
G is:
INTEGER 
N 
REAL (KIND=nag_wp) 
EPS, YA(N), YB(N), BC(N) 

 1: $\mathrm{EPS}$ – REAL (KIND=nag_wp)Input

On entry: $\epsilon $, the value of the continuation parameter. This is $1$ if continuation is not being used.
 2: $\mathrm{YA}\left({\mathbf{N}}\right)$ – REAL (KIND=nag_wp) arrayInput

On entry: the value
${y}_{\mathit{i}}\left(a\right)$, for $\mathit{i}=1,2,\dots ,n$.
 3: $\mathrm{YB}\left({\mathbf{N}}\right)$ – REAL (KIND=nag_wp) arrayInput

On entry: the value
${y}_{\mathit{i}}\left(b\right)$, for $\mathit{i}=1,2,\dots ,n$.
 4: $\mathrm{BC}\left({\mathbf{N}}\right)$ – REAL (KIND=nag_wp) arrayOutput

On exit: the values
${g}_{\mathit{i}}\left(y\left(a\right),y\left(b\right),\epsilon \right)$, for
$\mathit{i}=1,2,\dots ,n$. These must be ordered as follows:
(i) 
first, the conditions involving only $y\left(a\right)$ (see NUMBEG); 
(ii) 
next, the NUMMIX coupled conditions involving both $y\left(a\right)$ and $y\left(b\right)$ (see NUMMIX); and, 
(iii) 
finally, the conditions involving only $y\left(b\right)$ (${\mathbf{N}}{\mathbf{NUMBEG}}{\mathbf{NUMMIX}}$). 
 5: $\mathrm{N}$ – INTEGERInput

On entry: $\mathit{n}$, the number of equations.
G must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which D02RAF is called. Arguments denoted as
Input must
not be changed by this procedure.
 14: $\mathrm{IJAC}$ – INTEGERInput

On entry: indicates whether or not you are supplying Jacobian evaluation routines.
 ${\mathbf{IJAC}}\ne 0$
 You must supply JACOBF and JACOBG and also, when continuation is used, JACEPS and JACGEP.
 ${\mathbf{IJAC}}=0$
 Numerical differentiation is used to calculate the Jacobian and the routines D02GAW, D02GAX, D02GAY and D02GAZ respectively may be used as the dummy arguments.
 15: $\mathrm{JACOBF}$ – SUBROUTINE, supplied by the NAG Library or the user.External Procedure

JACOBF evaluates the Jacobian
$\left(\frac{\partial {f}_{\mathit{i}}}{\partial {y}_{\mathit{j}}}\right)$, for
$\mathit{i}=1,2,\dots ,n$ and
$\mathit{j}=1,2,\dots ,n$, given
$x$ and
${y}_{\mathit{j}}$, for
$\mathit{j}=1,2,\dots ,n$.
If ${\mathbf{IJAC}}=0$, then numerical differentiation is used to calculate the Jacobian and the routine D02GAZ may be substituted for this argument.
The specification of
JACOBF is:
SUBROUTINE JACOBF ( 
X, EPS, Y, F, N) 
INTEGER 
N 
REAL (KIND=nag_wp) 
X, EPS, Y(N), F(N,N) 

 1: $\mathrm{X}$ – REAL (KIND=nag_wp)Input

On entry: $x$, the value of the independent variable.
 2: $\mathrm{EPS}$ – REAL (KIND=nag_wp)Input

On entry: $\epsilon $, the value of the continuation parameter. This is $1$ if continuation is not being used.
 3: $\mathrm{Y}\left({\mathbf{N}}\right)$ – REAL (KIND=nag_wp) arrayInput

On entry: ${y}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,\mathit{n}$, the values of the dependent variables at $x$.
 4: $\mathrm{F}\left({\mathbf{N}},{\mathbf{N}}\right)$ – REAL (KIND=nag_wp) arrayOutput

On exit: ${\mathbf{F}}\left(\mathit{j},\mathit{i}\right)$ must be set to the value of $\frac{\partial {f}_{\mathit{i}}}{\partial {y}_{\mathit{j}}}$, evaluated at the point $\left(x,y\right)$, for $\mathit{i}=1,2,\dots ,n$ and $\mathit{j}=1,2,\dots ,n$.
 5: $\mathrm{N}$ – INTEGERInput

On entry: $\mathit{n}$, the number of equations.
JACOBF must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which D02RAF is called. Arguments denoted as
Input must
not be changed by this procedure.
 16: $\mathrm{JACOBG}$ – SUBROUTINE, supplied by the NAG Library or the user.External Procedure

JACOBG evaluates the Jacobians
$\left(\frac{\partial {g}_{i}}{\partial {y}_{j}\left(a\right)}\right)$ and
$\left(\frac{\partial {g}_{i}}{\partial {y}_{j}\left(b\right)}\right)$. The ordering of the rows of
AJ and
BJ must correspond to the ordering of the boundary conditions described in the specification of
G.
If ${\mathbf{IJAC}}=0$, then numerical differentiation is used to calculate the Jacobian and the routine D02GAY may be substituted for this argument.
The specification of
JACOBG is:
INTEGER 
N 
REAL (KIND=nag_wp) 
EPS, YA(N), YB(N), AJ(N,N), BJ(N,N) 

 1: $\mathrm{EPS}$ – REAL (KIND=nag_wp)Input

On entry: $\epsilon $, the value of the continuation parameter. This is $1$ if continuation is not being used.
 2: $\mathrm{YA}\left({\mathbf{N}}\right)$ – REAL (KIND=nag_wp) arrayInput

On entry: the value
${y}_{\mathit{i}}\left(a\right)$, for $\mathit{i}=1,2,\dots ,n$.
 3: $\mathrm{YB}\left({\mathbf{N}}\right)$ – REAL (KIND=nag_wp) arrayInput

On entry: the value
${y}_{\mathit{i}}\left(b\right)$, for $\mathit{i}=1,2,\dots ,n$.
 4: $\mathrm{AJ}\left({\mathbf{N}},{\mathbf{N}}\right)$ – REAL (KIND=nag_wp) arrayOutput

On exit: ${\mathbf{AJ}}\left(\mathit{i},\mathit{j}\right)$ must be set to the value $\frac{\partial {g}_{\mathit{i}}}{\partial {y}_{\mathit{j}}\left(a\right)}$, for $\mathit{i}=1,2,\dots ,n$ and $\mathit{j}=1,2,\dots ,n$.
 5: $\mathrm{BJ}\left({\mathbf{N}},{\mathbf{N}}\right)$ – REAL (KIND=nag_wp) arrayOutput

On exit: ${\mathbf{BJ}}\left(\mathit{i},\mathit{j}\right)$ must be set to the value $\frac{\partial {g}_{\mathit{i}}}{\partial {y}_{\mathit{j}}\left(b\right)}$, for $\mathit{i}=1,2,\dots ,n$ and $\mathit{j}=1,2,\dots ,n$.
 6: $\mathrm{N}$ – INTEGERInput

On entry: $\mathit{n}$, the number of equations.
JACOBG must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which D02RAF is called. Arguments denoted as
Input must
not be changed by this procedure.
 17: $\mathrm{DELEPS}$ – REAL (KIND=nag_wp)Input/Output

On entry: must be given a value which specifies whether continuation is required. If
${\mathbf{DELEPS}}\le 0.0$ or
${\mathbf{DELEPS}}\ge 1.0$ then it is assumed that continuation is not required. If
$0.0<{\mathbf{DELEPS}}<1.0$ then it is assumed that continuation is required unless
${\mathbf{DELEPS}}<\sqrt{\mathit{machineprecision}}$ when an error exit is taken.
DELEPS is used as the increment
${\epsilon}_{2}{\epsilon}_{1}$ (see
(4)) and the choice
${\mathbf{DELEPS}}=0.1$ is recommended.
On exit: an overestimate of the increment
${\epsilon}_{p}{\epsilon}_{p1}$ (in fact the value of the increment which would have been tried if the restriction
${\epsilon}_{p}=1$ had not been imposed). If continuation was not requested then
${\mathbf{DELEPS}}=0.0$.
If continuation is not requested then
JACEPS and
JACGEP may each be replaced by dummy actual arguments in the call to D02RAF. (D02GAW and D02GAX respectively may be used as the dummy arguments.)
 18: $\mathrm{JACEPS}$ – SUBROUTINE, supplied by the NAG Library or the user.External Procedure

JACEPS evaluates the derivative
$\frac{\partial {f}_{i}}{\partial \epsilon}$ given
$x$ and
$y$ if continuation is being used.
If all Jacobians (derivatives) are to be approximated internally by numerical differentiation, or continuation is not being used,
the routine D02GAW may be substituted for this argument.
The specification of
JACEPS is:
SUBROUTINE JACEPS ( 
X, EPS, Y, F, N) 
INTEGER 
N 
REAL (KIND=nag_wp) 
X, EPS, Y(N), F(N) 

 1: $\mathrm{X}$ – REAL (KIND=nag_wp)Input

On entry: $x$, the value of the independent variable.
 2: $\mathrm{EPS}$ – REAL (KIND=nag_wp)Input

On entry: $\epsilon $, the value of the continuation parameter.
 3: $\mathrm{Y}\left({\mathbf{N}}\right)$ – REAL (KIND=nag_wp) arrayInput

On entry: the solution values
${y}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$, at the point $x$.
 4: $\mathrm{F}\left({\mathbf{N}}\right)$ – REAL (KIND=nag_wp) arrayOutput

On exit: ${\mathbf{F}}\left(\mathit{i}\right)$ must contain the value $\frac{\partial {f}_{\mathit{i}}}{\partial \epsilon}$ at the point $\left(x,y\right)$, for $\mathit{i}=1,2,\dots ,n$.
 5: $\mathrm{N}$ – INTEGERInput

On entry: $\mathit{n}$, the number of equations.
JACEPS must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which D02RAF is called. Arguments denoted as
Input must
not be changed by this procedure.
 19: $\mathrm{JACGEP}$ – SUBROUTINE, supplied by the NAG Library or the user.External Procedure

JACGEP evaluates the derivatives
$\frac{\partial {g}_{i}}{\partial \epsilon}$ if continuation is being used.
If all Jacobians (derivatives) are to be approximated internally by numerical differentiation, or continuation is not being used,
the routine D02GAX may be substituted for this argument.
The specification of
JACGEP is:
INTEGER 
N 
REAL (KIND=nag_wp) 
EPS, YA(N), YB(N), BCEP(N) 

 1: $\mathrm{EPS}$ – REAL (KIND=nag_wp)Input

On entry: $\epsilon $, the value of the continuation parameter.
 2: $\mathrm{YA}\left({\mathbf{N}}\right)$ – REAL (KIND=nag_wp) arrayInput

On entry: the value of
${y}_{\mathit{i}}\left(a\right)$, for $\mathit{i}=1,2,\dots ,n$.
 3: $\mathrm{YB}\left({\mathbf{N}}\right)$ – REAL (KIND=nag_wp) arrayInput

On entry: the value of
${y}_{\mathit{i}}\left(b\right)$, for $\mathit{i}=1,2,\dots ,n$.
 4: $\mathrm{BCEP}\left({\mathbf{N}}\right)$ – REAL (KIND=nag_wp) arrayOutput

On exit: ${\mathbf{BCEP}}\left(\mathit{i}\right)$ must contain the value of $\frac{\partial {g}_{\mathit{i}}}{\partial \epsilon}$, for $\mathit{i}=1,2,\dots ,n$.
 5: $\mathrm{N}$ – INTEGERInput

On entry: $\mathit{n}$, the number of equations.
JACGEP must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which D02RAF is called. Arguments denoted as
Input must
not be changed by this procedure.
 20: $\mathrm{WORK}\left({\mathbf{LWORK}}\right)$ – REAL (KIND=nag_wp) arrayWorkspace
 21: $\mathrm{LWORK}$ – INTEGERInput

On entry: the dimension of the array
WORK as declared in the (sub)program from which D02RAF is called.
Constraint:
${\mathbf{LWORK}}\ge {\mathbf{MNP}}\times \left(3{{\mathbf{N}}}^{2}+6{\mathbf{N}}+2\right)+4{{\mathbf{N}}}^{2}+3{\mathbf{N}}$.
 22: $\mathrm{IWORK}\left({\mathbf{LIWORK}}\right)$ – INTEGER arrayWorkspace
 23: $\mathrm{LIWORK}$ – INTEGERInput

On entry: the dimension of the array
IWORK as declared in the (sub)program from which D02RAF is called.
Constraints:
 if ${\mathbf{IJAC}}\ne 0$, ${\mathbf{LIWORK}}\ge {\mathbf{MNP}}\times \left(2\times {\mathbf{N}}+1\right)+{\mathbf{N}}$;
 if ${\mathbf{IJAC}}=0$, ${\mathbf{LIWORK}}\ge {\mathbf{MNP}}\times \left(2\times {\mathbf{N}}+1\right)+{{\mathbf{N}}}^{2}+4\times {\mathbf{N}}+2$.
 24: $\mathrm{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
$\mathit{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:
${\mathbf{IFAIL}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see
Section 6).
6 Error Indicators and Warnings
If on entry
${\mathbf{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:
 ${\mathbf{IFAIL}}=1$

One or more of the arguments
N,
MNP,
NP,
NUMBEG,
NUMMIX,
TOL,
DELEPS,
LWORK or
LIWORK is incorrectly set, or
${\mathbf{X}}\left(1\right)\ge {\mathbf{X}}\left({\mathbf{NP}}\right)$ or the mesh points
${\mathbf{X}}\left(i\right)$ are not in strictly ascending order.
 ${\mathbf{IFAIL}}=2$

A finer mesh is required for the accuracy requested; that is
MNP is not large enough. This error exit normally occurs when the problem being solved is difficult (for example, there is a boundary layer) and high accuracy is requested. A poor initial choice of mesh points will make this error exit more likely.
 ${\mathbf{IFAIL}}=3$

The Newton iteration has failed to converge. There are several possible causes for this error:
(i) 
faulty coding in one of the Jacobian calculation routines; 
(ii) 
if ${\mathbf{IJAC}}=0$ then inaccurate Jacobians may have been calculated numerically (this is a very unlikely cause); or, 
(iii) 
a poor initial mesh or initial approximate solution has been selected either by you or by default or there are not enough points in the initial mesh. Possibly, you should try the continuation facility. 
 ${\mathbf{IFAIL}}=4$

The Newton iteration has reached roundoff error level. It could be however that the answer returned is satisfactory. The error is likely to occur if too high an accuracy is requested.
 ${\mathbf{IFAIL}}=5$

The Jacobian calculated by
JACOBG (or the equivalent matrix calculated by numerical differentiation) is singular. This may occur due to faulty coding of
JACOBG or, in some circumstances, to a zero initial choice of approximate solution (such as is chosen when
${\mathbf{INIT}}=0$).
 ${\mathbf{IFAIL}}=6$

There is no dependence on
$\epsilon $ when continuation is being used. This can be due to faulty coding of
JACEPS or
JACGEP or, in some circumstances, to a zero initial choice of approximate solution (such as is chosen when
${\mathbf{INIT}}=0$).
 ${\mathbf{IFAIL}}=7$

DELEPS is required to be less than
machine precision for continuation to proceed. It is likely that either the problem
(3) has no solution for some value near the current value of
$\epsilon $ (see the advisory print out from D02RAF) or that the problem is so difficult that even with continuation it is unlikely to be solved using this routine. If the latter cause is suspected then using more mesh points initially may help.
 ${\mathbf{IFAIL}}=8$
 ${\mathbf{IFAIL}}=9$

A serious error has occurred in an internal call. Check all array subscripts and subroutine argument lists in calls to D02RAF. Seek expert help.
 ${\mathbf{IFAIL}}=99$
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.
 ${\mathbf{IFAIL}}=399$
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.
 ${\mathbf{IFAIL}}=999$
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
(5) except in extreme circumstances. The final error estimate over the whole mesh for each component is given in the array
ABT. 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
D02RAF 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.
D02RAF is not threaded in any implementation.
There are too many factors present to quantify the timing. The time taken by D02RAF is negligible only on very simple problems.
You are strongly recommended to set
IFAIL to obtain selfexplanatory error messages, and also monitoring information about the course of the computation. Monitoring information is written to a logical advisory message unit which normally default to the same unit number as the error message unit (see
Section 3.5 in How to Use the NAG Library and its Documentation for details); the advisory message unit number can be changed by calling
X04ABF.
In the case where you wish to solve a sequence of similar problems, the use of the final mesh and solution from one case as the initial mesh is strongly recommended for the next.
10 Example
This example solves the differential equation
with
$\epsilon =1$ and boundary conditions
to an accuracy specified by
${\mathbf{TOL}}=\text{1.0E\u22124}$. The continuation facility is used with the continuation parameter
$\epsilon $ introduced as in the differential equation above and with
${\mathbf{DELEPS}}=0.1$ initially. (The continuation facility is not needed for this problem and is used here for illustration.)
10.1 Program Text
Program Text (d02rafe.f90)
10.2 Program Data
Program Data (d02rafe.d)
10.3 Program Results
Program Results (d02rafe.r)