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_rk_diag (d02py)

## Purpose

nag_ode_ivp_rk_diag (d02py) provides details about an integration performed by either nag_ode_ivp_rk_range (d02pc) or nag_ode_ivp_rk_onestep (d02pd).
Note: this function is scheduled to be withdrawn, please see d02py in Advice on Replacement Calls for Withdrawn/Superseded Routines..

## Syntax

[totfcn, stpcst, waste, stpsok, hnext, ifail] = d02py
[totfcn, stpcst, waste, stpsok, hnext, ifail] = nag_ode_ivp_rk_diag

## Description

nag_ode_ivp_rk_diag (d02py) and its associated functions (nag_ode_ivp_rk_range (d02pc), nag_ode_ivp_rk_onestep (d02pd), nag_ode_ivp_rk_setup (d02pv), nag_ode_ivp_rk_reset_tend (d02pw), nag_ode_ivp_rk_interp (d02px) and nag_ode_ivp_rk_errass (d02pz)) 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$n$ solution components and t$t$ is the independent variable.
After a call to nag_ode_ivp_rk_range (d02pc) or nag_ode_ivp_rk_onestep (d02pd), nag_ode_ivp_rk_diag (d02py) can be called to obtain information about the cost of the integration and the size of the next step.

## 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

None.

None.

None.

### Output Parameters

1:     totfcn – int64int32nag_int scalar
The total number of evaluations of f$f$ used in the primary integration so far; this includes evaluations of f$f$ for the secondary integration specified by a prior call to nag_ode_ivp_rk_setup (d02pv) with errass = true${\mathbf{errass}}=\mathbf{true}$.
2:     stpcst – int64int32nag_int scalar
The cost in terms of number of evaluations of f$f$ of a typical step with the method being used for the integration. The method is specified by the parameter method in a prior call to nag_ode_ivp_rk_setup (d02pv).
3:     waste – double scalar
The number of attempted steps that failed to meet the local error requirement divided by the total number of steps attempted so far in the integration. A ‘large’ fraction indicates that the integrator is having trouble with the problem being solved. This can happen when the problem is ‘stiff’ and also when the solution has discontinuities in a low-order derivative.
4:     stpsok – int64int32nag_int scalar
The number of accepted steps.
5:     hnext – double scalar
The step size the integrator will attempt to use for the next step.
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$
An invalid call to nag_ode_ivp_rk_diag (d02py) has been made, for example without a previous call to nag_ode_ivp_rk_range (d02pc) or nag_ode_ivp_rk_onestep (d02pd). You cannot continue integrating the problem.

## Accuracy

Not applicable.

When a secondary integration has taken place, that is when global error assessment has been specified using errass = true${\mathbf{errass}}=\mathbf{true}$ in a prior call to nag_ode_ivp_rk_setup (d02pv), then the approximate extra number of evaluations of f$f$ used is given by 2 × stpsok × stpcst$2×{\mathbf{stpsok}}×{\mathbf{stpcst}}$ for method = 2${\mathbf{method}}=2$ or 3$3$ and 3 × stpsok × stpcst$3×{\mathbf{stpsok}}×{\mathbf{stpcst}}$ for method = 1${\mathbf{method}}=1$.

## Example

```function nag_ode_ivp_rk_diag_example
tstart = 0;
ystart = [0; 1];
tend = 6.283185307179586;
tol = 0.001;
thres = [1e-08; 1e-08];
method = int64(2);
errass = false;
lenwrk = int64(64);
neq = int64(2);
twant = 0.3926990816987241;
reqest = 'Both';
nwant = int64(1);
wrkint = zeros(7, 1);
[work, ifail] = ...
nag_ode_ivp_rk_setup(tstart, ystart, tend, tol, thres, method, task, errass, lenwrk);
npts = 16;
tnow = tend-1;
while (tnow < tend)
[tnow, ynow, ypnow, work, ifail] = nag_ode_ivp_rk_onestep(@f, neq, work);
j = npts -1;
tinc = tend/npts;
while (twant <= tnow)
[ywant, ypwant, work, wrkint, ifail] = ...
nag_ode_ivp_rk_interp(neq, twant, reqest, nwant, @f, work, wrkint);
j = j-1;
twant = tend -j*tinc;
end
end
[totfcn, stpcst, waste, stpsok, hnext, ifail] = nag_ode_ivp_rk_diag

function [yp] = f(t, y)
% Evaluate derivative vector.
yp = zeros(2, 1);
yp(1) =  y(2);
yp(2) = -y(1);
```
```

totfcn =

68

stpcst =

7

waste =

0.1429

stpsok =

6

hnext =

1.4387

ifail =

0

```
```function d02py_example
tstart = 0;
ystart = [0; 1];
tend = 6.283185307179586;
tol = 0.001;
thres = [1e-08; 1e-08];
method = int64(2);
errass = false;
lenwrk = int64(64);
neq = int64(2);
twant = 0.3926990816987241;
reqest = 'Both';
nwant = int64(1);
wrkint = zeros(7, 1);
[work, ifail] = ...
d02pv(tstart, ystart, tend, tol, thres, method, task, errass, lenwrk);
npts = 16;
tnow = tend-1;
while (tnow < tend)
[tnow, ynow, ypnow, work, ifail] = d02pd(@f, neq, work);
j = npts -1;
tinc = tend/npts;
while (twant <= tnow)
[ywant, ypwant, work, wrkint, ifail] = ...
d02px(neq, twant, reqest, nwant, @f, work, wrkint);
j = j-1;
twant = tend -j*tinc;
end
end
[totfcn, stpcst, waste, stpsok, hnext, ifail] = d02py

function [yp] = f(t, y)
% Evaluate derivative vector.
yp = zeros(2, 1);
yp(1) =  y(2);
yp(2) = -y(1);
```
```

totfcn =

68

stpcst =

7

waste =

0.1429

stpsok =

6

hnext =

1.4387

ifail =

0

```