# NAG FL Interfaced02raf (bvp_​fd_​nonlin_​gen)

## 1Purpose

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

## 2Specification

Fortran Interface
 Subroutine d02raf ( n, mnp, np, tol, init, x, y, ldy, abt, fcn, g, ijac, work,
 Integer, Intent (In) :: n, mnp, numbeg, nummix, init, ldy, ijac, lwork, liwork Integer, Intent (Inout) :: np, ifail Integer, Intent (Out) :: iwork(liwork) Real (Kind=nag_wp), Intent (In) :: tol Real (Kind=nag_wp), Intent (Inout) :: x(mnp), y(ldy,mnp), deleps Real (Kind=nag_wp), Intent (Out) :: abt(n), work(lwork) External :: fcn, g, jacobf, jacobg, jaceps, jacgep
#include <nag.h>
 void d02raf_ (const Integer *n, const Integer *mnp, Integer *np, const Integer *numbeg, const Integer *nummix, const double *tol, const Integer *init, double x[], double y[], const Integer *ldy, double abt[], void (NAG_CALL *fcn)(const double *x, const double *eps, const double y[], double f[], const Integer *n),void (NAG_CALL *g)(const double *eps, const double ya[], const double yb[], double bc[], const Integer *n),const Integer *ijac, void (NAG_CALL *jacobf)(const double *x, const double *eps, const double y[], double f[], const Integer *n),void (NAG_CALL *jacobg)(const double *eps, const double ya[], const double yb[], double aj[], double bj[], const Integer *n),double *deleps, void (NAG_CALL *jaceps)(const double *x, const double *eps, const double y[], double f[], const Integer *n),void (NAG_CALL *jacgep)(const double *eps, const double ya[], const double yb[], double bcep[], const Integer *n),double work[], const Integer *lwork, Integer iwork[], const Integer *liwork, Integer *ifail)
The routine may be called by the names d02raf or nagf_ode_bvp_fd_nonlin_gen.

## 3Description

d02raf solves a two-point 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
 $yi′ = f i x, y 1 , y 2 ,…, y n , i=1,2,…,n$ (1)
and the derivatives ${f}_{i}$ are evaluated by fcn. With the differential equations (1) must be given a system of $n$ (nonlinear) boundary conditions
 $gi ya,yb = 0 , i=1,2,…,n ,$
where
 $y x = y 1 x , y 2 x ,…, y n x T .$ (2)
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
 $∂fi ∂yj , ∂gi ∂yja and ∂gi ∂yjb .$
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
 $y′ = f x,y,ε , g ya,yb,ε = 0 ,$ (3)
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
 $0 = ε1 < ε2 < ⋯ < εp = 1 .$ (4)
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.

## 4References

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

## 5Arguments

1: $\mathbf{n}$Integer Input
On entry: $\mathit{n}$, the number of differential equations.
Constraint: ${\mathbf{n}}>0$.
2: $\mathbf{mnp}$Integer Input
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: $\mathbf{np}$Integer Input/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: $\mathbf{numbeg}$Integer Input
On entry: the number of left-hand boundary conditions (that is the number involving $y\left(a\right)$ only).
Constraint: $0\le {\mathbf{numbeg}}<{\mathbf{n}}$.
5: $\mathbf{nummix}$Integer Input
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: $\mathbf{tol}$Real (Kind=nag_wp) Input
On entry: a positive absolute error tolerance. If
 $a=x1
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
 $zjxi-yjxi≤tol, i=1,2,…,np​ and ​j=1,2,…,n.$ (5)
Constraint: ${\mathbf{tol}}>0.0$.
7: $\mathbf{init}$Integer Input
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: $\mathbf{x}\left({\mathbf{mnp}}\right)$Real (Kind=nag_wp) array Input/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: $\mathbf{y}\left({\mathbf{ldy}},{\mathbf{mnp}}\right)$Real (Kind=nag_wp) array Input/Output
On entry: if ${\mathbf{init}}=0$, y need not be set.
If ${\mathbf{init}}=1$, the array y must contain an initial approximation to the solution such that ${\mathbf{y}}\left(j,i\right)$ contains an approximation to
 $yjxi, i=1,2,…,np​ and ​j=1,2,…,n.$
On exit: the approximate solution ${z}_{j}\left({x}_{i}\right)$ satisfying (5) 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. If an error has occurred then y contains the latest approximation to the solution. The remaining columns of y are not used.
10: $\mathbf{ldy}$Integer Input
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: $\mathbf{abt}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Output
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: $\mathbf{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:
Fortran Interface
 Subroutine fcn ( x, eps, y, f, n)
 Integer, Intent (In) :: n Real (Kind=nag_wp), Intent (In) :: x, eps, y(n) Real (Kind=nag_wp), Intent (Out) :: f(n)
 void fcn_ (const double *x, const double *eps, const double y[], double f[], const Integer *n)
1: $\mathbf{x}$Real (Kind=nag_wp) Input
On entry: $x$, the value of the independent variable.
2: $\mathbf{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: $\mathbf{y}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Input
On entry: ${y}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,\mathit{n}$, the values of the dependent variables at $x$.
4: $\mathbf{f}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Output
On exit: the values of the derivatives ${f}_{\mathit{i}}$ evaluated at $x$ given $\epsilon$, for $\mathit{i}=1,2,\dots ,\mathit{n}$.
5: $\mathbf{n}$Integer Input
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.
Note: fcn should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by d02raf. If your code inadvertently does return any NaNs or infinities, d02raf is likely to produce unexpected results.
13: $\mathbf{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:
Fortran Interface
 Subroutine g ( eps, ya, yb, bc, n)
 Integer, Intent (In) :: n Real (Kind=nag_wp), Intent (In) :: eps, ya(n), yb(n) Real (Kind=nag_wp), Intent (Out) :: bc(n)
 void g_ (const double *eps, const double ya[], const double yb[], double bc[], const Integer *n)
1: $\mathbf{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: $\mathbf{ya}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Input
On entry: the value ${y}_{\mathit{i}}\left(a\right)$, for $\mathit{i}=1,2,\dots ,n$.
3: $\mathbf{yb}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Input
On entry: the value ${y}_{\mathit{i}}\left(b\right)$, for $\mathit{i}=1,2,\dots ,n$.
4: $\mathbf{bc}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Output
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:
1. (i)first, the conditions involving only $y\left(a\right)$ (see numbeg);
2. (ii)next, the nummix coupled conditions involving both $y\left(a\right)$ and $y\left(b\right)$ (see nummix); and,
3. (iii)finally, the conditions involving only $y\left(b\right)$ (${\mathbf{n}}-{\mathbf{numbeg}}-{\mathbf{nummix}}$).
5: $\mathbf{n}$Integer Input
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.
Note: g should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by d02raf. If your code inadvertently does return any NaNs or infinities, d02raf is likely to produce unexpected results.
14: $\mathbf{ijac}$Integer Input
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: $\mathbf{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$, numerical differentiation is used to calculate the Jacobian and the routine d02gaz may be substituted for this argument.
The specification of jacobf is:
Fortran Interface
 Subroutine jacobf ( x, eps, y, f, n)
 Integer, Intent (In) :: n Real (Kind=nag_wp), Intent (In) :: x, eps, y(n) Real (Kind=nag_wp), Intent (Out) :: f(n,n)
 void jacobf_ (const double *x, const double *eps, const double y[], double f[], const Integer *n)
1: $\mathbf{x}$Real (Kind=nag_wp) Input
On entry: $x$, the value of the independent variable.
2: $\mathbf{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: $\mathbf{y}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Input
On entry: ${y}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,\mathit{n}$, the values of the dependent variables at $x$.
4: $\mathbf{f}\left({\mathbf{n}},{\mathbf{n}}\right)$Real (Kind=nag_wp) array Output
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: $\mathbf{n}$Integer Input
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.
Note: jacobf should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by d02raf. If your code inadvertently does return any NaNs or infinities, d02raf is likely to produce unexpected results.
16: $\mathbf{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$, numerical differentiation is used to calculate the Jacobian and the routine d02gay may be substituted for this argument.
The specification of jacobg is:
Fortran Interface
 Subroutine jacobg ( eps, ya, yb, aj, bj, n)
 Integer, Intent (In) :: n Real (Kind=nag_wp), Intent (In) :: eps, ya(n), yb(n) Real (Kind=nag_wp), Intent (Out) :: aj(n,n), bj(n,n)
 void jacobg_ (const double *eps, const double ya[], const double yb[], double aj[], double bj[], const Integer *n)
1: $\mathbf{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: $\mathbf{ya}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Input
On entry: the value ${y}_{\mathit{i}}\left(a\right)$, for $\mathit{i}=1,2,\dots ,n$.
3: $\mathbf{yb}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Input
On entry: the value ${y}_{\mathit{i}}\left(b\right)$, for $\mathit{i}=1,2,\dots ,n$.
4: $\mathbf{aj}\left({\mathbf{n}},{\mathbf{n}}\right)$Real (Kind=nag_wp) array Output
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: $\mathbf{bj}\left({\mathbf{n}},{\mathbf{n}}\right)$Real (Kind=nag_wp) array Output
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: $\mathbf{n}$Integer Input
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.
Note: jacobg should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by d02raf. If your code inadvertently does return any NaNs or infinities, d02raf is likely to produce unexpected results.
17: $\mathbf{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 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 }_{p-1}$ (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: $\mathbf{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:
Fortran Interface
 Subroutine jaceps ( x, eps, y, f, n)
 Integer, Intent (In) :: n Real (Kind=nag_wp), Intent (In) :: x, eps, y(n) Real (Kind=nag_wp), Intent (Out) :: f(n)
 void jaceps_ (const double *x, const double *eps, const double y[], double f[], const Integer *n)
1: $\mathbf{x}$Real (Kind=nag_wp) Input
On entry: $x$, the value of the independent variable.
2: $\mathbf{eps}$Real (Kind=nag_wp) Input
On entry: $\epsilon$, the value of the continuation parameter.
3: $\mathbf{y}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Input
On entry: the solution values ${y}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$, at the point $x$.
4: $\mathbf{f}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Output
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: $\mathbf{n}$Integer Input
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.
Note: jaceps should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by d02raf. If your code inadvertently does return any NaNs or infinities, d02raf is likely to produce unexpected results.
19: $\mathbf{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:
Fortran Interface
 Subroutine jacgep ( eps, ya, yb, bcep, n)
 Integer, Intent (In) :: n Real (Kind=nag_wp), Intent (In) :: eps, ya(n), yb(n) Real (Kind=nag_wp), Intent (Out) :: bcep(n)
 void jacgep_ (const double *eps, const double ya[], const double yb[], double bcep[], const Integer *n)
1: $\mathbf{eps}$Real (Kind=nag_wp) Input
On entry: $\epsilon$, the value of the continuation parameter.
2: $\mathbf{ya}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Input
On entry: the value of ${y}_{\mathit{i}}\left(a\right)$, for $\mathit{i}=1,2,\dots ,n$.
3: $\mathbf{yb}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Input
On entry: the value of ${y}_{\mathit{i}}\left(b\right)$, for $\mathit{i}=1,2,\dots ,n$.
4: $\mathbf{bcep}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Output
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: $\mathbf{n}$Integer Input
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.
Note: jacgep should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by d02raf. If your code inadvertently does return any NaNs or infinities, d02raf is likely to produce unexpected results.
20: $\mathbf{work}\left({\mathbf{lwork}}\right)$Real (Kind=nag_wp) array Workspace
21: $\mathbf{lwork}$Integer Input
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}}×\left(3{{\mathbf{n}}}^{2}+6{\mathbf{n}}+2\right)+4{{\mathbf{n}}}^{2}+3{\mathbf{n}}$.
22: $\mathbf{iwork}\left({\mathbf{liwork}}\right)$Integer array Workspace
23: $\mathbf{liwork}$Integer Input
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}}×\left(2×{\mathbf{n}}+1\right)+{\mathbf{n}}$;
• if ${\mathbf{ijac}}=0$, ${\mathbf{liwork}}\ge {\mathbf{mnp}}×\left(2×{\mathbf{n}}+1\right)+{{\mathbf{n}}}^{2}+4×{\mathbf{n}}+2$.
24: $\mathbf{ifail}$Integer Input/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 4 in the Introduction to the NAG Library FL Interface).
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).

## 6Error 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$
On entry, ${\mathbf{liwork}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{liwork}}\ge 〈\mathit{\text{value}}〉$.
On entry, ${\mathbf{lwork}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{lwork}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{np}},32\right)×\left(3×{{\mathbf{n}}}^{2}+6×{\mathbf{n}}+2\right)+4×{{\mathbf{n}}}^{2}+3×{\mathbf{n}}$; that is, $〈\mathit{\text{value}}〉$.
On entry, ${\mathbf{mnp}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{mnp}}\ge 32$.
On entry, ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{n}}\ge 1$.
On entry, ${\mathbf{np}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{np}}\ge 4$.
On entry, ${\mathbf{np}}=〈\mathit{\text{value}}〉$ and ${\mathbf{mnp}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{np}}\le {\mathbf{mnp}}$.
On entry, ${\mathbf{numbeg}}=〈\mathit{\text{value}}〉$, ${\mathbf{nummix}}=〈\mathit{\text{value}}〉$ and ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{numbeg}}+{\mathbf{nummix}}\le {\mathbf{n}}$.
On entry, ${\mathbf{numbeg}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{numbeg}}\ge 0$.
On entry, ${\mathbf{numbeg}}=〈\mathit{\text{value}}〉$ and ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{numbeg}}<{\mathbf{n}}$.
On entry, ${\mathbf{nummix}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{nummix}}\ge 0$.
On entry, ${\mathbf{tol}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{tol}}>0.0$.
On entry, ${\mathbf{x}}\left(1\right)=〈\mathit{\text{value}}〉$ and ${\mathbf{x}}\left({\mathbf{np}}\right)=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{x}}\left(1\right)<{\mathbf{x}}\left({\mathbf{np}}\right)$.
On entry the mesh points are not in strictly ascending order.
For $i=〈\mathit{\text{value}}〉$, mesh point $i=〈\mathit{\text{value}}〉$, but mesh point $i+1=〈\mathit{\text{value}}〉$.
${\mathbf{ifail}}=2$
A finer mesh is required for the accuracy requested; that is, ${\mathbf{mnp}}=〈\mathit{\text{value}}〉$ is not large enough.
${\mathbf{ifail}}=3$
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 or you cannot make changes to prevent this error, you should use the routine with a continuation facility instead.
${\mathbf{ifail}}=4$
Newton iteration has reached round-off level.
If desired accuracy has not been reached, tol is too small for this problem and this machine precision.
${\mathbf{ifail}}=5$
The Jacobian for the boundary conditions is singular.
This may occur due to faulty coding of the Jacobian or, in some circumstances, to a zero initial choice of approximate solution.
${\mathbf{ifail}}=6$
There is no dependence on the continuation parameter when continuation is being used. This can be due to faulty coding of derivatives with respect to the continuation parameter or to a zero initial choice of approximate solution.
${\mathbf{ifail}}=7$
The continuation step is required to be less than machine precision for continuation to proceed. It is likely that either the problem has no solution for some value of the continuation parameter near the current value or that the problem is so difficult that even with continuation it is unlikely to be solved using this routine. In the latter case using more mesh points initially may help.
${\mathbf{ifail}}=8$
A serious error occurred in a call to the internal integrator.
The error code internally was $〈\mathit{\text{value}}〉$.
${\mathbf{ifail}}=9$
A continuation error occurred, but continuation is not being used.
${\mathbf{ifail}}=-99$
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-399$
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.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

## 7Accuracy

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.

## 8Parallelism and Performance

d02raf 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.

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 self-explanatory 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 5 in the Introduction to the NAG Library FL Interface 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.

## 10Example

This example solves the differential equation
 $y′′′=-yy′′-2ε1-y′2$
with $\epsilon =1$ and boundary conditions
 $y0=y′0=0, y′10=1$
to an accuracy specified by ${\mathbf{tol}}=\text{1.0E−4}$. 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.1Program Text

Program Text (d02rafe.f90)

### 10.2Program Data

Program Data (d02rafe.d)

### 10.3Program Results

Program Results (d02rafe.r)