The function may be called by the names: d02gbc or nag_ode_bvp_fd_lin_gen.
3Description
d02gbc solves the linear two-point boundary value problem for a system of neq ordinary differential equations in the interval $[a,b]$. The system is written in the form
$${y}^{\prime}=F\left(x\right)y+g\left(x\right)$$
(1)
and the boundary conditions are written in the form
$$Cy\left(a\right)+Dy\left(b\right)=\gamma $$
(2)
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.
4References
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{neq}$ – IntegerInput
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 userExternal Function
fcnf must evaluate the matrix $F\left(x\right)$ in (1) at a general point $x$.
On exit: the $(i,j)$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[(i-1)\times {\mathbf{neq}}+(j-1)\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 floating-point 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 userExternal Function
fcng must evaluate the vector $g\left(x\right)$ in (1) at a general point $x$.
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 floating-point 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.
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 re-ordered 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 $[C,D]$ must be neq for the problem to be properly posed. Any violation of these conditions will lead to an error exit.
9: $\mathbf{mnp}$ – IntegerInput
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 user-supplied 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.
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).
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
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).
6Error Indicators and Warnings
NE_2_REAL_ARG_LE
On entry, ${\mathbf{b}}=\u27e8\mathit{\text{value}}\u27e9$ while ${\mathbf{a}}=\u27e8\mathit{\text{value}}\u27e9$. 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 $[C,D]$ are identically zero. i.e., the boundary conditions are rank deficient. The number of non-identically zero columns is $\u27e8\mathit{\text{value}}\u27e9$.
NE_BOUND_COND_LC
At least one row of the neq by $2\times {\mathbf{neq}}$ matrix $[C,D]$ is a linear combination of the other rows, i.e., the boundary conditions are rank deficient. The index of the first such row is $\u27e8\mathit{\text{value}}\u27e9$.
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 $[C,D]$ 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 $\u27e8\mathit{\text{value}}\u27e9$. 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
Row $\u27e8\mathit{\text{value}}\u27e9$ 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}}=\u27e8\mathit{\text{value}}\u27e9$.
Constraint: ${\mathbf{mnp}}\ge 32$.
On entry, ${\mathbf{neq}}=\u27e8\mathit{\text{value}}\u27e9$.
Constraint: ${\mathbf{neq}}\ge 2$.
NE_INT_RANGE_CONS_2
On entry, ${\mathbf{np}}=\u27e8\mathit{\text{value}}\u27e9$ and ${\mathbf{mnp}}=\u27e8\mathit{\text{value}}\u27e9$. 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}}=\u27e8\mathit{\text{value}}\u27e9$, ${\mathbf{x}}\left[0\right]=\u27e8\mathit{\text{value}}\u27e9$.
NE_NOT_STRICTLY_INCREASING
The sequence x is not strictly increasing: ${\mathbf{x}}\left[\u27e8\mathit{\text{value}}\u27e9\right]=\u27e8\mathit{\text{value}}\u27e9$, ${\mathbf{x}}\left[\u27e8\mathit{\text{value}}\u27e9\right]=\u27e8\mathit{\text{value}}\u27e9$.
NE_REAL_ARG_LE
On entry, tol must not be less than or equal to 0.0: ${\mathbf{tol}}=\u27e8\mathit{\text{value}}\u27e9$.
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}}=\u27e8\mathit{\text{value}}\u27e9$, ${\mathbf{x}}\left[{\mathbf{np}}-1\right]=\u27e8\mathit{\text{value}}\u27e9$.
7Accuracy
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.
8Parallelism and Performance
d02gbc is not threaded in any implementation.
9Further Comments
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.
10Example
We solve the problem (written as a first order system)
$$\epsilon {y}^{\prime \prime}+{y}^{\prime}=0$$
with boundary conditions
$$y\left(0\right)=0,y\left(1\right)=1$$
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}$.