NAG Library Routine Document
d02cjf
(ivp_adams_zero_simple)
1
Purpose
d02cjf integrates a system of first-order ordinary differential equations over a range with suitable initial conditions, using a variable-order, variable-step Adams' method until a user-specified function, if supplied, of the solution is zero, and returns the solution at points specified by you, if desired.
2
Specification
Fortran Interface
Subroutine d02cjf ( |
x,
xend,
n,
y,
fcn,
tol,
relabs,
output,
g,
w,
ifail) |
Integer, Intent (In) | :: |
n | Integer, Intent (Inout) | :: |
ifail | Real (Kind=nag_wp), External | :: |
g | Real (Kind=nag_wp), Intent (In) | :: |
xend,
tol | Real (Kind=nag_wp), Intent (Inout) | :: |
x,
y(n) | Real (Kind=nag_wp), Intent (Out) | :: |
w(28+21*n) | Character (1), Intent (In) | :: |
relabs | External | :: |
fcn,
output |
|
C Header Interface
#include nagmk26.h
void |
d02cjf_ (
double *x,
const double *xend,
const Integer *n,
double y[],
void (NAG_CALL *fcn)(
const double *x,
const double y[],
double f[]),
const double *tol,
const char *relabs,
void (NAG_CALL *output)(
double *xsol,
const double y[]),
double (NAG_CALL *g)(
const double *x,
const double y[]),
double w[],
Integer *ifail,
const Charlen length_relabs) |
|
3
Description
d02cjf advances the solution of a system of ordinary differential equations
from
to
using a variable-order, variable-step Adams' method. The system is defined by
fcn, which evaluates
in terms of
and
. The initial values of
must be given at
.
The solution is returned via
output at points specified by you, if desired: this solution is obtained by
interpolation on solution values produced by the method. As the integration proceeds a check can be made on the user-specified function
to determine an interval where it changes sign. The position of this sign change is then determined accurately by
interpolation to the solution. It is assumed that
is a continuous function of the variables, so that a solution of
can be determined by searching for a change in sign in
. The accuracy of the integration,
the interpolation and, indirectly, of the determination of the position where
, is controlled by the arguments
tol and
relabs.
For a description of Adams' methods and their practical implementation see
Hall and Watt (1976).
4
References
Hall G and Watt J M (ed.) (1976) Modern Numerical Methods for Ordinary Differential Equations Clarendon Press, Oxford
5
Arguments
- 1: – Real (Kind=nag_wp)Input/Output
-
On entry: the initial value of the independent variable .
Constraint:
.
On exit: if
is supplied by you, it contains the point where
, unless
anywhere on the range
x to
xend, in which case,
x will contain
xend. If
is not supplied by you it contains
xend, unless an error has occurred, when it contains the value of
at the error.
- 2: – Real (Kind=nag_wp)Input
-
On entry: the final value of the independent variable. If , integration will proceed in the negative direction.
Constraint:
.
- 3: – IntegerInput
-
On entry: , the number of differential equations.
Constraint:
.
- 4: – Real (Kind=nag_wp) arrayInput/Output
-
On entry: the initial values of the solution at .
On exit: the computed values of the solution at the final point .
- 5: – Subroutine, supplied by the user.External Procedure
-
fcn must evaluate the functions
(i.e., the derivatives
) for given values of its arguments
.
The specification of
fcn is:
Fortran Interface
Subroutine fcn ( |
x,
y,
f) |
Real (Kind=nag_wp), Intent (In) | :: |
x,
y(*) | Real (Kind=nag_wp), Intent (Inout) | :: |
f(*) |
|
C Header Interface
#include nagmk26.h
void |
fcn (
const double *x,
const double y[],
double f[]) |
|
- 1: – Real (Kind=nag_wp)Input
-
On entry: , the value of the independent variable.
- 2: – Real (Kind=nag_wp) arrayInput
-
Note: the dimension,
, of
y is
n as in the call of
d02cjf.
On entry: , for , the value of the variable.
- 3: – Real (Kind=nag_wp) arrayOutput
-
Note: the dimension,
, of
f is
n as in the call of
d02cjf.
On exit: the value of
, for .
fcn must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which
d02cjf 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
d02cjf. If your code inadvertently
does return any NaNs or infinities,
d02cjf is likely to produce unexpected results.
- 6: – Real (Kind=nag_wp)Input
-
On entry: a
positive tolerance for controlling the error in the integration. Hence
tol affects the determination of the position where
, if
is supplied.
d02cjf has been designed so that, for most problems, a reduction in
tol leads to an approximately proportional reduction in the error in the solution. However, the actual relation between
tol and the accuracy achieved cannot be guaranteed. You are strongly recommended to call
d02cjf with more than one value for
tol and to compare the results obtained to estimate their accuracy. In the absence of any prior knowledge, you might compare the results obtained by calling
d02cjf with
and
where
correct decimal digits are required in the solution.
Constraint:
.
- 7: – Character(1)Input
-
On entry: the type of error control. At each step in the numerical solution an estimate of the local error,
, is made. For the current step to be accepted the following condition must be satisfied:
where
and
are defined by
where
is a small machine-dependent number and
is an estimate of the local error at
, computed internally. If the appropriate condition is not satisfied, the step size is reduced and the solution is recomputed on the current step. If you wish to measure the error in the computed solution in terms of the number of correct decimal places,
relabs should be set to 'A' on entry, whereas if the error requirement is in terms of the number of correct significant digits,
relabs should be set to 'R'. If you prefer a mixed error test,
relabs should be set to 'M', otherwise if you have no preference,
relabs should be set to the default 'D'. Note that in this case 'D' is taken to be 'M'.
Constraint:
, , or .
- 8: – Subroutine, supplied by the NAG Library or the user.External Procedure
-
output permits access to intermediate values of the computed solution (for example to print or plot them), at successive user-specified points. It is initially called by
d02cjf with
(the initial value of
). You must reset
xsol to the next point (between the current
xsol and
xend) where
output is to be called, and so on at each call to
output. If, after a call to
output, the reset point
xsol is beyond
xend,
d02cjf will integrate to
xend with no further calls to
output; if a call to
output is required at the point
,
xsol must be given precisely the value
xend.
The specification of
output is:
Fortran Interface
Subroutine output ( |
xsol,
y) |
Real (Kind=nag_wp), Intent (In) | :: |
y(*) | Real (Kind=nag_wp), Intent (Inout) | :: |
xsol |
|
C Header Interface
#include nagmk26.h
void |
output (
double *xsol,
const double y[]) |
|
- 1: – Real (Kind=nag_wp)Input/Output
-
On entry: the output value of the independent variable .
On exit: you must set
xsol to the next value of
at which
output is to be called.
- 2: – Real (Kind=nag_wp) arrayInput
-
Note: the dimension,
, of
y is
n as in the call of
d02cjf.
On entry: the computed solution at the point
xsol.
output must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which
d02cjf is called. Arguments denoted as
Input must
not be changed by this procedure.
Note: output should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by
d02cjf. If your code inadvertently
does return any NaNs or infinities,
d02cjf is likely to produce unexpected results.
If you do not wish to access intermediate output, the actual argument
output must be the
dummy routine d02cjx. (d02cjx is included in the NAG Library.)
- 9: – real (Kind=nag_wp) Function, supplied by the user.External Procedure
-
g must evaluate the function
for specified values
. It specifies the function
for which the first position
where
is to be found.
The specification of
g is:
Fortran Interface
Real (Kind=nag_wp) | :: | g | Real (Kind=nag_wp), Intent (In) | :: |
x,
y(*) |
|
C Header Interface
#include nagmk26.h
double |
g (
const double *x,
const double y[]) |
|
- 1: – Real (Kind=nag_wp)Input
-
On entry: , the value of the independent variable.
- 2: – Real (Kind=nag_wp) arrayInput
-
Note: the dimension,
, of
y is
n as in the call of
d02cjf.
On entry: , for , the value of the variable.
g must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which
d02cjf 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
d02cjf. If your code inadvertently
does return any NaNs or infinities,
d02cjf is likely to produce unexpected results.
If you do not require the root-finding option, the actual argument
g must be the
dummy routine d02cjw. (d02cjw is included in the NAG Library.)
- 10: – Real (Kind=nag_wp) arrayWorkspace
-
- 11: – IntegerInput/Output
-
On entry:
ifail must be set to
,
. If you are unfamiliar with this argument you should refer to
Section 3.4 in How to Use the NAG Library and its Documentation for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value
is recommended. If the output of error messages is undesirable, then the value
is recommended. Otherwise, if you are not familiar with this argument, the recommended value is
.
When the value is used it is essential to test the value of ifail on exit.
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, | , |
or | , |
or | , , or , |
or | . |
-
With the given value of
tol, no further progress can be made across the integration range from the current point
. (See
Section 9 for a discussion of this error exit.) The components
contain the computed values of the solution at the current point
. If you have supplied
, no point at which
changes sign has been located up to the point
.
-
tol is too small for
d02cjf to take an initial step.
x and
retain their initial values.
-
xsol has not been reset or
xsol lies behind
x in the direction of integration, after the initial call to
output, if the
output option was selected.
-
A value of
xsol returned by the
output has not been reset or lies behind the last value of
xsol in the direction of integration, if the
output option was selected.
-
At no point in the range
x to
xend did the function
change sign, if
was supplied. It is assumed that
has no solution.
-
A serious error has occurred in an internal call. Check all subroutine calls and array sizes. 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 accuracy of the computation of the solution vector
y may be controlled by varying the local error tolerance
tol. In general, a decrease in local error tolerance should lead to an increase in accuracy. You are advised to choose
unless you have a good reason for a different choice.
If the problem is a root-finding one, then the accuracy of the root determined will depend on the properties of
. You should try to code
g without introducing any unnecessary cancellation errors.
8
Parallelism and Performance
d02cjf is not threaded in any implementation.
If more than one root is required then
d02qff should be used.
If
d02cjf fails with
, then it can be called again with a larger value of
tol if this has not already been tried. If the accuracy requested is really needed and cannot be obtained with this routine,
the system may be very stiff (see below) or so badly scaled that it cannot be solved to the required accuracy.
If
d02cjf fails with
, it is probable that it has been called with a value of
tol which is so small that a solution cannot be obtained on the range
x to
xend. This can happen for well-behaved systems and very small values of
tol. You should, however, consider whether there is a more fundamental difficulty. For example:
(a) |
in the region of a singularity (infinite value) of the solution, the routine
will usually stop with , unless overflow occurs first. Numerical integration cannot be continued through a singularity, and analytic treatment should be considered; |
(b) |
for ‘stiff’ equations where the solution contains rapidly decaying components, the routine will use very small steps in (internally to d02cjf) to preserve stability. This will exhibit itself by making the computing time excessively long, or occasionally by an exit with . Adams' methods are not efficient in such cases, and you should try d02ejf. |
10
Example
This example illustrates the solution of four different problems. In each case the differential system (for a projectile) is
over an interval
to
starting with values
,
and
. We solve each of the following problems with local error tolerances
and
.
(i) |
To integrate to producing output at intervals of until a point is encountered where . |
(ii) |
As (i) but with no intermediate output. |
(iii) |
As (i) but with no termination on a root-finding condition. |
(iv) |
As (i) but with no intermediate output and no root-finding termination condition. |
10.1
Program Text
Program Text (d02cjfe.f90)
10.2
Program Data
Program Data (d02cjfe.d)
10.3
Program Results
Program Results (d02cjfe.r)