NAG CL Interface
d02gbc (bvp_fd_lin_gen)
1
Purpose
d02gbc solves a general linear twopoint boundary value problem for a system of ordinary differential equations using a deferred correction technique.
2
Specification
void 
d02gbc (Integer neq,
double a,
double b,
double c[],
double d[],
double gam[],
Integer mnp,
Integer *np,
double x[],
double y[],
double tol,
Nag_User *comm,
NagError *fail) 

The function may be called by the names: d02gbc or nag_ode_bvp_fd_lin_gen.
3
Description
d02gbc solves the linear twopoint boundary value problem for a system of
neq ordinary differential equations in the interval
$\left[a,b\right]$. The system is written in the form
and the boundary conditions are written in the form
Here
$F\left(x\right)$,
$C$ and
$D$ are
neq by
neq matrices, and
$g\left(x\right)$ and
$\gamma $ are
neq component vectors. The approximate solution to
(1) and
(2) is found using a finite difference method with deferred correction. The algorithm is a specialisation of that used in the function
d02rac which solves a nonlinear version of
(1) and
(2). The nonlinear version of the algorithm is described fully in
Pereyra (1979).
You need to 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 functions provided in
Chapter E01 if these points do not themselves form a convenient mesh.
4
References
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{neq}$ – Integer
Input

On entry: the number of equations; that is
neq is the order of system
(1).
Constraint:
${\mathbf{neq}}\ge 2$.

2:
$\mathbf{fcnf}$ – function, supplied by the user
External Function

fcnf must evaluate the matrix
$F\left(x\right)$ in
(1) at a general point
$x$.
The specification of
fcnf is:
void 
fcnf (Integer neq,
double x,
double f[],
Nag_User *comm)



1:
$\mathbf{neq}$ – Integer
Input

On entry: the number of differential equations.

2:
$\mathbf{x}$ – double
Input

On entry: the value of the independent variable $x$.

3:
$\mathbf{f}\left[{\mathbf{neq}}\times {\mathbf{neq}}\right]$ – double
Output

On exit: the
$\left(i,j\right)$th element of the matrix
$F\left(x\right)$, for
$i,j=1,2,\dots ,{\mathbf{neq}}$ where
${F}_{ij}$ is set by
${\mathbf{f}}\left[\left(i1\right)\times {\mathbf{neq}}+\left(j1\right)\right]$. (See
Section 10 for an example.)

4:
$\mathbf{comm}$ – Nag_User *

Pointer to a structure of type Nag_User with the following member:
 p – Pointer

On entry/exit: the pointer
$\mathbf{comm}\mathbf{\to}\mathbf{p}$ should be cast to the required type, e.g.,
struct user *s = (struct user *)comm → p, to obtain the original object's address with appropriate type. (See the argument
comm below.)
Note: fcnf should not return floatingpoint NaN (Not a Number) or infinity values, since these are not handled by
d02gbc. If your code inadvertently
does return any NaNs or infinities,
d02gbc is likely to produce unexpected results.

3:
$\mathbf{fcng}$ – function, supplied by the user
External Function

fcng must evaluate the vector
$g\left(x\right)$ in
(1) at a general point
$x$.
The specification of
fcng is:
void 
fcng (Integer neq,
double x,
double g[],
Nag_User *comm)



1:
$\mathbf{neq}$ – Integer
Input

On entry: the number of differential equations.

2:
$\mathbf{x}$ – double
Input

On entry: the value of the independent variable $x$.

3:
$\mathbf{g}\left[{\mathbf{neq}}\right]$ – double
Output

On exit: the
$\mathit{i}$th element of the vector
$g\left(x\right)$, for
$\mathit{i}=1,2,\dots ,{\mathbf{neq}}$. (See
Section 10 for an example.)

4:
$\mathbf{comm}$ – Nag_User *

Pointer to a structure of type Nag_User with the following member:
 p – Pointer

On entry/exit: the pointer
$\mathbf{comm}\mathbf{\to}\mathbf{p}$ should be cast to the required type, e.g.,
struct user *s = (struct user *)comm → p, to obtain the original object's address with appropriate type. (See the argument
comm below.)
Note: fcng should not return floatingpoint NaN (Not a Number) or infinity values, since these are not handled by
d02gbc. If your code inadvertently
does return any NaNs or infinities,
d02gbc is likely to produce unexpected results.
If you do not wish to supply
fcng the actual argument
fcng must be the NAG defined null function pointer
NULLFN.

4:
$\mathbf{a}$ – double
Input

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

5:
$\mathbf{b}$ – double
Input

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

6:
$\mathbf{c}\left[{\mathbf{neq}}\times {\mathbf{neq}}\right]$ – double
Input/Output

7:
$\mathbf{d}\left[{\mathbf{neq}}\times {\mathbf{neq}}\right]$ – double
Input/Output

8:
$\mathbf{gam}\left[{\mathbf{neq}}\right]$ – double
Input/Output

On entry: the arrays
c and
d must be set to the matrices
$C$ and
$D$ in
(2).
gam must be set to the vector
$\gamma $ in
(2).
On exit: the rows of
c and
d and the components of
gam are reordered so that the boundary conditions are in the order:

(i)conditions on $y\left(a\right)$ only;

(ii)condition involving $y\left(a\right)$ and $y\left(b\right)$; and

(iii)conditions on $y\left(b\right)$ only.
The function will be slightly more efficient if the arrays
c,
d and
gam are ordered in this way before entry, and in this event they will be unchanged on exit.
Note that the boundary conditions must be of boundary value type, that is neither
$C$ nor
$D$ may be identically zero. Note also that the rank of the matrix
$\left[C,D\right]$ must be
neq for the problem to be properly posed. Any violation of these conditions will lead to an error exit.

9:
$\mathbf{mnp}$ – Integer
Input

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

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

On entry: determines whether a default or usersupplied initial mesh is used.
 ${\mathbf{np}}=0$
 np is set to a default value of 4 and a corresponding equispaced mesh ${\mathbf{x}}\left[0\right],{\mathbf{x}}\left[1\right],\dots ,{\mathbf{x}}\left[{\mathbf{np}}1\right]$ is 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.

11:
$\mathbf{x}\left[{\mathbf{mnp}}\right]$ – double
Input/Output

On entry: if
${\mathbf{np}}\ge 4$ (see
np above), the first
np elements must define an initial mesh. Otherwise the elements of
x need not be set.
Constraint:
for
${\mathbf{np}}\ge 4$.
On exit:
${\mathbf{x}}\left[0\right],{\mathbf{x}}\left[1\right],\dots ,{\mathbf{x}}\left[{\mathbf{np}}1\right]$ define the final mesh (with the returned value of
np) satisfying the relation
(3).

12:
$\mathbf{y}\left[{\mathbf{neq}}\times {\mathbf{mnp}}\right]$ – double
Output

On exit: the approximate solution
${z}_{j}\left({x}_{i}\right)$ satisfying
(4), 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.

13:
$\mathbf{tol}$ – double
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}_{i}\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$.

14:
$\mathbf{comm}$ – Nag_User *

Pointer to a structure of type Nag_User with the following member:
 p – Pointer

On entry/exit: the pointer
$\mathbf{comm}\mathbf{\to}\mathbf{p}$, of type Pointer, allows you to communicate information to and from
fcnf and
fcng. An object of the required type should be declared, e.g., a structure, and its address assigned to the pointer
$\mathbf{comm}\mathbf{\to}\mathbf{p}$ by means of a cast to Pointer in the calling program, e.g.,
comm.p = (Pointer)&s. The type pointer will be
void * with a C compiler that defines
void * and
char * otherwise.

15:
$\mathbf{fail}$ – NagError *
Input/Output

The NAG error argument (see
Section 7 in the Introduction to the NAG Library CL Interface).
6
Error Indicators and Warnings
 NE_2_REAL_ARG_LE

On entry, ${\mathbf{b}}=\u2329\mathit{\text{value}}\u232a$ while ${\mathbf{a}}=\u2329\mathit{\text{value}}\u232a$. These arguments must satisfy ${\mathbf{b}}>{\mathbf{a}}$.
 NE_ALLOC_FAIL

Dynamic memory allocation failed.
 NE_BOUND_COND_COL

More than
neq columns of the
neq by
$2\times {\mathbf{neq}}$ matrix
$\left[C,D\right]$ are identically zero. i.e., the boundary conditions are rank deficient. The number of nonidentically zero columns is
$\u2329\mathit{\text{value}}\u232a$.
 NE_BOUND_COND_LC

At least one row of the
neq by
$2\times {\mathbf{neq}}$ matrix
$\left[C,D\right]$ is a linear combination of the other rows, i.e., the boundary conditions are rank deficient. The index of the first such row is
$\u2329\mathit{\text{value}}\u232a$.
 NE_BOUND_COND_MAT

One of the matrices $C$ or $D$ is identically zero, i.e., the problem is of initial value and not of the boundary type.
 NE_BOUND_COND_NLC

At least one row of the
neq by
$2\times {\mathbf{neq}}$ matrix
$\left[C,D\right]$ is a linear combination of the other rows determined up to a numerical tolerance, i.e., the boundary conditions are rank deficient. The index of first such row is
$\u2329\mathit{\text{value}}\u232a$. There is some doubt as to the rank deficiency of the boundary conditions. However even if the boundary conditions are not rank deficient they are not posed in a suitable form for use with this function. For example, if
and
$\epsilon $ is small enough, this error exit is likely to be taken. A better form for the boundary conditions in this case would be
 NE_BOUND_COND_ROW

Row
$\u2329\mathit{\text{value}}\u232a$ of the array
c and the corresponding row of array
d are identically zero, i.e., the boundary conditions are rank deficient.
 NE_CONV_MESH

A finer mesh is required for the accuracy requested; that is
mnp is not large enough.
 NE_CONV_MESH_INIT

The Newton iteration failed to converge on the initial mesh. This may be due to the initial mesh having too few points or the initial approximate solution being too inaccurate. Try using
d02rac.
 NE_CONV_ROUNDOFF

Solution cannot be improved due to roundoff error. Too much accuracy might have been requested.
 NE_INT_ARG_LT

On entry, ${\mathbf{mnp}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{mnp}}\ge 32$.
On entry, ${\mathbf{neq}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{neq}}\ge 2$.
 NE_INT_RANGE_CONS_2

On entry,
${\mathbf{np}}=\u2329\mathit{\text{value}}\u232a$ and
${\mathbf{mnp}}=\u2329\mathit{\text{value}}\u232a$. The argument
np must satisfy either
$4\le {\mathbf{np}}\le {\mathbf{mnp}}$ or
${\mathbf{np}}=0$.
 NE_INTERNAL_ERROR

An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact
NAG for assistance.
 NE_LF_B_MESH

On entry, the left boundary value
a, has not been set to
${\mathbf{x}}\left[0\right]$:
${\mathbf{a}}=\u2329\mathit{\text{value}}\u232a$,
${\mathbf{x}}\left[0\right]=\u2329\mathit{\text{value}}\u232a$.
 NE_NOT_STRICTLY_INCREASING

The sequence
x is not strictly increasing:
${\mathbf{x}}\left[\u2329\mathit{\text{value}}\u232a\right]=\u2329\mathit{\text{value}}\u232a$,
${\mathbf{x}}\left[\u2329\mathit{\text{value}}\u232a\right]=\u2329\mathit{\text{value}}\u232a$.
 NE_REAL_ARG_LE

On entry,
tol must not be less than or equal to 0.0:
${\mathbf{tol}}=\u2329\mathit{\text{value}}\u232a$.
 NE_RT_B_MESH

On entry, the right boundary value
b, has not been set to
${\mathbf{x}}\left[{\mathbf{np}}1\right]$:
${\mathbf{b}}=\u2329\mathit{\text{value}}\u232a$,
${\mathbf{x}}\left[{\mathbf{np}}1\right]=\u2329\mathit{\text{value}}\u232a$.
7
Accuracy
The solution returned by the function will be accurate to your tolerance as defined by the relation
(4) 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
d02gbc is not threaded in any implementation.
The time taken by the function depends on the difficulty of the problem, the number of mesh points (and meshes) used and the number of deferred corrections.
In the case where you wish to solve a sequence of similar problems, the use of the final mesh from one case is strongly recommended as the initial mesh for the next.
10
Example
We solve the problem (written as a first order system)
with boundary conditions
for the cases
$\epsilon ={10}^{1}$ and
$\epsilon ={10}^{2}$ using the default initial mesh in the first case, and the final mesh of the first case as initial mesh for the second (more difficult) case. We give the solution and the error at each mesh point to illustrate the accuracy of the method given the accuracy request
${\mathbf{tol}}=\text{1.0e\u22123}$.
10.1
Program Text
10.2
Program Data
None.
10.3
Program Results