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_stiff_c1_interp (d02xk)

## Purpose

nag_ode_ivp_stiff_c1_interp (d02xk) interpolates components of the solution of a system of first-order ordinary differential equations from information provided by the integrators in Sub-chapter D02M–N. It provides ${C}^{1}$ interpolation suitable for general use.

## Syntax

[sol, ifail] = d02xk(xsol, m, ysav, acor, x, nqu, hu, h, 'sdysav', sdysav, 'neq', neq)
[sol, ifail] = nag_ode_ivp_stiff_c1_interp(xsol, m, ysav, acor, x, nqu, hu, h, 'sdysav', sdysav, 'neq', neq)
Note: the interface to this routine has changed since earlier releases of the toolbox:
 At Mark 22: neq was made optional

## Description

nag_ode_ivp_stiff_c1_interp (d02xk) evaluates the first $m$ components of the solution of a system of ordinary differential equations at any point using ${C}^{1}$ polynomial interpolation based on information generated by the integrator. This information must be passed unchanged to nag_ode_ivp_stiff_c1_interp (d02xk). nag_ode_ivp_stiff_c1_interp (d02xk) should not normally be used to extrapolate outside the range of values obtained from the above functions.
It may be used with the D02N functions only when the BDF integration method is being employed (setup function nag_ode_ivp_stiff_bdf (d02nv)), provided the Petzold error test was not selected.

None.

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{xsol}$ – double scalar
The point at which the first $m$ components of the solution are to be evaluated. xsol should not be an extrapolation point, that is xsol should satisfy $\left({\mathbf{xsol}}-{\mathbf{x}}\right)×{\mathbf{hu}}\le 0.0$. Extrapolation is permitted but not recommended.
2:     $\mathrm{m}$int64int32nag_int scalar
The number of components of the solution whose values at xsol are required. The first $m$ components are evaluated.
Constraint: $1\le {\mathbf{m}}\le {\mathbf{neq}}$.
3:     $\mathrm{ysav}\left(\mathit{ldysav},{\mathbf{sdysav}}\right)$ – double array
ldysav, the first dimension of the array, must satisfy the constraint $\mathit{ldysav}\ge 1$.
The values provided in the argument ysav on return from the integrator.
4:     $\mathrm{acor}\left({\mathbf{neq}}\right)$ – double array
The value returned in position $\left(\mathit{ldysav}+50+\mathit{i}\right)$, for $\mathit{i}=1,2,\dots ,{\mathbf{neq}}$, of the argument rwork returned by the integrator. If one of the forward communication D02N functions is being employed and nag_ode_ivp_stiff_c1_interp (d02xk) is to be used in monitr, then ${\mathbf{acor}}\left(\mathit{i}\right)$ must contain the value given in position $\left(\mathit{i},2\right)$ of the monitr argument acor, for $\mathit{i}=1,2,\dots ,{\mathbf{neq}}$ (e.g., see nag_ode_ivp_stiff_exp_fulljac (d02nb)).
5:     $\mathrm{x}$ – double scalar
The latest value at which the solution has been computed, as provided in the argument tcur on return from the optional output nag_ode_ivp_stiff_integ_diag (d02ny).
6:     $\mathrm{nqu}$int64int32nag_int scalar
The order of the method used up to the latest value at which the solution has been computed, as provided in the argument nqu on return from the optional output nag_ode_ivp_stiff_integ_diag (d02ny).
Constraint: ${\mathbf{nqu}}\ge 1$.
7:     $\mathrm{hu}$ – double scalar
The last successful step used, that is the step used in the integration to get to x, as provided in the argument hu on return from the optional output nag_ode_ivp_stiff_integ_diag (d02ny).
8:     $\mathrm{h}$ – double scalar
The next step size to be attempted in the integration, as provided in the argument h on return from the optional output nag_ode_ivp_stiff_integ_diag (d02ny).

### Optional Input Parameters

1:     $\mathrm{sdysav}$int64int32nag_int scalar
Default: the second dimension of the array ysav.
The value used for the argument sdysav when calling the integrator.
Constraint: ${\mathbf{sdysav}}\ge {\mathbf{nqu}}+1$.
2:     $\mathrm{neq}$int64int32nag_int scalar
Default: the dimension of the array acor.
The value used for the argument neq when calling the integrator.
Constraint: $1\le {\mathbf{neq}}\le \mathit{ldysav}$.

### Output Parameters

1:     $\mathrm{sol}\left({\mathbf{m}}\right)$ – double array
The calculated value of the $\mathit{i}$th component of the solution at xsol, for $\mathit{i}=1,2,\dots ,m$.
2:     $\mathrm{ifail}$int64int32nag_int scalar
${\mathbf{ifail}}={\mathbf{0}}$ unless the function detects an error (see Error Indicators and Warnings).
If nag_ode_ivp_stiff_c1_interp (d02xk) is to be used for extrapolation, ifail must be set to $1$ before entry. It is then essential to test the value of ifail on exit for ${\mathbf{ifail}}={\mathbf{1}}$ or ${\mathbf{2}}$.

## Error Indicators and Warnings

Errors or warnings detected by the function:

Cases prefixed with W are classified as warnings and do not generate an error of type NAG:error_n. See nag_issue_warnings.

${\mathbf{ifail}}=1$
 On entry, ${\mathbf{m}}<1$, or ${\mathbf{neq}}<1$, or $\mathit{ldysav}<1$, or ${\mathbf{neq}}>\mathit{ldysav}$, or ${\mathbf{m}}>{\mathbf{neq}}$, or ${\mathbf{nqu}}<1$, or ${\mathbf{sdysav}}<{\mathbf{nqu}}+1$, or the BDF integrator was not previously used, or the Petzold error test, if applicable, was used.
${\mathbf{ifail}}=2$
On entry, ${\mathbf{hu}}=0.0$ or ${\mathbf{h}}=0.0$. This error can only occur if h and hu have been changed by you or possibly if the integrator has failed before calling nag_ode_ivp_stiff_c1_interp (d02xk).
W  ${\mathbf{ifail}}=3$
nag_ode_ivp_stiff_c1_interp (d02xk) has been called for extrapolation. Before returning with this error exit, the value of the solution at xsol is calculated and placed in sol.
${\mathbf{ifail}}=-99$
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

## Accuracy

The solution values returned will be of a similar accuracy to those computed by the integrator.

nag_ode_ivp_stiff_c1_interp (d02xk) provides a ${C}^{1}$ interpolant and as such is ideal for most applications, for example for tabulation and root-finding. In general nag_ode_ivp_stiff_c1_interp (d02xk) should be preferred to nag_ode_ivp_stiff_nat_interp (d02xj) for interpolation as the latter provides only a ${C}^{0}$ interpolant. nag_ode_ivp_stiff_nat_interp (d02xj) is the natural interpolant employed by the BDF method and it is supplied only to permit you to reproduce the internal values used by the integrator.

## Example

```function d02xk_example

fprintf('d02xk example results\n\n');

% Initialize setup setup variables and arrays.
neq    = int64(3);
neqmax = neq;
maxord = int64(5);
sdysav = maxord+1;
petzld = false;
tcrit  = 0;
hmin   = 1.0e-10;
hmax   = 10;
h0     = 0;
maxstp = int64(200);
mxhnil = int64(5);
const  = zeros(6, 1);
rwork  = zeros(50+4*neq, 1);

% BDF with Newton iterations.
[const, rwork, ifail] = d02nv( ...
neqmax, sdysav, maxord, 'Newton', petzld, ...
const, tcrit, hmin, hmax, h0, maxstp, ...
mxhnil, 'Average-L2', rwork);

% Numerical Jacobian
nwkjac = neqmax*(neqmax + 1);
[rwork, ifail] = d02ns( ...
neq, neqmax, 'Numerical', nwkjac, rwork);

% Initialize variables and arrays.
njcpvt = int64(1);
wkjac  = zeros(nwkjac, 1);
ydot   = zeros(neq, 1);
ysave  = zeros(neq, sdysav);
inform(1:23) = int64(0);
jacpvt(1) = int64(0);
algequ = zeros(neq, 1);

% Integrate to tout by overshooting (itask = 1).
% At monitoring stages output intermediate solutions after interpolating.
t     = 0;
tout  = 10.0;
iout  = 1;
xout  = 2;
y     = [1; 0; 0];
itol  = int64(1);
rtol  = [1e-04];
atol  = [1e-07];

% Output header and initial results.
fprintf('\n      x           y(1)       y(2)          y(3)\n');
fprintf(' %8.3f %12.4f %12.2e %11.4f\n', t, y);

% bogus initial entry values for unitialized input parameters.
irevcm = int64(-999); imon = irevcm; inln = irevcm; ires = irevcm;

% Ask for warning messages only.
itrace = int64(0);

% The reverse communication process is controlled by the value of irevcm
% (which is 0 for the final exit).
while (irevcm ~= 0)
[t, y, ydot, rwork, inform, ysave, wkjac, jacpvt, imon, inln, ires, ...
irevcm, ifail] = d02nm( ...
t, tout, y, ydot, rwork, rtol, atol, itol, ...
inform, ysave, wkjac, jacpvt, imon, inln, ...
ires, irevcm, itask, itrace, 'neq', neq, ...
'sdysav', sdysav, 'nwkjac', nwkjac);

% Evaluate the derivative, then use irevcm to place it.
f(1) = -0.04*y(1) + 1.0e4*y(2)*y(3);
f(2) =  0.04*y(1) - 1.0e4*y(2)*y(3) - 3.0e7*y(2)*y(2);
f(3) =  3.0e7*y(2)*y(2);
if (irevcm == 1 || irevcm == 3 )
lrw = 50+2*neq;
rwork(lrw+1:lrw+neq) = f;
elseif (irevcm == 4)
lrw = 50+neq;
rwork(lrw+1:lrw+neq) = f;
elseif (irevcm == 5)
ydot = f;
elseif (irevcm == 9 && imon == 1)
% Extract useful information about the current step.
tc    = rwork(19);
hlast = rwork(15);
hnext = rwork(16);
nqu   = int64(rwork(10));

% xout is intermediate output point.
while (xout <= tc)
lrw = 50+neq;
[sol, ifail] = d02xk( ...
xout, neq, ysave, rwork(lrw+1:lrw+neq), ...
tc, nqu, hlast, hnext);
% Output interpolated result, and save it for plotting.
fprintf(' %8.3f %12.4f %12.2e %11.4f\n', xout, sol);
iout = iout + 1;
xout = iout*2;
end
end
end

```
```d02xk example results

x           y(1)       y(2)          y(3)
0.000       1.0000     0.00e+00      0.0000
2.000       0.9416     2.70e-05      0.0584
4.000       0.9055     2.24e-05      0.0945
6.000       0.8793     1.96e-05      0.1207
8.000       0.8585     1.77e-05      0.1414
10.000       0.8414     1.62e-05      0.1586
```