# NAG Library Routine Document

## 1Purpose

d02puf provides details about global error assessment computed during an integration with either d02pef, d02pff or d02pgf.

## 2Specification

Fortran Interface
 Subroutine d02puf ( n,
 Integer, Intent (In) :: n Integer, Intent (Inout) :: iwsav(130), ifail Real (Kind=nag_wp), Intent (Inout) :: rwsav(32*n+350) Real (Kind=nag_wp), Intent (Out) :: rmserr(n), errmax, terrmx
#include nagmk26.h
 void d02puf_ (const Integer *n, double rmserr[], double *errmax, double *terrmx, Integer iwsav[], double rwsav[], Integer *ifail)

## 3Description

d02puf and its associated routines (d02pef, d02pff, d02pgf, d02phf, d02pjf, d02pqf, d02prf, d02psf and d02ptf) solve the initial value problem for a first-order system of ordinary differential equations. The routines, based on Runge–Kutta methods and derived from RKSUITE (see Brankin et al. (1991)), integrate
 $y′=ft,y given yt0=y0$
where $y$ is the vector of $\mathit{n}$ solution components and $t$ is the independent variable.
After a call to d02pef, d02pff or d02pgf, d02puf can be called for information about error assessment, if this assessment was specified in the setup routine d02pqf. A more accurate ‘true’ solution $\stackrel{^}{y}$ is computed in a secondary integration. The error is measured as specified in d02pqf for local error control. At each step in the primary integration, an average magnitude ${\mu }_{i}$ of component ${y}_{i}$ is computed, and the error in the component is
 $yi-y^i maxμi,threshi .$
It is difficult to estimate reliably the true error at a single point. For this reason the RMS (root-mean-square) average of the estimated global error in each solution component is computed. This average is taken over all steps from the beginning of the integration through to the current integration point. If all has gone well, the average errors reported will be comparable to tol (see d02pqf). The maximum error seen in any component in the integration so far and the point where the maximum error first occurred are also reported.

## 4References

Brankin R W, Gladwell I and Shampine L F (1991) RKSUITE: A suite of Runge–Kutta codes for the initial value problems for ODEs SoftReport 91-S1 Southern Methodist University

## 5Arguments

1:     $\mathbf{n}$ – IntegerInput
On entry: $n$, the number of ordinary differential equations in the system to be solved by the integration routine.
Constraint: ${\mathbf{n}}\ge 1$.
2:     $\mathbf{rmserr}\left({\mathbf{n}}\right)$ – Real (Kind=nag_wp) arrayOutput
On exit: ${\mathbf{rmserr}}\left(\mathit{i}\right)$ approximates the RMS average of the true error of the numerical solution for the $\mathit{i}$th solution component, for $\mathit{i}=1,2,\dots ,\mathit{n}$. The average is taken over all steps from the beginning of the integration to the current integration point.
3:     $\mathbf{errmax}$ – Real (Kind=nag_wp)Output
On exit: the maximum weighted approximate true error taken over all solution components and all steps.
4:     $\mathbf{terrmx}$ – Real (Kind=nag_wp)Output
On exit: the first value of the independent variable where an approximate true error attains the maximum value, errmax.
5:     $\mathbf{iwsav}\left(130\right)$ – Integer arrayCommunication Array
6:     $\mathbf{rwsav}\left(32×{\mathbf{n}}+350\right)$ – Real (Kind=nag_wp) arrayCommunication Array
On entry: these must be the same arrays supplied in a previous call to d02pef, d02pff or d02pgf. They must remain unchanged between calls.
On exit: information about the integration for use on subsequent calls to d02pef, d02pff or d02pgf or other associated routines.
7:     $\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, 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).

## 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).
Errors or warnings detected by the routine:
${\mathbf{ifail}}=1$
No error assessment is available since the integrator has not actually taken any successful steps.
No error assessment is available since you did not ask for it in your call to the setup routine.
On entry, a previous call to the setup routine has not been made or the communication arrays have become corrupted, or a catastrophic error has already been detected elsewhere.
You cannot continue integrating the problem.
On entry, ${\mathbf{n}}=〈\mathit{\text{value}}〉$, but the value passed to the setup routine was ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
You cannot call this routine before you have called the integrator.
You have already made one call to this routine after the integrator could not achieve specified accuracy.
You cannot call this routine again.
${\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.

## 8Parallelism and Performance

d02puf is not threaded in any implementation.

If the integration has proceeded ‘well’ and the problem is smooth enough, stable and not too difficult then the values returned in the arguments rmserr and errmax should be comparable to the value of tol specified in the prior call to d02pqf.

## 10Example

This example integrates a two body problem. The equations for the coordinates $\left(x\left(t\right),y\left(t\right)\right)$ of one body as functions of time $t$ in a suitable frame of reference are
 $x′′=-xr3$
 $y′′=-yr3, r=x2+y2.$
The initial conditions
 $x0=1-ε, x′0=0 y0=0, y′0= 1+ε 1-ε$
lead to elliptic motion with $0<\epsilon <1$. $\epsilon =0.7$ is selected and the system of ODEs is reposed as
 $y1′=y3 y2′=y4 y3′=- y1r3 y4′=- y2r3$
over the range $\left[0,3\pi \right]$. Relative error control is used with threshold values of $\text{1.0E−10}$ for each solution component and a high-order Runge–Kutta method (${\mathbf{method}}=3$) with tolerance ${\mathbf{tol}}=\text{1.0E−6}$.
Note that for illustration purposes since it is not necessary for this problem, this example integrates to the end of the range regardless of efficiency concerns (i.e., returns from d02pef with ${\mathbf{ifail}}={\mathbf{2}}$, ${\mathbf{3}}$ or ${\mathbf{4}}$).

### 10.1Program Text

Program Text (d02pufe.f90)

### 10.2Program Data

Program Data (d02pufe.d)

### 10.3Program Results

Program Results (d02pufe.r)

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