NAG C Library Function Document
nag_ode_bvp_fd_lin_gen (d02gbc)
1
Purpose
nag_ode_bvp_fd_lin_gen (d02gbc) solves a general linear two-point boundary value problem for a system of ordinary differential equations using a deferred correction technique.
2
Specification
#include <nag.h> |
#include <nagd02.h> |
void |
nag_ode_bvp_fd_lin_gen (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) |
|
3
Description
nag_ode_bvp_fd_lin_gen (d02gbc) solves the linear two-point boundary value problem for a system of
neq 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
neq by
neq matrices, and
and
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
nag_ode_bvp_fd_nonlin_gen (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 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:
– IntegerInput
-
On entry: the number of equations; that is
neq is the order of system
(1).
Constraint:
.
- 2:
– function, supplied by the userExternal Function
-
fcnf must evaluate the matrix
in
(1) at a general point
.
The specification of
fcnf is:
void |
fcnf (Integer neq,
double x,
double f[],
Nag_User *comm)
|
|
- 1:
– IntegerInput
-
On entry: the number of differential equations.
- 2:
– doubleInput
-
On entry: the value of the independent variable .
- 3:
– doubleOutput
-
On exit: the
th element of the matrix
, for
where
is set by
. (See
Section 10 for an example.)
- 4:
– Nag_User *
-
Pointer to a structure of type Nag_User with the following member:
- p – Pointer
-
On entry/exit: the pointer
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
nag_ode_bvp_fd_lin_gen (d02gbc). If your code inadvertently
does return any NaNs or infinities,
nag_ode_bvp_fd_lin_gen (d02gbc) is likely to produce unexpected results.
- 3:
– function, supplied by the userExternal Function
-
fcng must evaluate the vector
in
(1) at a general point
.
The specification of
fcng is:
void |
fcng (Integer neq,
double x,
double g[],
Nag_User *comm)
|
|
- 1:
– IntegerInput
-
On entry: the number of differential equations.
- 2:
– doubleInput
-
On entry: the value of the independent variable .
- 3:
– doubleOutput
-
On exit: the
th element of the vector
, for
. (See
Section 10 for an example.)
- 4:
– Nag_User *
-
Pointer to a structure of type Nag_User with the following member:
- p – Pointer
-
On entry/exit: the pointer
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
nag_ode_bvp_fd_lin_gen (d02gbc). If your code inadvertently
does return any NaNs or infinities,
nag_ode_bvp_fd_lin_gen (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:
– doubleInput
-
On entry: the left-hand boundary point, .
- 5:
– doubleInput
-
On entry: the right-hand boundary point, .
Constraint:
.
- 6:
– doubleInput/Output
- 7:
– doubleInput/Output
- 8:
– doubleInput/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 re-ordered so that the boundary conditions are in the order:
(i) |
conditions on only; |
(ii) |
condition involving and ; and |
(iii) |
conditions on 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
nor
may be identically zero. Note also that the rank of the matrix
must be
neq for the problem to be properly posed. Any violation of these conditions will lead to an error exit.
- 9:
– IntegerInput
-
On entry: the maximum permitted number of mesh points.
Constraint:
.
- 10:
– Integer *Input/Output
-
On entry: determines whether a default or user-supplied initial mesh is used.
- np is set to a default value of 4 and a corresponding equispaced mesh is used.
- You must define an initial mesh using the array x as described.
Constraint:
or .
On exit: the number of points in the final (returned) mesh.
- 11:
– doubleInput/Output
-
On entry: if
(see
np above), the first
np elements must define an initial mesh. Otherwise the elements of
x need not be set.
On exit:
define the final mesh (with the returned value of
np) satisfying the relation
(3).
- 12:
– doubleOutput
-
On exit: the approximate solution
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:
– doubleInput
-
On entry: a positive absolute error tolerance.
If
is the final mesh,
is the
th component of the approximate solution at
, and
is the
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:
.
- 14:
– Nag_User *
-
Pointer to a structure of type Nag_User with the following member:
- p – Pointer
-
On entry/exit: the pointer
, 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
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:
– NagError *Input/Output
-
The NAG error argument (see
Section 3.7 in How to Use the NAG Library and its Documentation).
6
Error Indicators and Warnings
- NE_2_REAL_ARG_LE
-
On entry, while . These arguments must satisfy .
- NE_ALLOC_FAIL
-
Dynamic memory allocation failed.
- NE_BOUND_COND_COL
-
More than
neq columns of the
neq by
matrix
are identically zero. i.e., the boundary conditions are rank deficient. The number of non-identically zero columns is
.
- NE_BOUND_COND_LC
-
At least one row of the
neq 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
.
- NE_BOUND_COND_MAT
-
One of the matrices or 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
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 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
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
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
nag_ode_bvp_fd_nonlin_gen (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, .
Constraint: .
On entry, .
Constraint: .
- NE_INT_RANGE_CONS_2
-
On entry,
and
. The argument
np must satisfy either
or
.
- 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
:
,
.
- NE_NOT_STRICTLY_INCREASING
-
The sequence
x is not strictly increasing:
,
.
- NE_REAL_ARG_LE
-
On entry,
tol must not be less than or equal to 0.0:
.
- NE_RT_B_MESH
-
On entry, the right boundary value
b, has not been set to
:
,
.
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
nag_ode_bvp_fd_lin_gen (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
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
.
10.1
Program Text
Program Text (d02gbce.c)
10.2
Program Data
None.
10.3
Program Results
Program Results (d02gbce.r)