# NAG Library Routine Document

## 1Purpose

d02zaf calculates the weighted norm of the local error estimate from inside a monitr called from an integrator in Sub-chapter D02M–N (e.g., see d02nbf).

## 2Specification

Fortran Interface
 Function d02zaf ( neq, v, w,
 Real (Kind=nag_wp) :: d02zaf Integer, Intent (In) :: neq Integer, Intent (Inout) :: ifail Real (Kind=nag_wp), Intent (In) :: v(neq), w(neq)
#include nagmk26.h
 double d02zaf_ (const Integer *neq, const double v[], const double w[], Integer *ifail)

## 3Description

d02zaf is for use with the direct communication integrators d02nbf, d02ncf, d02ndf, d02ngf, d02nhf and d02njf and the reverse communication integrators d02nmf and d02nnf. It must be used only inside monitr (if this option is selected) for the direct communication routines or on the equivalent return for the reverse communication routines. It may be used to evaluate the norm of the scaled local error estimate, $‖v‖$, where the weights used are contained in $w$ and the norm used is as defined by an earlier call to the integrator setup routine (d02mvf, d02nvf or d02nwf). Its use is described under the description of monitr in the specifications for the direct communication integrators mentioned above.
None.

## 5Arguments

1:     $\mathbf{neq}$ – IntegerInput
On entry: the number of differential equations, as defined for the integrator being used.
2:     $\mathbf{v}\left({\mathbf{neq}}\right)$ – Real (Kind=nag_wp) arrayInput
On entry: the vector, the weighted norm of which is to be evaluated by d02zaf. v is calculated internally by the integrator being used.
3:     $\mathbf{w}\left({\mathbf{neq}}\right)$ – Real (Kind=nag_wp) arrayInput
On entry: the weights, calculated internally by the integrator, to be used in the norm evaluation.
4:     $\mathbf{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, because for this routine the values of the output arguments may be useful even if ${\mathbf{ifail}}\ne {\mathbf{0}}$ on exit, the recommended value is $-1$. When the value $-\mathbf{1}\text{​ or ​}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).

## 6Error 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).
Note: d02zaf may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the routine:
${\mathbf{ifail}}=1$
The value of the norm would either overflow or is close to overflowing. A value close to the square root of the largest number on the computer is returned.
${\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.

## 7Accuracy

The result is calculated close to machine precision except in the case when the routine exits with ${\mathbf{ifail}}={\mathbf{1}}$.

## 8Parallelism and Performance

d02zaf is not thread safe and should not be called from a multithreaded user program. Please see Section 3.12.1 in How to Use the NAG Library and its Documentation for more information on thread safety.
d02zaf is not threaded in any implementation.

d02zaf should only be used within monitr associated with the integrators in Sub-chapter D02M–N (e.g., see d02nbf). Its use and only valid calling sequence are fully documented in the description of monitr in the routine documents for the integrators.

## 10Example

This example solves the well-known stiff Robertson problem
 $a′ = -0.04a + 1.0E4bc b′ = 0.04a - 1.0E4bc - 3.0E7⁢b2 c′ = 3.0E7⁢b2$
over the range $\left[0,10\right]$ with initial conditions $a=1.0$ and $b=c=0.0$ using scalar error control (${\mathbf{itol}}=1$) and computation of the solution at ${\mathbf{tout}}=10.0$ with tcrit (e.g., see d02mvf) set to $10.0$ (${\mathbf{itask}}=4$). A BDF integrator (setup routine d02nvf) is used and a modified Newton method is selected. This example illustrates the use of d02zaf within a monitor routine monitr to output intermediate results during the integration. The same problem is solved in the example program for d02nbf where no monitoring was performed and so no intermediate solution information is output.

### 10.1Program Text

Program Text (d02zafe.f90)

### 10.2Program Data

Program Data (d02zafe.d)

### 10.3Program Results

Program Results (d02zafe.r)

© The Numerical Algorithms Group Ltd, Oxford, UK. 2017