Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_ode_ivp_rkts_errass (d02pu)

## Purpose

nag_ode_ivp_rkts_errass (d02pu) provides details about global error assessment computed during an integration with either nag_ode_ivp_rkts_range (d02pe) or nag_ode_ivp_rkts_onestep (d02pf).

## Syntax

[rmserr, errmax, terrmx, iwsav, rwsav, ifail] = d02pu(n, iwsav, rwsav)
[rmserr, errmax, terrmx, iwsav, rwsav, ifail] = nag_ode_ivp_rkts_errass(n, iwsav, rwsav)

## Description

nag_ode_ivp_rkts_errass (d02pu) and its associated functions (nag_ode_ivp_rkts_range (d02pe), nag_ode_ivp_rkts_onestep (d02pf), nag_ode_ivp_rkts_setup (d02pq), nag_ode_ivp_rkts_reset_tend (d02pr), nag_ode_ivp_rkts_interp (d02ps) and nag_ode_ivp_rkts_diag (d02pt)) 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 (see Brankin et al. (1991)), integrate
 y′ = f(t,y)  given  y(t0) = y0 $y′=f(t,y) given y(t0)=y0$
where y$y$ is the vector of n$\mathit{n}$ solution components and t$t$ is the independent variable.
After a call to nag_ode_ivp_rkts_range (d02pe) or nag_ode_ivp_rkts_onestep (d02pf), nag_ode_ivp_rkts_errass (d02pu) can be called for information about error assessment, if this assessment was specified in the setup function nag_ode_ivp_rkts_setup (d02pq). A more accurate ‘true’ solution $\stackrel{^}{y}$ is computed in a secondary integration. The error is measured as specified in nag_ode_ivp_rkts_setup (d02pq) for local error control. At each step in the primary integration, an average magnitude μi${\mu }_{i}$ of component yi${y}_{i}$ is computed, and the error in the component is
 (|yi − ŷi|)/(max (μi,thresh(i))). $|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 nag_ode_ivp_rkts_setup (d02pq)). The maximum error seen in any component in the integration so far and the point where the maximum error first occurred are also reported.

## References

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

## Parameters

### Compulsory Input Parameters

1:     n – int64int32nag_int scalar
n$n$, the number of ordinary differential equations in the system to be solved by the integration function.
Constraint: n1${\mathbf{n}}\ge 1$.
2:     iwsav(130$130$) – int64int32nag_int array
3:     rwsav(32 × n + 350$32×{\mathbf{n}}+350$) – double array
These must be the same arrays supplied in a previous call to nag_ode_ivp_rkts_range (d02pe) or nag_ode_ivp_rkts_onestep (d02pf). They must remain unchanged between calls.

None.

None.

### Output Parameters

1:     rmserr(n) – double array
rmserr(i)${\mathbf{rmserr}}\left(\mathit{i}\right)$ approximates the RMS average of the true error of the numerical solution for the i$\mathit{i}$th solution component, for i = 1,2,,n$\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.
2:     errmax – double scalar
The maximum weighted approximate true error taken over all solution components and all steps.
3:     terrmx – double scalar
The first value of the independent variable where an approximate true error attains the maximum value, errmax.
4:     iwsav(130$130$) – int64int32nag_int array
5:     rwsav(32 × n + 350$32×{\mathbf{n}}+350$) – double array
Information about the integration for use on subsequent calls to nag_ode_ivp_rkts_range (d02pe) or nag_ode_ivp_rkts_onestep (d02pf) or other associated functions.
6:     ifail – int64int32nag_int scalar
${\mathrm{ifail}}={\mathbf{0}}$ unless the function detects an error (see [Error Indicators and Warnings]).

## Error Indicators and Warnings

Errors or warnings detected by the function:
ifail = 1${\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 function.
On entry, a previous call to the setup function 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, n = _${\mathbf{n}}=_$, but the value passed to the setup function was .
You cannot call this function before you have called the integrator.
You have already made one call to this function after the the integrator could not achieve specified accuracy.
You cannot call this function again.

## Accuracy

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_rkts_setup (d02pq).

## Example

```function nag_ode_ivp_rkts_errass_example
% Set initial conditions and input
method = int64(3);
tstart = 0;
tend = 3*pi;
ecc = 0.7;
yinit = [1-ecc; 0; 0; sqrt((1+ecc)/(1-ecc))];
hstart = 0;
thresh = [1e-10; 1e-10; 1e-10; 1e-10];
n = int64(4);
npts = 96;
ygot = zeros(n, 1);
ymax = zeros(n, 1);

% Set control for output
tol = 1e-6;
tinc = (tend-tstart)/npts;

% Call setup function
[iwsav, rwsav, ifail] = nag_ode_ivp_rkts_setup(tstart, tend, yinit, tol, thresh, method);

fprintf('\nCalculation with TOL = %8.1e\n\n', tol);
fprintf('    t         y1         y2         y3         y4\n');
fprintf(' %6.3f   %8.4f   %8.4f   %8.4f   %8.4f\n', tstart, yinit);

twant = tend;

ifail = int64(3);
while ifail == 2 || ifail == 3 || ifail == 4
[tgot, ygot, ypgot, ymax, user, iwsav, rwsav, ifail] = ...
nag_ode_ivp_rkts_range(@f, twant, ygot, ymax, iwsav, rwsav);
end

% Print Solution
fprintf(' %6.3f   %8.4f   %8.4f   %8.4f   %8.4f\n', tgot, ygot);

% Compute and print error estimates.
[rmserr, errmax, terrmx, iwsav, rwsav, ifail] = nag_ode_ivp_rkts_errass(n, iwsav, rwsav);

fprintf('\nComponentwise error assessment\n');
fprintf('%9.2e ', rmserr);
fprintf('\nWorst global error observed was %9.2e - it occurred at T = %6.3e\n', errmax, terrmx);

[fevals, stepcost, waste, stepsok, hnext, iwsav, ifail] = ...
nag_ode_ivp_rkts_diag(iwsav, rwsav);
fprintf('\nCost of the integration in evaluations of f is %d\n', fevals);

function [yp, user] = f(t, n, y, user)
r = sqrt(y(1)^2+y(2)^2);
yp = [y(3); y(4); -y(1)/r^3; -y(2)/r^3];
```
```

Calculation with TOL =  1.0e-06

t         y1         y2         y3         y4
0.000     0.3000     0.0000     0.0000     2.3805
9.425    -1.7000     0.0000    -0.0000    -0.4201

Componentwise error assessment
3.81e-06  7.10e-06  6.92e-06  2.10e-06
Worst global error observed was  3.43e-05 - it occurred at T = 6.302e+00

Cost of the integration in evaluations of f is 1361

```
```function d02pu_example
% Set initial conditions and input
method = int64(3);
tstart = 0;
tend = 3*pi;
ecc = 0.7;
yinit = [1-ecc; 0; 0; sqrt((1+ecc)/(1-ecc))];
hstart = 0;
thresh = [1e-10; 1e-10; 1e-10; 1e-10];
n = int64(4);
npts = 96;
ygot = zeros(n, 1);
ymax = zeros(n, 1);

% Set control for output
tol = 1e-6;
tinc = (tend-tstart)/npts;

% Call setup function
[iwsav, rwsav, ifail] = d02pq(tstart, tend, yinit, tol, thresh, method);

fprintf('\nCalculation with TOL = %8.1e\n\n', tol);
fprintf('    t         y1         y2         y3         y4\n');
fprintf(' %6.3f   %8.4f   %8.4f   %8.4f   %8.4f\n', tstart, yinit);

twant = tend;

ifail = int64(3);
while ifail == 2 || ifail == 3 || ifail == 4
[tgot, ygot, ypgot, ymax, user, iwsav, rwsav, ifail] = ...
d02pe(@f, twant, ygot, ymax, iwsav, rwsav);
end

% Print Solution
fprintf(' %6.3f   %8.4f   %8.4f   %8.4f   %8.4f\n', tgot, ygot);

% Compute and print error estimates.
[rmserr, errmax, terrmx, iwsav, rwsav, ifail] = d02pu(n, iwsav, rwsav);

fprintf('\nComponentwise error assessment\n');
fprintf('%9.2e ', rmserr);
fprintf('\nWorst global error observed was %9.2e - it occurred at T = %6.3e\n', errmax, terrmx);

[fevals, stepcost, waste, stepsok, hnext, iwsav, ifail] = ...
d02pt(iwsav, rwsav);
fprintf('\nCost of the integration in evaluations of f is %d\n', fevals);

function [yp, user] = f(t, n, y, user)
r = sqrt(y(1)^2+y(2)^2);
yp = [y(3); y(4); -y(1)/r^3; -y(2)/r^3];
```
```

Calculation with TOL =  1.0e-06

t         y1         y2         y3         y4
0.000     0.3000     0.0000     0.0000     2.3805
9.425    -1.7000     0.0000    -0.0000    -0.4201

Componentwise error assessment
3.81e-06  7.10e-06  6.92e-06  2.10e-06
Worst global error observed was  3.43e-05 - it occurred at T = 6.302e+00

Cost of the integration in evaluations of f is 1361

```