d02ejc 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 specified points, if desired.
from $x={\mathbf{x}}$ to $x={\mathbf{xend}}$ using a variable-order, variable-step method implementing the BDF. The system is defined by fcn, which evaluates ${f}_{i}$ in terms of $x$ and ${y}_{1},{y}_{2},\dots ,{y}_{{\mathbf{neq}}}$ (see Section 5). The initial values of ${y}_{1},{y}_{2},\dots ,{y}_{{\mathbf{neq}}}$ must be given at $x={\mathbf{x}}$.
The solution is returned via output at specified points, if desired: this solution is obtained by ${C}^{1}$ interpolation on solution values produced by the method. As the integration proceeds a check can be made on the user-specified function $g(x,y)$ to determine an interval where it changes sign. The position of this sign change is then determined accurately. It is assumed that $g(x,y)$ is a continuous function of the variables, so that a solution of $g(x,y)=0.0$ can be determined by searching for a change in sign in $g(x,y)$. The accuracy of the integration, the interpolation and, indirectly, of the determination of the position where $g(x,y)=0.0$, is controlled by the arguments tol and err_c. The Jacobian of the system ${y}^{\prime}=f(x,y)$ may be supplied in function pederv, if it is available.
For a description of BDF and their practical implementation see Hall and Watt (1976).
4References
Hall G and Watt J M (ed.) (1976) Modern Numerical Methods for Ordinary Differential Equations Clarendon Press, Oxford
5Arguments
1: $\mathbf{neq}$ – IntegerInput
On entry: the number of differential equations.
Constraint:
${\mathbf{neq}}\ge 1$.
2: $\mathbf{fcn}$ – function, supplied by the userExternal Function
fcn must evaluate the first derivatives ${y}_{i}^{\prime}$ (i.e., the functions ${f}_{i}$) for given values of their arguments $x,{y}_{1},{y}_{2},\dots ,{y}_{{\mathbf{neq}}}$.
On exit: $f[\mathit{i}-1]$ must contain the value of ${f}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,{\mathbf{neq}}$.
5: $\mathbf{comm}$ – Nag_User *
Pointer to a structure of type Nag_User with the following member:
p – Pointer
On entry/exit: the pointer $\mathbf{comm}\mathbf{\to}\mathbf{p}$ 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:fcn should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by d02ejc. If your code inadvertently does return any NaNs or infinities, d02ejc is likely to produce unexpected results.
3: $\mathbf{pederv}$ – function, supplied by the userExternal Function
pederv must evaluate the Jacobian of the system (that is, the partial derivatives $\frac{\partial {f}_{i}}{\partial {y}_{j}}$) for given values of the variables $x,{y}_{1},{y}_{2},\dots ,{y}_{{\mathbf{neq}}}$.
On exit: ${\mathbf{pw}}\left[(i-1)\times {\mathbf{neq}}+j-1\right]$ must contain the value of $\frac{\partial {f}_{i}}{\partial {y}_{j}}$, for $i,j=1,2,\dots ,{\mathbf{neq}}$.
5: $\mathbf{comm}$ – Nag_User *
Pointer to a structure of type Nag_User with the following member:
p – Pointer
On entry/exit: the pointer $\mathbf{comm}\mathbf{\to}\mathbf{p}$ 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:pederv should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by d02ejc. If your code inadvertently does return any NaNs or infinities, d02ejc is likely to produce unexpected results.
If you do not wish to supply the Jacobian, the actual argument pederv must be the NAG defined null function pointer NULLFN.
4: $\mathbf{x}$ – double *Input/Output
On entry: the value of the independent variable $x$.
Constraint:
${\mathbf{x}}\ne {\mathbf{xend}}$.
On exit: if $g$ is supplied, x contains the point where $g(x,y)=0.0$, unless $g(x,y)\ne 0.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.
On entry: $y[\mathit{i}-1]$ holds the value of the variable ${y}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,{\mathbf{neq}}$.
On exit: the computed values of the solution at the final point $x={\mathbf{x}}$.
6: $\mathbf{xend}$ – doubleInput
On entry: the final value of the independent variable.
${\mathbf{xend}}<{\mathbf{x}}$
Iintegration proceeds in the negative direction.
Constraint:
${\mathbf{xend}}\ne {\mathbf{x}}$.
7: $\mathbf{tol}$ – doubleInput
On entry: a positive tolerance for controlling the error in the integration. Hence tol affects the determination of the position where $g(x,y)=0.0$, if $g$ is supplied.
d02ejc 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 d02ejc 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 d02ejc with ${\mathbf{tol}}={10}^{-p}$ and ${\mathbf{tol}}={10}^{-p-1}$ if $p$ correct decimal digits are required in the solution.
Constraint:
${\mathbf{tol}}>0.0$.
8: $\mathbf{err\_c}$ – Nag_ErrorControlInput
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 $\epsilon $ is a small machine-dependent number and ${e}_{i}$ is an estimate of the local error at ${y}_{i}$, 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 err_c should be set to $\mathrm{Nag\_Absolute}$ on entry, whereas if the error requirement is in terms of the number of correct significant digits, then err_c should be set to $\mathrm{Nag\_Relative}$. If you prefer a mixed error test, then err_c should be set to $\mathrm{Nag\_Mixed}$. The recommended value for err_c is $\mathrm{Nag\_Relative}$.
Constraint:
${\mathbf{err\_c}}=\mathrm{Nag\_Absolute}$, $\mathrm{Nag\_Mixed}$ or $\mathrm{Nag\_Relative}$.
9: $\mathbf{output}$ – function, supplied by the userExternal Function
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 d02ejc with ${\mathbf{xsol}}={\mathbf{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, d02ejc will integrate to xend with no further calls to output; if a call to output is required at the point ${\mathbf{xsol}}={\mathbf{xend}}$, then xsol must be given precisely the value xend.
On entry: $y[\mathit{i}-1]$ holds the value of the variable ${y}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,{\mathbf{neq}}$.
4: $\mathbf{comm}$ – Nag_User *
Pointer to a structure of type Nag_User with the following member:
p – Pointer
On entry/exit: the pointer $\mathbf{comm}\mathbf{\to}\mathbf{p}$ 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:output should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by d02ejc. If your code inadvertently does return any NaNs or infinities, d02ejc is likely to produce unexpected results.
If you do not wish to access intermediate output, the actual argument output must be the NAG defined null function pointer NULLFN.
10: $\mathbf{g}$ – function, supplied by the userExternal Function
g must evaluate $g(x,y)$ for specified values $x,y$. It specifies the function $g$ for which the first position $x$ where $g(x,y)=0$ is to be found.
On entry: $y[\mathit{i}-1]$ holds the value of the variable ${y}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,{\mathbf{neq}}$.
4: $\mathbf{comm}$ – Nag_User *
Pointer to a structure of type Nag_User with the following member:
p – Pointer
On entry/exit: the pointer $\mathbf{comm}\mathbf{\to}\mathbf{p}$ 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:g should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by d02ejc. If your code inadvertently does return any NaNs or infinities, d02ejc is likely to produce unexpected results.
If you do not require the root finding option, the actual argument g must be the NAG defined null double function pointer NULLDFN.
11: $\mathbf{comm}$ – Nag_User *
Pointer to a structure of type Nag_User with the following member:
p – Pointer
On entry/exit: the pointer $\mathbf{comm}\mathbf{\to}\mathbf{p}$, of type Pointer, allows you to communicate information to and from fcn, pederv, output and g. An object of the required type should be declared, e.g., a structure, and its address assigned to the pointer $\mathbf{comm}\mathbf{\to}\mathbf{p}$ 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.
12: $\mathbf{fail}$ – NagError *Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).
6Error Indicators and Warnings
NE_2_REAL_ARG_EQ
On entry, ${\mathbf{x}}=\u27e8\mathit{\text{value}}\u27e9$ while ${\mathbf{xend}}=\u27e8\mathit{\text{value}}\u27e9$. These arguments must satisfy ${\mathbf{x}}\ne {\mathbf{xend}}$.
On entry, ${\mathbf{neq}}=\u27e8\mathit{\text{value}}\u27e9$.
Constraint: ${\mathbf{neq}}\ge 1$.
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_NO_SIGN_CHANGE
No change in sign of the function $g(x,y)$ was detected in the integration range.
NE_REAL_ARG_LE
On entry, tol must not be less than or equal to 0.0: ${\mathbf{tol}}=\u27e8\mathit{\text{value}}\u27e9$.
NE_TOL_PROGRESS
The value of tol, $\u27e8\mathit{\text{value}}\u27e9$, is too small for the function to make any further progress across the integration range. Current value of ${\mathbf{x}}=\u27e8\mathit{\text{value}}\u27e9$.
NE_TOL_TOO_SMALL
The value of tol, $\u27e8\mathit{\text{value}}\u27e9$, is too small for the function to take an initial step.
NE_XSOL_INCONSIST
On call $\u27e8\mathit{\text{value}}\u27e9$ to the supplied print function xsol was set to a value behind the previous value of xsol in the direction of integration.
Previous ${\mathbf{xsol}}=\u27e8\mathit{\text{value}}\u27e9$, ${\mathbf{xend}}=\u27e8\mathit{\text{value}}\u27e9$, new ${\mathbf{xsol}}=\u27e8\mathit{\text{value}}\u27e9$.
NE_XSOL_NOT_RESET
On call $\u27e8\mathit{\text{value}}\u27e9$ to the supplied print function xsol was not reset.
NE_XSOL_SET_WRONG
xsol was set to a value behind x in the direction of integration by the first call to the supplied print function.
The integration range is $(\u27e8\mathit{\text{value}}\u27e9,\u27e8\mathit{\text{value}}\u27e9)$, ${\mathbf{xsol}}=\u27e8\mathit{\text{value}}\u27e9$.
7Accuracy
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 ${\mathbf{err\_c}}=\mathrm{Nag\_Relative}$ 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 $\frac{\partial g}{\partial x}$ and $\frac{\partial g}{\partial {y}_{\mathit{i}}}$, for $\mathit{i}=1,2,\dots ,{\mathbf{neq}}$. Large values for these quantities may imply large errors in the root.
8Parallelism and Performance
Background information to multithreading can be found in the Multithreading documentation.
d02ejc is not threaded in any implementation.
9Further Comments
If more than one root is required, then to determine the second and later roots d02ejc may be called again starting a short distance past the previously determined roots.
If it is easy to code, you should supply the function 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 (${\mathbf{fail}}\mathbf{.}\mathbf{code}={\mathbf{NE\_TOL\_PROGRESS}}$).
10Example
We illustrate the solution of five different problems. In each case the differential system is the well-known stiff Robertson problem.
with initial conditions ${y}_{1}=1.0$, ${y}_{2}={y}_{3}=0.0$ at $x=0.0$. We solve each of the following problems with local error tolerances $\text{1.0e\u22123}$ and $\text{1.0e\u22124}$.
(i)To integrate to $x=10.0$ producing output at intervals of $2.0$ until a point is encountered where ${y}_{1}=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 root-finding termination condition.
(v)Integrating the equations as in (i) but with no intermediate output and no root-finding termination condition.