NAG FL Interface
d02gaf (bvp_fd_nonlin_fixedbc)
1
Purpose
d02gaf solves a twopoint 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
Fortran Interface
Subroutine d02gaf ( 
u, v, n, a, b, tol, fcn, mnp, x, y, np, w, lw, iw, liw, ifail) 
Integer, Intent (In) 
:: 
n, mnp, lw, liw 
Integer, Intent (Inout) 
:: 
np, ifail 
Integer, Intent (Out) 
:: 
iw(liw) 
Real (Kind=nag_wp), Intent (In) 
:: 
u(n,2), v(n,2), a, b, tol 
Real (Kind=nag_wp), Intent (Inout) 
:: 
x(mnp) 
Real (Kind=nag_wp), Intent (Out) 
:: 
y(n,mnp), w(lw) 
External 
:: 
fcn 

C Header Interface
#include <nag.h>
void 
d02gaf_ (const double u[], const double v[], const Integer *n, const double *a, const double *b, const double *tol, void (NAG_CALL *fcn)(const double *x, const double y[], double f[]), const Integer *mnp, double x[], double y[], Integer *np, double w[], const Integer *lw, Integer iw[], const Integer *liw, Integer *ifail) 

C++ Header Interface
#include <nag.h> extern "C" {
void 
d02gaf_ (const double u[], const double v[], const Integer &n, const double &a, const double &b, const double &tol, void (NAG_CALL *fcn)(const double &x, const double y[], double f[]), const Integer &mnp, double x[], double y[], Integer &np, double w[], const Integer &lw, Integer iw[], const Integer &liw, Integer &ifail) 
}

The routine may be called by the names d02gaf or nagf_ode_bvp_fd_nonlin_fixedbc.
3
Description
d02gaf solves a twopoint boundary value problem for a system of
$\mathit{n}$ differential equations in the interval [
$a,b$]. The system is written in the form:
and the derivatives
${f}_{i}$ are evaluated by
fcn. Initially,
$\mathit{n}$ boundary values of the variables
${y}_{i}$ must be specified, some at
$a$ and some at
$b$. You must supply estimates of the remaining
$\mathit{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
$\frac{\partial {f}_{i}}{\partial {y}_{j}}$ 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 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:
$\mathbf{u}\left({\mathbf{n}},2\right)$ – Real (Kind=nag_wp) array
Input

On entry: ${\mathbf{u}}\left(\mathit{i},1\right)$ must be set to the known or estimated value of ${y}_{\mathit{i}}$ at $a$ and ${\mathbf{u}}\left(\mathit{i},2\right)$ must be set to the known or estimated value of ${y}_{\mathit{i}}$ at $b$, for $\mathit{i}=1,2,\dots ,\mathit{n}$.

2:
$\mathbf{v}\left({\mathbf{n}},2\right)$ – Real (Kind=nag_wp) array
Input

On entry: ${\mathbf{v}}\left(\mathit{i},\mathit{j}\right)$ must be set to $0.0$ if ${\mathbf{u}}\left(\mathit{i},\mathit{j}\right)$ is a known value and to $1.0$ if ${\mathbf{u}}\left(\mathit{i},\mathit{j}\right)$ is an estimated value, for $\mathit{i}=1,2,\dots ,\mathit{n}$ and $\mathit{j}=1,2$.
Constraint:
precisely $\mathit{n}$ of the ${\mathbf{v}}\left(i,j\right)$ must be set to $0.0$, i.e., precisely $\mathit{n}$ of the ${\mathbf{u}}\left(i,j\right)$ must be known values, and these must not be all at $a$ or all at $b$.

3:
$\mathbf{n}$ – Integer
Input

On entry: $\mathit{n}$, the number of equations.
Constraint:
${\mathbf{n}}\ge 2$.

4:
$\mathbf{a}$ – Real (Kind=nag_wp)
Input

On entry: $a$, the lefthand boundary point.

5:
$\mathbf{b}$ – Real (Kind=nag_wp)
Input

On entry: $b$, the righthand boundary point.
Constraint:
${\mathbf{b}}>{\mathbf{a}}$.

6:
$\mathbf{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 equation
(1) (see
Section 3) and the boundary conditions, then, except in extreme cases, it is expected that
Constraint:
${\mathbf{tol}}>0.0$.

7:
$\mathbf{fcn}$ – Subroutine, supplied by the user.
External Procedure

fcn must evaluate the functions
${f}_{\mathit{i}}$ (i.e., the derivatives
${y}_{\mathit{i}}^{\prime}$), for
$\mathit{i}=1,2,\dots ,\mathit{n}$, at a general point
$x$.
The specification of
fcn is:
Fortran Interface
Subroutine fcn ( 
x, y, f) 
Real (Kind=nag_wp), Intent (In) 
:: 
x, y(*) 
Real (Kind=nag_wp), Intent (Out) 
:: 
f(*) 

C Header Interface
void 
fcn_ (const double *x, const double y[], double f[]) 

C++ Header Interface
#include <nag.h> extern "C" {
void 
fcn_ (const double &x, const double y[], double f[]) 
}

In the description of the arguments of
d02gaf below,
$\mathit{n}$ denotes the actual value of
n in the call of
d02gaf.

1:
$\mathbf{x}$ – Real (Kind=nag_wp)
Input

On entry: $x$, the value of the argument.

2:
$\mathbf{y}\left(*\right)$ – Real (Kind=nag_wp) array
Input

On entry: ${y}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,\mathit{n}$, the value of the argument.

3:
$\mathbf{f}\left(*\right)$ – Real (Kind=nag_wp) array
Output

On exit: the values of
${f}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,\mathit{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.
Note: fcn should not return floatingpoint 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:
$\mathbf{mnp}$ – Integer
Input

On entry: the maximum permitted number of mesh points.
Constraint:
${\mathbf{mnp}}\ge 32$.

9:
$\mathbf{x}\left({\mathbf{mnp}}\right)$ – Real (Kind=nag_wp) array
Input/Output

On entry: if
${\mathbf{np}}\ge 4$ (see
np), the first
np elements must define an initial mesh. Otherwise the elements of
x need not be set.
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) satisfying the relation
(3).

10:
$\mathbf{y}\left({\mathbf{n}},{\mathbf{mnp}}\right)$ – Real (Kind=nag_wp) array
Output

On exit: the approximate solution
${z}_{j}\left({x}_{i}\right)$ satisfying
(2), on the final mesh, that is
where
np is the number of points in the final mesh.
The remaining columns of
y are not used.

11:
$\mathbf{np}$ – Integer
Input/Output

On entry: determines whether a default or usersupplied mesh is used.
 ${\mathbf{np}}=0$
 A default value of $4$ for np and a corresponding equispaced mesh ${\mathbf{x}}\left(1\right),{\mathbf{x}}\left(2\right),\dots ,{\mathbf{x}}\left({\mathbf{np}}\right)$ are used.
 ${\mathbf{np}}\ge 4$
 You must define an initial mesh using the array x as described.
Constraint:
${\mathbf{np}}=0$ or $4\le {\mathbf{np}}\le {\mathbf{mnp}}$.
On exit: the number of points in the final (returned) mesh.

12:
$\mathbf{w}\left({\mathbf{lw}}\right)$ – Real (Kind=nag_wp) array
Workspace

13:
$\mathbf{lw}$ – Integer
Input

On entry: the dimension of the array
w as declared in the (sub)program from which
d02gaf is called.
Constraint:
${\mathbf{lw}}\ge {\mathbf{mnp}}\times \left(3{{\mathbf{n}}}^{2}+6{\mathbf{n}}+2\right)+4{{\mathbf{n}}}^{2}+4{\mathbf{n}}$.

14:
$\mathbf{iw}\left({\mathbf{liw}}\right)$ – Integer array
Workspace

15:
$\mathbf{liw}$ – Integer
Input

On entry: the dimension of the array
iw as declared in the (sub)program from which
d02gaf is called.
Constraint:
${\mathbf{liw}}\ge {\mathbf{mnp}}\times \left(2{\mathbf{n}}+1\right)+{{\mathbf{n}}}^{2}+4{\mathbf{n}}+2$.

16:
$\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).
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$

On entry, ${\mathbf{a}}=\u2329\mathit{\text{value}}\u232a$ and ${\mathbf{b}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{b}}>{\mathbf{a}}$.
On entry, ${\mathbf{liw}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{liw}}\ge {\mathbf{mnp}}\times \left(2\times {\mathbf{n}}+1\right)+{{\mathbf{n}}}^{2}+4\times {\mathbf{n}}+2$; that is, $\u2329\mathit{\text{value}}\u232a$.
On entry, ${\mathbf{lw}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{lw}}\ge {\mathbf{mnp}}\times \left(3\times {{\mathbf{n}}}^{2}+6\times {\mathbf{n}}+2\right)+4\times {{\mathbf{n}}}^{2}+4\times {\mathbf{n}}$; that is, $\u2329\mathit{\text{value}}\u232a$.
On entry, ${\mathbf{mnp}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{mnp}}\ge 32$.
On entry, ${\mathbf{n}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{n}}\ge 2$.
On entry, ${\mathbf{np}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{np}}=0$ or ${\mathbf{np}}\ge 4$.
On entry, ${\mathbf{np}}=\u2329\mathit{\text{value}}\u232a$ and ${\mathbf{mnp}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{np}}\le {\mathbf{mnp}}$.
On entry, ${\mathbf{tol}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{tol}}>0.0$.
On entry: ${\mathbf{a}}=\u2329\mathit{\text{value}}\u232a$ and ${\mathbf{x}}\left(1\right)=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{a}}={\mathbf{x}}\left(1\right)<{\mathbf{x}}\left(2\right)<\cdots <{\mathbf{x}}\left({\mathbf{np}}\right)={\mathbf{b}}\text{, \hspace{1em}}{\mathbf{np}}\ge 4$.
On entry: ${\mathbf{b}}=\u2329\mathit{\text{value}}\u232a$ and ${\mathbf{x}}\left({\mathbf{np}}\right)=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{a}}={\mathbf{x}}\left(1\right)<{\mathbf{x}}\left(2\right)<\cdots <{\mathbf{x}}\left({\mathbf{np}}\right)={\mathbf{b}}\text{, \hspace{1em}}{\mathbf{np}}\ge 4$.
The number of known left boundary values must be less than the number of equations: the number of known left boundary values $\text{}=\u2329\mathit{\text{value}}\u232a$, the number of equations $\text{}=\u2329\mathit{\text{value}}\u232a$.
The number of known right boundary values must be less than the number of equations: the number of known right boundary values $\text{}=\u2329\mathit{\text{value}}\u232a$, the number of equations $\text{}=\u2329\mathit{\text{value}}\u232a$.
The sequence
x is not strictly increasing. For
$i=\u2329\mathit{\text{value}}\u232a$,
${\mathbf{x}}\left(i\right)=\u2329\mathit{\text{value}}\u232a$ and
${\mathbf{x}}\left(i+1\right)=\u2329\mathit{\text{value}}\u232a$.
The sum of known left and right boundary values must equal the number of equations: the number of known left boundary values $\text{}=\u2329\mathit{\text{value}}\u232a$, the number of known right boundary values $\text{}=\u2329\mathit{\text{value}}\u232a$, the number of equations $\text{}=\u2329\mathit{\text{value}}\u232a$.
 ${\mathbf{ifail}}=2$

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}}=3$

Newton iteration has reached roundoff level.
If desired accuracy has not been reached,
tol is too small for this problem and this
machine precision.
 ${\mathbf{ifail}}=4$

A finer mesh is required for the accuracy requested; that is, ${\mathbf{mnp}}=\u2329\mathit{\text{value}}\u232a$ is not large enough.
 ${\mathbf{ifail}}=5$

A serious error occurred in a call to the internal integrator.
The error code internally was
$\u2329\mathit{\text{value}}\u232a$. Please contact
NAG.
 ${\mathbf{ifail}}=99$
An unexpected error has been triggered by this routine. Please
contact
NAG.
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.
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 1 in FL Interface Multithreading 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 implementationspecific 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 selfexplanatory 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
for
$\beta =0.0$ and
$\beta =0.2$ to an accuracy specified by
${\mathbf{tol}}=\text{1.0E\u22123}$. We solve first the simpler problem with
$\beta =0.0$ using an equispaced mesh of
$26$ points and then we solve the problem with
$\beta =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
10.2
Program Data
10.3
Program Results