d02 Chapter Contents
d02 Chapter Introduction
NAG Library Manual

# NAG Library Function Documentnag_ode_ivp_rk_errass (d02pzc)

## 1  Purpose

nag_ode_ivp_rk_errass (d02pzc) provides details about global error assessment computed during an integration with either nag_ode_ivp_rk_range (d02pcc) or nag_ode_ivp_rk_onestep (d02pdc).

## 2  Specification

 #include #include
 void nag_ode_ivp_rk_errass (Integer neq, double rmserr[], double *errmax, double *terrmx, Nag_ODE_RK *opt, NagError *fail)

## 3  Description

nag_ode_ivp_rk_errass (d02pzc) and its associated functions (nag_ode_ivp_rk_range (d02pcc), nag_ode_ivp_rk_onestep (d02pdc), nag_ode_ivp_rk_setup (d02pvc), nag_ode_ivp_rk_reset_tend (d02pwc), nag_ode_ivp_rk_interp (d02pxc)) solve the initial value problem for a first order system of ordinary differential equations. The functions, based on Runge–Kutta methods and derived from RKSUITE (Brankin et al. (1991)) integrate
 $y ′ = f t,y given y t 0 = y 0$
where $y$ is the vector of neq solution components and $t$ is the independent variable.
After a call to nag_ode_ivp_rk_range (d02pcc) or nag_ode_ivp_rk_onestep (d02pdc), nag_ode_ivp_rk_errass (d02pzc) can be called for information about error assessment, if this assessment was specified in the setup function nag_ode_ivp_rk_setup (d02pvc). A more accurate ‘`true’' solution $\stackrel{^}{y}$ is computed in a secondary integration. The error is measured as specified in nag_ode_ivp_rk_setup (d02pvc) for local error control. At each step in the primary integration, an average magnitude ${\sigma }_{i}$ of component ${y}_{i}$ is computed, and the error in the component is
 $y i - y ^ i max σ i ,thres,i .$
where $\mathit{thres}\left(i\right)$ denotes the threshold value used in the error requirement, see nag_ode_ivp_rk_setup (d02pvc).
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 nag_ode_ivp_rk_setup (d02pvc)). The maximum error seen in any component in the integration so far and the point where the maximum error first occurred are also reported.
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

## 5  Arguments

1:    $\mathbf{neq}$IntegerInput
On entry: the number of ordinary differential equations in the system.
Constraint: ${\mathbf{neq}}\ge 1$.
2:    $\mathbf{rmserr}\left[{\mathbf{neq}}\right]$doubleOutput
On exit: ${\mathbf{rmserr}}\left[i-1\right]$ approximates the RMS average of the true error of the numerical solution for the $\mathit{i}$th solution component ${y}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,{\mathbf{neq}}$. The average is taken over all steps from the beginning of the integration to the current integration point.
3:    $\mathbf{errmax}$double *Output
On exit: the maximum weighted approximate true error taken over all solution components and all steps.
4:    $\mathbf{terrmx}$double *Output
On exit: the first value of the independent variable where an approximate true error attains the maximum value, errmax.
5:    $\mathbf{opt}$Nag_ODE_RK *Input/Output
On entry: the structure of type Nag_ODE_RK as output from nag_ode_ivp_rk_range (d02pcc) or nag_ode_ivp_rk_onestep (d02pdc). You must not change this structure.
On exit: some members of opt are changed internally.
6:    $\mathbf{fail}$NagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

## 6  Error Indicators and Warnings

NE_ERRASS_REQ
No error assessment is available as it was not requested in the call to nag_ode_ivp_rk_setup (d02pvc).
NE_MEMORY_FREED
Internally allocated memory has been freed by a call to nag_ode_ivp_rk_free (d02ppc) without a subsequent call to the setup function nag_ode_ivp_rk_setup (d02pvc).
NE_MISSING_CALL
Previous call to nag_ode_ivp_rk_range (d02pcc) has not been made, hence nag_ode_ivp_rk_errass (d02pzc) must not be called.
Previous call to nag_ode_ivp_rk_onestep (d02pdc) has not been made, hence nag_ode_ivp_rk_errass (d02pzc) must not be called.
NE_NEQ
The value of neq supplied is not the same as that given to the setup function.
NE_PREV_CALL
The previous call to a function had resulted in a severe error. You must call nag_ode_ivp_rk_setup (d02pvc) to start another problem.
NE_PREV_CALL_INI
The previous call to the function nag_ode_ivp_rk_errass (d02pzc) had resulted in a severe error. You must call nag_ode_ivp_rk_setup (d02pvc) to start another problem.
NE_RK_NOSTEP
The integrator has not actually taken any successful steps. This function must not be called in this circumstance.

Not applicable.

## 8  Parallelism and Performance

Not applicable.

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 nag_ode_ivp_rk_setup (d02pvc).

## 10  Example

We integrate 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 ′′ = -x r 3 y ′′ = -y r 3 , r = x 2 + y 2 .$
The intial conditions
 $x 0 = 1 - ε , x ′ 0 = 0 y 0 = 0 , y ′ 0 = 1+ε 1-ε$
lead to elliptic motion with $0<\epsilon <1$. We select $\epsilon =0.7$ and repose as
 $y 1 ′ = y 2 y 2 ′ = y 4 y 3 ′ = - y 1 r 3 y 4 ′ = - y 1 r 3$
over the range $\left[0,3\pi \right]$. We use relative error control with threshold values of $\text{1.0e−10}$ for each solution component and a high order Runge–Kutta method (${\mathbf{method}}=\mathrm{Nag_RK_7_8}$) with tolerance ${\mathbf{tol}}=\text{1.0e−6}$. The value of $\pi$ is obtained by using nag_pi (X01AAC).
Note, for illustration purposes we select to integrate to the end of the range regardless of efficiency concerns.

### 10.1  Program Text

Program Text (d02pzce.c)

None.

### 10.3  Program Results

Program Results (d02pzce.r)