NAG Library Routine Document
d02raf
(bvp_fd_nonlin_gen)
1
Purpose
d02raf solves a two-point boundary value problem with general boundary conditions for a system of ordinary differential equations, using a deferred correction technique and Newton iteration.
2
Specification
Fortran Interface
Subroutine d02raf ( |
n,
mnp,
np,
numbeg,
nummix,
tol,
init,
x,
y,
ldy,
abt,
fcn,
g,
ijac,
jacobf,
jacobg,
deleps,
jaceps,
jacgep,
work,
lwork,
iwork,
liwork,
ifail) |
Integer, Intent (In) | :: |
n,
mnp,
numbeg,
nummix,
init,
ldy,
ijac,
lwork,
liwork | Integer, Intent (Inout) | :: |
np,
ifail | Integer, Intent (Out) | :: |
iwork(liwork) | Real (Kind=nag_wp), Intent (In) | :: |
tol | Real (Kind=nag_wp), Intent (Inout) | :: |
x(mnp),
y(ldy,mnp),
deleps | Real (Kind=nag_wp), Intent (Out) | :: |
abt(n),
work(lwork) | External | :: |
fcn,
g,
jacobf,
jacobg,
jaceps,
jacgep |
|
C Header Interface
#include nagmk26.h
void |
d02raf_ (
const Integer *n,
const Integer *mnp,
Integer *np,
const Integer *numbeg,
const Integer *nummix,
const double *tol,
const Integer *init,
double x[],
double y[],
const Integer *ldy,
double abt[],
void (NAG_CALL *fcn)(
const double *x,
const double *eps,
const double y[],
double f[],
const Integer *n),
void (NAG_CALL *g)(
const double *eps,
const double ya[],
const double yb[],
double bc[],
const Integer *n),
const Integer *ijac,
void (NAG_CALL *jacobf)(
const double *x,
const double *eps,
const double y[],
double f[],
const Integer *n),
void (NAG_CALL *jacobg)(
const double *eps,
const double ya[],
const double yb[],
double aj[],
double bj[],
const Integer *n),
double *deleps,
void (NAG_CALL *jaceps)(
const double *x,
const double *eps,
const double y[],
double f[],
const Integer *n),
void (NAG_CALL *jacgep)(
const double *eps,
const double ya[],
const double yb[],
double bcep[],
const Integer *n),
double work[],
const Integer *lwork,
Integer iwork[],
const Integer *liwork,
Integer *ifail) |
|
3
Description
d02raf solves a two-point boundary value problem for a system of
ordinary differential equations in the interval
with
. The system is written in the form
and the derivatives
are evaluated by
fcn. With the differential equations
(1) must be given a system of
(nonlinear) boundary conditions
where
The functions
are evaluated by
g. The solution is computed using a finite difference technique with deferred correction allied to a Newton iteration to solve the finite difference equations. The technique used is described fully in
Pereyra (1979).
You must supply an absolute error tolerance and may also supply an initial mesh for the finite difference equations and an initial approximate solution (alternatively a default mesh and approximation are used). The approximate solution is corrected using Newton iteration and deferred correction. Then, additional points are added to the mesh and the solution is recomputed with the aim of making the error everywhere less than your tolerance and of approximately equidistributing the error 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.
The Newton iteration requires Jacobian matrices
These may be supplied through
jacobf for
and
jacobg for the others. Alternatively the Jacobians may be calculated by numerical differentiation using the algorithm described in
Curtis et al. (1974).
For problems of the type
(1) and
(2) for which it is difficult to determine an initial approximation from which the Newton iteration will converge, a continuation facility is provided. You must set up a family of problems
where
etc., and where
is a continuation parameter. The choice
must give a problem
(3) which is easy to solve and
must define the problem whose solution is actually required. The routine solves a sequence of problems with
values
The number
and the values
are chosen by the routine so that each problem can be solved using the solution of its predecessor as a starting approximation. Jacobians
and
are required and they may be supplied by you via
jaceps and
jacgep respectively or may be computed by numerical differentiation.
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 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 differential equations.
Constraint:
.
- 2: – IntegerInput
-
On entry:
mnp must be set to the maximum permitted number of points in the finite difference mesh. If
lwork or
liwork are too small then internally
mnp will be replaced by the maximum permitted by these values. (A warning message will be output if on entry
ifail is set to obtain monitoring information.)
Constraint:
.
- 3: – IntegerInput/Output
-
On entry: must be set to the number of points to be used in the initial mesh.
Constraint:
.
On exit: the number of points in the final mesh.
- 4: – IntegerInput
-
On entry: the number of left-hand boundary conditions (that is the number involving only).
Constraint:
.
- 5: – IntegerInput
-
On entry: the number of coupled boundary conditions (that is the number involving both and ).
Constraint:
.
- 6: – Real (Kind=nag_wp)Input
-
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
(1) and
(2), then, except in extreme circumstances, it is expected that
Constraint:
.
- 7: – IntegerInput
-
On entry: indicates whether you wish to supply an initial mesh and approximate solution () or whether default values are to be used, ().
Constraint:
or .
- 8: – Real (Kind=nag_wp) arrayInput/Output
-
On entry: you must set and . If on entry a default equispaced mesh will be used, otherwise you must specify a mesh by setting
, for .
Constraints:
- if , ;
- if , .
On exit:
define the final mesh (with the returned value of
np) and
and
.
- 9: – Real (Kind=nag_wp) arrayInput/Output
-
On entry: if
,
y need not be set.
If
, the array
y must contain an initial approximation to the solution such that
contains an approximation to
On exit: the approximate solution
satisfying
(5) on the final mesh, that is
where
np is the number of points in the final mesh. If an error has occurred then
y contains the latest approximation to the solution. The remaining columns of
y are not used.
- 10: – IntegerInput
-
On entry: the first dimension of the array
y as declared in the (sub)program from which
d02raf is called.
Constraint:
.
- 11: – Real (Kind=nag_wp) arrayOutput
-
On exit: , for , holds the largest estimated error (in magnitude) of the th component of the solution over all mesh points.
- 12: – Subroutine, supplied by the user.External Procedure
-
fcn must evaluate the functions
(i.e., the derivatives
) at a general point
for a given value of
, the continuation parameter (see
Section 3).
The specification of
fcn is:
Fortran Interface
Integer, Intent (In) | :: |
n | Real (Kind=nag_wp), Intent (In) | :: |
x,
eps,
y(n) | Real (Kind=nag_wp), Intent (Out) | :: |
f(n) |
|
C Header Interface
#include nagmk26.h
void |
fcn (
const double *x,
const double *eps,
const double y[],
double f[],
const Integer *n) |
|
- 1: – Real (Kind=nag_wp)Input
-
On entry: , the value of the independent variable.
- 2: – Real (Kind=nag_wp)Input
-
On entry: , the value of the continuation parameter. This is if continuation is not being used.
- 3: – Real (Kind=nag_wp) arrayInput
-
On entry: , for , the values of the dependent variables at .
- 4: – Real (Kind=nag_wp) arrayOutput
-
On exit: the values of the derivatives
evaluated at given , for .
- 5: – IntegerInput
-
On entry: , the number of equations.
fcn must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which
d02raf is called. Arguments denoted as
Input must
not be changed by this procedure.
Note: fcn should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by
d02raf. If your code inadvertently
does return any NaNs or infinities,
d02raf is likely to produce unexpected results.
- 13: – Subroutine, supplied by the user.External Procedure
-
g must evaluate the boundary conditions in equation
(3) and place them in the array
bc.
The specification of
g is:
Fortran Interface
Integer, Intent (In) | :: |
n | Real (Kind=nag_wp), Intent (In) | :: |
eps,
ya(n),
yb(n) | Real (Kind=nag_wp), Intent (Out) | :: |
bc(n) |
|
C Header Interface
#include nagmk26.h
void |
g (
const double *eps,
const double ya[],
const double yb[],
double bc[],
const Integer *n) |
|
- 1: – Real (Kind=nag_wp)Input
-
On entry: , the value of the continuation parameter. This is if continuation is not being used.
- 2: – Real (Kind=nag_wp) arrayInput
-
On entry: the value
, for .
- 3: – Real (Kind=nag_wp) arrayInput
-
On entry: the value
, for .
- 4: – Real (Kind=nag_wp) arrayOutput
-
On exit: the values
, for
. These must be ordered as follows:
(i) |
first, the conditions involving only (see numbeg); |
(ii) |
next, the nummix coupled conditions involving both and (see nummix); and, |
(iii) |
finally, the conditions involving only (). |
- 5: – IntegerInput
-
On entry: , the number of equations.
g must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which
d02raf is called. Arguments denoted as
Input must
not be changed by this procedure.
Note: g should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by
d02raf. If your code inadvertently
does return any NaNs or infinities,
d02raf is likely to produce unexpected results.
- 14: – IntegerInput
-
On entry: indicates whether or not you are supplying Jacobian evaluation routines.
- You must supply jacobf and jacobg and also, when continuation is used, jaceps and jacgep.
- Numerical differentiation is used to calculate the Jacobian and the routines d02gaw, d02gax, d02gay and d02gaz respectively may be used as the dummy arguments.
- 15: – Subroutine, supplied by the NAG Library or the user.External Procedure
-
jacobf evaluates the Jacobian
, for
and
, given
and
, for
.
If , numerical differentiation is used to calculate the Jacobian and the routine d02gaz may be substituted for this argument.
The specification of
jacobf is:
Fortran Interface
Subroutine jacobf ( |
x,
eps,
y,
f,
n) |
Integer, Intent (In) | :: |
n | Real (Kind=nag_wp), Intent (In) | :: |
x,
eps,
y(n) | Real (Kind=nag_wp), Intent (Out) | :: |
f(n,n) |
|
C Header Interface
#include nagmk26.h
void |
jacobf (
const double *x,
const double *eps,
const double y[],
double f[],
const Integer *n) |
|
- 1: – Real (Kind=nag_wp)Input
-
On entry: , the value of the independent variable.
- 2: – Real (Kind=nag_wp)Input
-
On entry: , the value of the continuation parameter. This is if continuation is not being used.
- 3: – Real (Kind=nag_wp) arrayInput
-
On entry: , for , the values of the dependent variables at .
- 4: – Real (Kind=nag_wp) arrayOutput
-
On exit: must be set to the value of , evaluated at the point , for and .
- 5: – IntegerInput
-
On entry: , the number of equations.
jacobf must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which
d02raf is called. Arguments denoted as
Input must
not be changed by this procedure.
Note: jacobf should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by
d02raf. If your code inadvertently
does return any NaNs or infinities,
d02raf is likely to produce unexpected results.
- 16: – Subroutine, supplied by the NAG Library or the user.External Procedure
-
jacobg evaluates the Jacobians
and
. The ordering of the rows of
aj and
bj must correspond to the ordering of the boundary conditions described in the specification of
g.
If , numerical differentiation is used to calculate the Jacobian and the routine d02gay may be substituted for this argument.
The specification of
jacobg is:
Fortran Interface
Integer, Intent (In) | :: |
n | Real (Kind=nag_wp), Intent (In) | :: |
eps,
ya(n),
yb(n) | Real (Kind=nag_wp), Intent (Out) | :: |
aj(n,n),
bj(n,n) |
|
C Header Interface
#include nagmk26.h
void |
jacobg (
const double *eps,
const double ya[],
const double yb[],
double aj[],
double bj[],
const Integer *n) |
|
- 1: – Real (Kind=nag_wp)Input
-
On entry: , the value of the continuation parameter. This is if continuation is not being used.
- 2: – Real (Kind=nag_wp) arrayInput
-
On entry: the value
, for .
- 3: – Real (Kind=nag_wp) arrayInput
-
On entry: the value
, for .
- 4: – Real (Kind=nag_wp) arrayOutput
-
On exit: must be set to the value , for and .
- 5: – Real (Kind=nag_wp) arrayOutput
-
On exit: must be set to the value , for and .
- 6: – IntegerInput
-
On entry: , the number of equations.
jacobg must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which
d02raf is called. Arguments denoted as
Input must
not be changed by this procedure.
Note: jacobg should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by
d02raf. If your code inadvertently
does return any NaNs or infinities,
d02raf is likely to produce unexpected results.
- 17: – Real (Kind=nag_wp)Input/Output
-
On entry: must be given a value which specifies whether continuation is required. If
or
then it is assumed that continuation is not required. If
then it is assumed that continuation is required unless
when an error exit is taken.
deleps is used as the increment
(see
(4)) and the choice
is recommended.
On exit: an overestimate of the increment
(in fact the value of the increment which would have been tried if the restriction
had not been imposed). If continuation was not requested then
.
If continuation is not requested then
jaceps and
jacgep may each be replaced by dummy actual arguments in the call to
d02raf. (d02gaw and d02gax respectively may be used as the dummy arguments.)
- 18: – Subroutine, supplied by the NAG Library or the user.External Procedure
-
jaceps evaluates the derivative
given
and
if continuation is being used.
If all Jacobians (derivatives) are to be approximated internally by numerical differentiation, or continuation is not being used,
the routine d02gaw may be substituted for this argument.
The specification of
jaceps is:
Fortran Interface
Subroutine jaceps ( |
x,
eps,
y,
f,
n) |
Integer, Intent (In) | :: |
n | Real (Kind=nag_wp), Intent (In) | :: |
x,
eps,
y(n) | Real (Kind=nag_wp), Intent (Out) | :: |
f(n) |
|
C Header Interface
#include nagmk26.h
void |
jaceps (
const double *x,
const double *eps,
const double y[],
double f[],
const Integer *n) |
|
- 1: – Real (Kind=nag_wp)Input
-
On entry: , the value of the independent variable.
- 2: – Real (Kind=nag_wp)Input
-
On entry: , the value of the continuation parameter.
- 3: – Real (Kind=nag_wp) arrayInput
-
On entry: the solution values
, for , at the point .
- 4: – Real (Kind=nag_wp) arrayOutput
-
On exit: must contain the value at the point , for .
- 5: – IntegerInput
-
On entry: , the number of equations.
jaceps must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which
d02raf is called. Arguments denoted as
Input must
not be changed by this procedure.
Note: jaceps should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by
d02raf. If your code inadvertently
does return any NaNs or infinities,
d02raf is likely to produce unexpected results.
- 19: – Subroutine, supplied by the NAG Library or the user.External Procedure
-
jacgep evaluates the derivatives
if continuation is being used.
If all Jacobians (derivatives) are to be approximated internally by numerical differentiation, or continuation is not being used,
the routine d02gax may be substituted for this argument.
The specification of
jacgep is:
Fortran Interface
Integer, Intent (In) | :: |
n | Real (Kind=nag_wp), Intent (In) | :: |
eps,
ya(n),
yb(n) | Real (Kind=nag_wp), Intent (Out) | :: |
bcep(n) |
|
C Header Interface
#include nagmk26.h
void |
jacgep (
const double *eps,
const double ya[],
const double yb[],
double bcep[],
const Integer *n) |
|
- 1: – Real (Kind=nag_wp)Input
-
On entry: , the value of the continuation parameter.
- 2: – Real (Kind=nag_wp) arrayInput
-
On entry: the value of
, for .
- 3: – Real (Kind=nag_wp) arrayInput
-
On entry: the value of
, for .
- 4: – Real (Kind=nag_wp) arrayOutput
-
On exit: must contain the value of , for .
- 5: – IntegerInput
-
On entry: , the number of equations.
jacgep must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which
d02raf is called. Arguments denoted as
Input must
not be changed by this procedure.
Note: jacgep should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by
d02raf. If your code inadvertently
does return any NaNs or infinities,
d02raf is likely to produce unexpected results.
- 20: – Real (Kind=nag_wp) arrayWorkspace
- 21: – IntegerInput
-
On entry: the dimension of the array
work as declared in the (sub)program from which
d02raf is called.
Constraint:
.
- 22: – Integer arrayWorkspace
- 23: – IntegerInput
-
On entry: the dimension of the array
iwork as declared in the (sub)program from which
d02raf is called.
Constraints:
- if , ;
- if , .
- 24: – IntegerInput/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 3.4 in How to Use the NAG Library and its Documentation).
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:
-
One or more of the arguments
n,
mnp,
np,
numbeg,
nummix,
tol,
deleps,
lwork or
liwork is incorrectly set, or
or the mesh points
are not in strictly ascending order.
-
A finer mesh is required for the accuracy requested; that is
mnp is not large enough. This error exit normally occurs when the problem being solved is difficult (for example, there is a boundary layer) and high accuracy is requested. A poor initial choice of mesh points will make this error exit more likely.
-
The Newton iteration has failed to converge. There are several possible causes for this error:
(i) |
faulty coding in one of the Jacobian calculation routines; |
(ii) |
if then inaccurate Jacobians may have been calculated numerically (this is a very unlikely cause); or, |
(iii) |
a poor initial mesh or initial approximate solution has been selected either by you or by default or there are not enough points in the initial mesh. Possibly, you should try the continuation facility. |
-
The Newton iteration has reached round-off error level. It could be however that the answer returned is satisfactory. The error is likely to occur if too high an accuracy is requested.
-
The Jacobian calculated by
jacobg (or the equivalent matrix calculated by numerical differentiation) is singular. This may occur due to faulty coding of
jacobg or, in some circumstances, to a zero initial choice of approximate solution (such as is chosen when
).
-
There is no dependence on
when continuation is being used. This can be due to faulty coding of
jaceps or
jacgep or, in some circumstances, to a zero initial choice of approximate solution (such as is chosen when
).
-
deleps is required to be less than
machine precision for continuation to proceed. It is likely that either the problem
(3) has no solution for some value near the current value of
(see the advisory print out from
d02raf) or that the problem is so difficult that even with continuation it is unlikely to be solved using this routine. If the latter cause is suspected then using more mesh points initially may help.
-
A serious error has occurred in an internal call. Check all array subscripts and subroutine argument lists in calls to d02raf. Seek expert help.
An unexpected error has been triggered by this routine. Please
contact
NAG.
See
Section 3.9 in How to Use the NAG Library and its Documentation for further information.
Your licence key may have expired or may not have been installed correctly.
See
Section 3.8 in How to Use the NAG Library and its Documentation for further information.
Dynamic memory allocation failed.
See
Section 3.7 in How to Use the NAG Library and its Documentation for further information.
7
Accuracy
The solution returned by the routine will be accurate to your tolerance as defined by the relation
(5) except in extreme circumstances. The final error estimate over the whole mesh for each component is given in the array
abt. 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
d02raf is not thread safe and should not be called from a multithreaded user program. Please see
Section 3.12.1 in How to Use the NAG Library and its Documentation for more information on thread safety.
d02raf 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.
There are too many factors present to quantify the timing. The time taken by d02raf is negligible only on very simple problems.
You are strongly recommended to set
ifail to obtain self-explanatory error messages, and also monitoring information about the course of the computation. Monitoring information is written to a logical advisory message unit which normally default to the same unit number as the error message unit (see
Section 3.5 in How to Use the NAG Library and its Documentation for details); the advisory message unit number can be changed by calling
x04abf.
In the case where you wish to solve a sequence of similar problems, the use of the final mesh and solution from one case as the initial mesh is strongly recommended for the next.
10
Example
This example solves the differential equation
with
and boundary conditions
to an accuracy specified by
. The continuation facility is used with the continuation parameter
introduced as in the differential equation above and with
initially. (The continuation facility is not needed for this problem and is used here for illustration.)
10.1
Program Text
Program Text (d02rafe.f90)
10.2
Program Data
Program Data (d02rafe.d)
10.3
Program Results
Program Results (d02rafe.r)