+− Contents

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

3 Description

D02CJF advances the solution of a system of ordinary differential equations

yi′=fix,y1,y2,…,yn, i=1,2,…,n,

from x=X to x=XEND using a variable-order, variable-step Adams method. The system is defined by FCN, which evaluates fi in terms of x and y1,y2,…,yn. The initial values of y1,y2,…,yn must be given at x=X.

The solution is returned via OUTPUT at points specified by you, if desired: this solution is obtained by C1 interpolation on solution values produced by the method. As the integration proceeds a check can be made on the user-specified function gx,y to determine an interval where it changes sign. The position of this sign change is then determined accurately by C1 interpolation to the solution. It is assumed that gx,y is a continuous function of the variables, so that a solution of gx,y=0.0 can be determined by searching for a change in sign in gx,y. The accuracy of the integration,
the interpolation and, indirectly, of the determination of the position where gx,y=0.0, is controlled by the parameters TOL and
RELABS.

4 References

5 Parameters

1: X – REAL (KIND=nag_wp)Input/Output

On entry: the initial value of the independent variable x.

Constraint:
X≠XEND.

On exit: if g is supplied by you, it contains the point where gx,y=0.0, unless gx,y≠0.0 anywhere on the range X to XEND, in which case, X will contain XEND. If g is not supplied by you it contains XEND, unless an error has occurred, when it contains the value of x at the error.

2: XEND – REAL (KIND=nag_wp)Input

On entry: the final value of the independent variable. If XEND<X, integration will proceed in the negative direction.

FCN must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which D02CJF is called. Parameters denoted as Input must not be changed by this procedure.

6: TOL – 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 gx,y=0.0, if g 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 TOL=10.0-p and TOL=10.0-p-1 where p correct decimal digits are required in the solution.

Constraint:
TOL>0.0.

7: RELABS – CHARACTER(1)Input

On entry: the type of error control. At each step in the numerical solution an estimate of the local error, est, is made. For the current step to be accepted the following condition must be satisfied:

where ε is a small machine-dependent number and ei is an estimate of the local error at yi, 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, then RELABS should be set to 'A' on entry, whereas if the error requirement is in terms of the number of correct significant digits, then RELABS should be set to 'R'. If you prefer a mixed error test, then 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:
RELABS='M', 'A', 'R' or 'D'.

8: OUTPUT – 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 XSOL=X (the initial value of x). 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=XEND, then XSOL must be given precisely the value XEND.

G must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which D02CJF is called. Parameters denoted as Input must not be changed by this procedure.

If you do not require the root-finding option, the actual parameter Gmust be the
dummy routine D02CJW. (D02CJW is included in the NAG Library.)

10: W(28+21×N) – REAL (KIND=nag_wp) arrayWorkspace

11: IFAIL – INTEGERInput/Output

On entry: IFAIL must be set to 0, -1​ or ​1. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.

For environments where it might be inappropriate to halt program execution when an error is detected, the value -1​ or ​1 is recommended. If the output of error messages is undesirable, then the value 1 is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is 0. When the value -1​ or ​1 is used it is essential to test the value of IFAIL on exit.

On exit: IFAIL=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6 Error Indicators and Warnings

If on entry IFAIL=0 or -1, explanatory error messages are output on the current error message unit (as defined by X04AAF).

Errors or warnings detected by the routine:

IFAIL=1

On entry,

TOL≤0.0,

or

N≤0,

or

RELABS≠'M', 'A', 'R' or 'D',

or

X=XEND.

IFAIL=2

With the given value of TOL, no further progress can be made across the integration range from the current point x=X. (See Section 8 for a discussion of this error exit.) The components Y1,Y2,…,YN contain the computed values of the solution at the current point x=X. If you have supplied g, then no point at which gx,y changes sign has been located up to the point x=X.

IFAIL=3

TOL is too small for D02CJF to take an initial step. X and Y1,Y2,…,YN retain their initial values.

IFAIL=4

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.

IFAIL=5

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.

IFAIL=6

At no point in the range X to XEND did the function gx,y change sign, if g was supplied. It is assumed that gx,y=0 has no solution.

IFAIL=7

A serious error has occurred in an internal call. Check all subroutine calls and array sizes. Seek expert help.

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 RELABS='M' 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 gx,y. You should try to code G without introducing any unnecessary cancellation errors.

8 Further Comments

If D02CJF fails with IFAIL=3, 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 IFAIL=2, 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 IFAIL=2, 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 x (internally to D02CJF) to preserve stability. This will exhibit itself by making the computing time excessively long, or occasionally by an exit with IFAIL=2. Adams methods are not efficient in such cases, and you should try D02EJF.

9 Example

This example illustrates the solution of four different problems. In each case the differential system (for a projectile) is

y′=tan⁡ϕv′=-0.032tan⁡ϕv-0.02vcos⁡ϕϕ′=-0.032v2

over an interval X=0.0 to XEND=10.0 starting with values y=0.5, v=0.5 and ϕ=π/5. We solve each of the following problems with local error tolerances 1.0E−4 and 1.0E−5.

(i)

To integrate to x=10.0 producing output at intervals of 2.0 until a point is encountered where y=0.0.