NAG Library Routine Document

d02ejf  (ivp_bdf_zero_simple)

 Contents

    1  Purpose
    7  Accuracy

1
Purpose

d02ejf integrates a stiff system of first-order ordinary differential equations over an interval with suitable initial conditions, using a variable-order, variable-step method implementing the Backward Differentiation Formulae (BDF), 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 d02ejf ( x, xend, n, y, fcn, pederv, tol, relabs, output, g, w, iw, ifail)
Integer, Intent (In):: n, iw
Integer, Intent (Inout):: ifail
Real (Kind=nag_wp), External:: g
Real (Kind=nag_wp), Intent (In):: xend
Real (Kind=nag_wp), Intent (Inout):: x, y(n), tol
Real (Kind=nag_wp), Intent (Out):: w(iw)
Character (1), Intent (In):: relabs
External:: fcn, pederv, output
C Header Interface
#include nagmk26.h
void  d02ejf_ ( double *x, const double *xend, const Integer *n, double y[],
void (NAG_CALL *fcn)( const double *x, const double y[], double f[]),
void (NAG_CALL *pederv)( const double *x, const double y[], double pw[]),
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[], const Integer *iw, Integer *ifail, const Charlen length_relabs)

3
Description

d02ejf advances the solution of a system of ordinary differential equations
yi = fi x,y1,y2,,yn ,   i=1,2,,n ,  
from x=x to x=xend using a variable-order, variable-step method implementing the BDF. The system is defined by fcn, which evaluates fi in terms of x and y1 , y2 , , yn  (see Section 5). The initial values of y1 , y2 , , yn  must be given at x=x.
The solution is returned via the 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 arguments tol and relabs. The Jacobian of the system y=fx,y may be supplied in pederv, if it is available.
For a description of BDF 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:     x – Real (Kind=nag_wp)Input/Output
On entry: the initial value of the independent variable x.
Constraint: xxend.
On exit: if g is supplied by you, x contains the point where gx,y=0.0, unless gx,y0.0 anywhere on the range x to xend, in which case, x will contain xend. If g is not supplied x 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.
Constraint: xendx.
3:     n – IntegerInput
On entry: n, the number of differential equations.
Constraint: n1.
4:     yn – Real (Kind=nag_wp) arrayInput/Output
On entry: the initial values of the solution y1,y2,,yn at x=x.
On exit: the computed values of the solution at the final point x=x.
5:     fcn – Subroutine, supplied by the user.External Procedure
fcn must evaluate the functions fi (i.e., the derivatives yi) for given values of its arguments x,y1,,yn.
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:     x – Real (Kind=nag_wp)Input
On entry: x, the value of the independent variable.
2:     y* – Real (Kind=nag_wp) arrayInput
Note: the dimension, n, of y is n as in the call of d02ejf.
On entry: yi, for i=1,2,,n, the value of the variable.
3:     f* – Real (Kind=nag_wp) arrayOutput
Note: the dimension, n, of f is n as in the call of d02ejf.
On exit: the value of fi, for i=1,2,,n.
fcn must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which d02ejf 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 d02ejf. If your code inadvertently does return any NaNs or infinities, d02ejf is likely to produce unexpected results.
6:     pederv – Subroutine, supplied by the NAG Library or the user.External Procedure
pederv must evaluate the Jacobian of the system (that is, the partial derivatives fi yj ) for given values of the variables x,y1,y2,,yn.
The specification of pederv is:
Fortran Interface
Subroutine pederv ( x, y, pw)
Real (Kind=nag_wp), Intent (In):: x, y(*)
Real (Kind=nag_wp), Intent (Inout):: pw(*)
C Header Interface
#include nagmk26.h
void  pederv ( const double *x, const double y[], double pw[])
1:     x – Real (Kind=nag_wp)Input
On entry: x, the value of the independent variable.
2:     y* – Real (Kind=nag_wp) arrayInput
Note: the dimension, n, of y is n as in the call of d02ejf.
On entry: yi, for i=1,2,,n, the value of the variable.
3:     pw* – Real (Kind=nag_wp) arrayOutput
Note: the dimension of pw is n×n, with n as in the call of d02ejf.
On exit: pwn×i-1+j must contain the value of fi yj , for i=1,2,,n and j=1,2,,n.
pederv must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which d02ejf is called. Arguments denoted as Input must not be changed by this procedure.
Note: pederv should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by d02ejf. If your code inadvertently does return any NaNs or infinities, d02ejf is likely to produce unexpected results.
If you do not wish to supply the Jacobian, the actual argument pederv must be the dummy routine d02ejy. (d02ejy is included in the NAG Library.)
7:     tol – Real (Kind=nag_wp)Input/Output
On entry: must be set to 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.
d02ejf 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 d02ejf 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 d02ejf with tol=10-p and tol=10-p-1 if p correct decimal digits are required in the solution.
Constraint: tol>0.0.
On exit: normally unchanged. However if the range x to xend is so short that a small change in tol is unlikely to make any change in the computed solution, then, on return, tol has its sign changed.
8:     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:
est = 1n i=1 n ei / τr × yi + τa 2 1.0  
where τr and τa are defined by
relabs τr τa
'M' tol tol
'A' 0.0 tol
'R' tol ε
'D' tol ε
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, 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 'R'.
Constraint: relabs='A', 'M', 'R' or 'D'.
9:     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 d02ejf 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, d02ejf will integrate to xend with no further calls to output; if a call to output is required at the point xsol=xend, 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:     xsol – Real (Kind=nag_wp)Input/Output
On entry: x, the value of the independent variable.
On exit: you must set xsol to the next value of x at which output is to be called.
2:     y* – Real (Kind=nag_wp) arrayInput
Note: the dimension, n, of y is n as in the call of d02ejf.
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 d02ejf 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 d02ejf. If your code inadvertently does return any NaNs or infinities, d02ejf is likely to produce unexpected results.
If you do not wish to access intermediate output, the actual argument output must be the dummy routine d02ejx. (d02ejx is included in the NAG Library.)
10:   g – real (Kind=nag_wp) Function, supplied by the user.External Procedure
g must evaluate the function gx,y for specified values x,y. It specifies the function g for which the first position x where gx,y=0 is to be found.
The specification of g is:
Fortran Interface
Function g ( x, y)
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:     x – Real (Kind=nag_wp)Input
On entry: x, the value of the independent variable.
2:     y* – Real (Kind=nag_wp) arrayInput
Note: the dimension, n, of y is n as in the call of d02ejf.
On entry: yi, for i=1,2,,n, the value of the variable.
g must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which d02ejf 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 d02ejf. If your code inadvertently does return any NaNs or infinities, d02ejf is likely to produce unexpected results.
If you do not require the root-finding option, the actual argument g must be the dummy routine d02ejw. (d02ejw is included in the NAG Library.)
11:   wiw – Real (Kind=nag_wp) arrayWorkspace
12:   iw – IntegerInput
On entry: the dimension of the array w as declared in the (sub)program from which d02ejf is called.
Constraint: iw12+n×n+50.
13:   ifail – IntegerInput/Output
On entry: ifail must be set to 0, -1​ or ​1. 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 -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 argument, 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,tol0.0,
orx=xend,
orn0,
orrelabs'M','A','R','D',
oriw<12+n×n+50.
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 5 for a discussion of this error test.) The components y1,y2,,yn contain the computed values of the solution at the current point x=x. If you have supplied g, no point at which gx,y changes sign has been located up to the point x=x.
ifail=3
tol is too small for d02ejf to take an initial step. x and y1,y2,,yn retain their initial values.
ifail=4
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 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 (c05azf)
A serious error has occurred in an internal call to the specified routine. Check all subroutine calls and array dimensions. Seek expert help.
ifail=8 (d02xkf)
A serious error has occurred in an internal call to the specified routine. Check all subroutine calls and array dimensions. Seek expert help.
ifail=9
A serious error has occurred in an internal call to an interpolation routine. Check all (sub)program calls and array dimensions. Seek expert help.
ifail=-99
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.
ifail=-399
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.
ifail=-999
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 relabs='R' unless you have a good reason for a different choice. It is particularly appropriate if the solution decays.
If the problem is a root-finding one, then the accuracy of the root determined will depend strongly on g x  and g yi , for i=1,2,,n. Large values for these quantities may imply large errors in the root.

8
Parallelism and Performance

d02ejf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
d02ejf 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.

9
Further Comments

If more than one root is required, then to determine the second and later roots d02ejf may be called again starting a short distance past the previously determined roots. Alternatively you may construct your own root-finding code using d02nbf (and other routines in Sub-chapter D02M–N), c05azf and d02xkf.
If it is easy to code, you should supply pederv. However, it is important to be aware that if pederv is coded incorrectly, a very inefficient integration may result and possibly even a failure to complete the integration (see ifail=2).

10
Example

We illustrate the solution of five different problems. In each case the differential system is the well-known stiff Robertson problem.
a = -0.04a+104bc b = 0.04a-104bc -3×107b2 c = -3×107b2  
with initial conditions a=1.0, b=c=0.0 at x=0.0. We solve each of the following problems with local error tolerances 1.0E−3 and 1.0E−4.
(i) To integrate to x=10.0 producing output at intervals of 2.0 until a point is encountered where a=0.9. The Jacobian is calculated numerically.
(ii) As (i) but with the Jacobian calculated analytically.
(iii) As (i) but with no intermediate output.
(iv) As (i) but with no termination on a root-finding condition.
(v) Integrating the equations as in (i) but with no intermediate output and no root-finding termination condition.

10.1
Program Text

Program Text (d02ejfe.f90)

10.2
Program Data

Program Data (d02ejfe.d)

10.3
Program Results

Program Results (d02ejfe.r)

GnuplotProduced by GNUPLOT 4.6 patchlevel 3 0 0.2 0.4 0.6 0.8 1 0 2 4 6 8 10 Solution (a,b,c) x Example Program ODE Solution using BDF Method with Root-finding a b c a = 0.9 gnuplot_plot_1 gnuplot_plot_2 gnuplot_plot_3 gnuplot_plot_4
© The Numerical Algorithms Group Ltd, Oxford, UK. 2017