NAG FL Interface
d02gbf (bvp_fd_lin_gen)
1
Purpose
d02gbf solves a general linear two-point boundary value problem for a system of ordinary differential equations, using a deferred correction technique.
2
Specification
Fortran Interface
Subroutine d02gbf ( |
a, b, n, tol, fcnf, fcng, c, d, gam, 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) |
:: |
a, b, tol |
Real (Kind=nag_wp), Intent (Inout) |
:: |
c(n,n), d(n,n), gam(n), x(mnp) |
Real (Kind=nag_wp), Intent (Out) |
:: |
y(n,mnp), w(lw) |
External |
:: |
fcnf, fcng |
|
C Header Interface
#include <nag.h>
void |
d02gbf_ (const double *a, const double *b, const Integer *n, const double *tol, void (NAG_CALL *fcnf)(const double *x, double f[]), void (NAG_CALL *fcng)(const double *x, double g[]), double c[], double d[], double gam[], 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 |
d02gbf_ (const double &a, const double &b, const Integer &n, const double &tol, void (NAG_CALL *fcnf)(const double &x, double f[]), void (NAG_CALL *fcng)(const double &x, double g[]), double c[], double d[], double gam[], 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 d02gbf or nagf_ode_bvp_fd_lin_gen.
3
Description
d02gbf solves a linear two-point boundary value problem for a system of
ordinary differential equations in the interval [
]. The system is written in the form
and the boundary conditions are written in the form
Here
,
and
are
by
matrices, and
and
are
-component vectors. The approximate solution to
(1) and
(2) is found using a finite difference method with deferred correction. The algorithm is a specialization of that used in subroutine
d02raf which solves a nonlinear version of
(1) and
(2). The nonlinear version of the algorithm is described fully in
Pereyra (1979).
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
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
5
Arguments
-
1:
– Real (Kind=nag_wp)
Input
-
On entry: , the left-hand boundary point.
-
2:
– Real (Kind=nag_wp)
Input
-
On entry: , the right-hand boundary point.
Constraint:
.
-
3:
– Integer
Input
-
On entry: the number of equations; that is
is the order of system
(1).
Constraint:
.
-
4:
– Real (Kind=nag_wp)
Input
-
On entry: a positive absolute error tolerance. If
is the final mesh,
is the approximate solution from
d02gbf and
is the true solution of equations
(1) and
(2) then, except in extreme cases, it is expected that
where
Constraint:
.
-
5:
– Subroutine, supplied by the user.
External Procedure
-
fcnf must evaluate the matrix
in
(1) at a general point
.
The specification of
fcnf is:
Fortran Interface
Real (Kind=nag_wp), Intent (In) |
:: |
x |
Real (Kind=nag_wp), Intent (Out) |
:: |
f(*) |
|
C Header Interface
void |
fcnf_ (const double *x, double f[]) |
|
C++ Header Interface
#include <nag.h> extern "C" {
void |
fcnf_ (const double &x, double f[]) |
}
|
In the description of the arguments of
d02gbf below,
denotes the actual value of
n in the call of
d02gbf.
-
1:
– Real (Kind=nag_wp)
Input
-
On entry: , the value of the independent variable.
-
2:
– Real (Kind=nag_wp) array
Output
-
On exit:
must contain the
th element of the matrix
, for
and
. (See
Section 10 for an example.)
fcnf must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which
d02gbf is called. Arguments denoted as
Input must
not be changed by this procedure.
Note: fcnf should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by
d02gbf. If your code inadvertently
does return any NaNs or infinities,
d02gbf is likely to produce unexpected results.
-
6:
– Subroutine, supplied by the user.
External Procedure
-
fcng must evaluate the vector
in
(1) at a general point
.
The specification of
fcng is:
Fortran Interface
Real (Kind=nag_wp), Intent (In) |
:: |
x |
Real (Kind=nag_wp), Intent (Out) |
:: |
g(*) |
|
C Header Interface
void |
fcng_ (const double *x, double g[]) |
|
C++ Header Interface
#include <nag.h> extern "C" {
void |
fcng_ (const double &x, double g[]) |
}
|
In the description of the arguments of
d02gbf below,
denotes the actual value of
n in the call of
d02gbf.
-
1:
– Real (Kind=nag_wp)
Input
-
On entry: , the value of the independent variable.
-
2:
– Real (Kind=nag_wp) array
Output
-
On exit: the
th element of the vector
, for
. (See
Section 10 for an example.)
fcng must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which
d02gbf is called. Arguments denoted as
Input must
not be changed by this procedure.
Note: fcng should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by
d02gbf. If your code inadvertently
does return any NaNs or infinities,
d02gbf is likely to produce unexpected results.
-
7:
– Real (Kind=nag_wp) array
Input/Output
-
8:
– Real (Kind=nag_wp) array
Input/Output
-
9:
– Real (Kind=nag_wp) array
Input/Output
-
On entry: the arrays
c and
d must be set to the matrices
and
in
(2)).
gam must be set to the vector
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 only;
-
(ii)condition involving and ; and
-
(iii)conditions on only.
The routine 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 problems
(1) and
(2) must be of boundary value type, that is neither
nor
may be identically zero. Note also that the rank of the matrix
must be
for the problem to be properly posed. Any violation of these conditions will lead to an error exit.
-
10:
– Integer
Input
-
On entry: the maximum permitted number of mesh points.
Constraint:
.
-
11:
– Real (Kind=nag_wp) array
Input/Output
-
On entry: if
(see
np), the first
np elements must define an initial mesh. Otherwise the elements of
need not be set.
On exit:
define the final mesh (with the returned value of
np) satisfying the relation
(4).
-
12:
– Real (Kind=nag_wp) array
Output
-
On exit: the approximate solution
satisfying
(3), 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:
– Integer
Input/Output
-
On entry: determines whether a default mesh or user-supplied mesh is used.
- A default value of for np and a corresponding equispaced mesh are used.
- You must define an initial mesh x as in (4).
On exit: the number of points in the final (returned) mesh.
-
14:
– Real (Kind=nag_wp) array
Workspace
-
15:
– Integer
Input
-
On entry: the dimension of the array
w as declared in the (sub)program from which
d02gbf is called.
Constraint:
.
-
16:
– Integer array
Workspace
-
17:
– Integer
Input
-
On entry: the dimension of the array
iw as declared in the (sub)program from which
d02gbf is called.
Constraint:
.
-
18:
– 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
, where each of the decimal digits
,
and
must have a value of
or
.
|
specifies hard failure, otherwise soft failure; |
|
suppresses error messages, otherwise error messages will be printed (see Section 6); |
|
suppresses warning messages, otherwise warning messages will be printed (see Section 6). |
The recommended value for inexperienced users is (i.e., hard failure with all messages printed).
On exit:
unless the routine detects an error or a warning has been flagged (see
Section 6).
6
Error Indicators and Warnings
If on entry
or
, explanatory error messages are output on the current error message unit (as defined by
x04aaf).
Errors or warnings detected by the routine:
-
On entry, and .
Constraint: .
On entry, .
Constraint: ; that is, .
On entry, .
Constraint: ; that is, .
On entry, .
Constraint: .
On entry, .
Constraint: .
On entry, .
Constraint: or .
On entry, and .
Constraint: .
On entry, .
Constraint: .
On entry: and .
Constraint: .
On entry: and .
Constraint: .
The sequence
x is not strictly increasing. For
,
and
.
-
c is identically zero;
n conditions are set in
d.
At least one condition must be on the left.
.
d is identically zero;
n conditions are set in
c.
At least one condition must be on the right.
.
More than
n columns of the
n by
matrix
are identically zero, i.e., the boundary conditions are rank deficient. The number of non-identically zero columns is
.
Row
of the array
c and the corresponding row of array
d are identically zero, i.e., the boundary conditions are rank deficient.
-
A finer mesh is required for the accuracy requested; that is,
mnp is not large enough.
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.
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.
-
A serious error occurred in a call to the internal integrator.
The error code internally was
. Please contact
NAG.
-
At least one row of the
n by
matrix
is a linear combination of the other rows, i.e., the boundary conditions are rank deficient. The index of the first such row is
.
At least one row of the
n by
matrix
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
.
There are two possible reasons for this error exit which occurs when checking the rank of the boundary conditions by reduction to a row echelon form:
-
(i)at least one row of the by matrix is a linear combination of the other rows and hence the boundary conditions are rank deficient. The index of the first such row encountered is given by on exit; and
-
(ii)as (i) but the rank deficiency implied by this error exit has only been determined up to a numerical tolerance. Minus the index of the first such row encountered is given by on exit.
In case
(ii) 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 routine.
For example, if
and
is small enough, this error exit is likely to be taken. A better form for the boundary conditions in this case would be
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.
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.
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
(3) 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
d02gbf 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.
d02gbf 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.
The time taken by d02gbf depends on the difficulty of the problem, the number of mesh points (and meshes) used and the number of deferred corrections.
You are strongly recommended to set
ifail to obtain self-explanatory 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.
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 problem (written as a first-order system)
with boundary conditions
for the cases
and
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
.
Note the call to
x04abf prior to the call to
d02gbf.
10.1
Program Text
10.2
Program Data
10.3
Program Results