D02 Chapter Contents
D02 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentD02MWF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

## 1  Purpose

D02MWF is a setup routine which must be called prior to the integrator D02NEF, if the DASSL implementation of Backward Differentiation Formulae (BDF) is to be used.

## 2  Specification

 SUBROUTINE D02MWF ( NEQ, MAXORD, JCEVAL, HMAX, H0, ITOL, ICOM, LICOM, COM, LCOM, IFAIL)
 INTEGER NEQ, MAXORD, ITOL, ICOM(LICOM), LICOM, LCOM, IFAIL REAL (KIND=nag_wp) HMAX, H0, COM(LCOM) CHARACTER(1) JCEVAL

## 3  Description

This integrator setup routine must be called before the first call to the integrator D02NEF. This setup routine D02MWF permits you to define options for the DASSL integrator, such as: whether the Jacobian is to be provided or is to be approximated numerically by the integrator; the initial and maximum step-sizes for the integration; whether relative and absolute tolerances are system wide or per system equation; and the maximum order of BDF method permitted.

None.

## 5  Arguments

1:     $\mathrm{NEQ}$ – INTEGERInput
On entry: the number of differential-algebraic equations to be solved.
Constraint: ${\mathbf{NEQ}}\ge 1$.
2:     $\mathrm{MAXORD}$ – INTEGERInput
On entry: the maximum order to be used for the BDF method. Orders up to 5th order are available; setting ${\mathbf{MAXORD}}>5$ means that the maximum order used will be $5$.
Constraint: $1\le {\mathbf{MAXORD}}$.
3:     $\mathrm{JCEVAL}$ – CHARACTER(1)Input
On entry: specifies the technique to be used to compute the Jacobian.
${\mathbf{JCEVAL}}=\text{'N'}$
The Jacobian is to be evaluated numerically by the integrator.
${\mathbf{JCEVAL}}=\text{'A'}$
You must supply a subroutine to evaluate the Jacobian on a call to the integrator.
Only the first character of the actual paramater JCEVAL is passed to D02MWF; hence it is permissible for the actual argument to be more descriptive, e.g., ‘Numerical’ or ‘Analytical’, on a call to D02MWF.
Constraint: ${\mathbf{JCEVAL}}=\text{'N'}$ or $\text{'A'}$.
4:     $\mathrm{HMAX}$ – REAL (KIND=nag_wp)Input
On entry: the maximum absolute step size to be allowed. Set ${\mathbf{HMAX}}=0.0$ if this option is not required.
Constraint: ${\mathbf{HMAX}}\ge 0.0$.
5:     $\mathrm{H0}$ – REAL (KIND=nag_wp)Input
On entry: the step size to be attempted on the first step. Set ${\mathbf{H0}}=0.0$ if the initial step size is calculated internally.
6:     $\mathrm{ITOL}$ – INTEGERInput
On entry: a value to indicate the form of the local error test.
${\mathbf{ITOL}}=0$
RTOL and ATOL are single element vectors.
${\mathbf{ITOL}}=1$
RTOL and ATOL are vectors. This should be chosen if you want to apply different tolerances to each equation in the system.
See D02NEF.
Note: the tolerances must either both be single element vectors or both be vectors of length NEQ.
Constraint: ${\mathbf{ITOL}}=0$ or $1$.
7:     $\mathrm{ICOM}\left({\mathbf{LICOM}}\right)$ – INTEGER arrayCommunication Array
On exit: used to communicate details of the task to be carried out to the integration routine D02NEF.
8:     $\mathrm{LICOM}$ – INTEGERInput
On entry: the dimension of the array ICOM as declared in the (sub)program from which D02MWF is called.
Constraint: ${\mathbf{LICOM}}\ge {\mathbf{NEQ}}+50$.
9:     $\mathrm{COM}\left({\mathbf{LCOM}}\right)$ – REAL (KIND=nag_wp) arrayCommunication Array
On exit: used to communicate problem parameters to the integration routine D02NEF. This must be the same communication array as the array COM supplied to D02NEF. In particular, the values of HMAX and H0 are contained in COM.
10:   $\mathrm{LCOM}$ – INTEGERInput
On entry: the dimension of the array COM as declared in the (sub)program from which D02MWF is called.
Constraints:
the array COM must be large enough for the requirements of D02NEF. That is:
• if the system Jacobian is dense, ${\mathbf{LCOM}}\ge 40+\left({\mathbf{MAXORD}}+4\right)×{\mathbf{NEQ}}+{{\mathbf{NEQ}}}^{2}$;
• if the system Jacobian is banded, ${\mathbf{LCOM}}\ge 40+\left({\mathbf{MAXORD}}+4\right)×{\mathbf{NEQ}}+\left(2×{\mathbf{ML}}+{\mathbf{MU}}+1\right)×{\mathbf{NEQ}}+2×\phantom{\rule{0ex}{0ex}}\left({\mathbf{NEQ}}/\left({\mathbf{ML}}+{\mathbf{MU}}+1\right)+1\right)$.
Here ML and MU are the lower and upper bandwidths respectively that are to be specified in a subsequent call to D02NPF.
11:   $\mathrm{IFAIL}$ – INTEGERInput/Output
On entry: IFAIL must be set to $0$, $-1\text{​ 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\text{​ 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 $-\mathbf{1}\text{​ or ​}\mathbf{1}$ is used it is essential to test the value of IFAIL on exit.
On exit: ${\mathbf{IFAIL}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6  Error Indicators and Warnings

If on entry ${\mathbf{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:
${\mathbf{IFAIL}}=1$
On entry, ${\mathbf{NEQ}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{NEQ}}\ge 1$.
${\mathbf{IFAIL}}=2$
On entry, ${\mathbf{MAXORD}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{MAXORD}}\ge 1$.
${\mathbf{IFAIL}}=3$
On entry, JCEVAL has an illegal value: ${\mathbf{JCEVAL}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{JCEVAL}}=\text{'N'}$ or $\text{'A'}$.
${\mathbf{IFAIL}}=4$
On entry, ${\mathbf{HMAX}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{HMAX}}\ge 0.0$.
${\mathbf{IFAIL}}=6$
On entry, ${\mathbf{ITOL}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{ITOL}}=0$ or $1$.
${\mathbf{IFAIL}}=8$
On entry, ${\mathbf{LICOM}}=〈\mathit{\text{value}}〉$ and ${\mathbf{NEQ}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{LICOM}}\ge 50+{\mathbf{NEQ}}$.
${\mathbf{IFAIL}}=-99$
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{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.
${\mathbf{IFAIL}}=-999$
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.

Not applicable.

## 8  Parallelism and Performance

D02MWF is not threaded in any implementation.

None.

## 10  Example

This example solves the plane pendulum problem, defined by the following equations:
 $x′ = u y′ = v u′ = -λx v′ = -λy-1 x2+y2 = 1.$
Differentiating the algebraic constraint once, a new algebraic constraint is obtained
 $xu+yv=0 .$
Differentiating the algebraic constraint one more time, substituting for ${x}^{\prime }$, ${y}^{\prime }$, ${u}^{\prime }$, ${v}^{\prime }$ and using ${x}^{2}+{y}^{2}-1=0$, the corresponding DAE system includes the differential equations and the algebraic equation in $\lambda$:
 $u2 + v2 - λ - y = 0 .$
We solve the reformulated DAE system
 $y1′ = y3 y2′ = y4 y3′ = -y5×y1 y4′ = -y5×y2-1 y32 + y42 - y5 - y2 = 0.$
For our experiments, we take consistent initial values
 $y10 = 1 , ​ y20 = 0 , ​ y30 = 0 , ​ y40 = 1 ​ and ​ y50 = 1$
at $t=0$.

### 10.1  Program Text

Program Text (d02mwfe.f90)

### 10.2  Program Data

Program Data (d02mwfe.d)

### 10.3  Program Results

Program Results (d02mwfe.r)