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 C1${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:
Mark 22: neq has been made optional
.

## Description

nag_ode_ivp_stiff_c1_interp (d02xk) evaluates the first m$m$ components of the solution of a system of ordinary differential equations at any point using C1${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:     xsol – double scalar
The point at which the first m$m$ components of the solution are to be evaluated. xsol should not be an extrapolation point, that is xsol should satisfy (xsolx) × hu0.0$\left({\mathbf{xsol}}-{\mathbf{x}}\right)×{\mathbf{hu}}\le 0.0$. Extrapolation is permitted but not recommended.
2:     m – int64int32nag_int scalar
The number of components of the solution whose values at xsol are required. The first m$m$ components are evaluated.
Constraint: 1mneq$1\le {\mathbf{m}}\le {\mathbf{neq}}$.
3:     ysav(ldysav,sdysav) – double array
ldysav, the first dimension of the array, must satisfy the constraint ldysav1$\mathit{ldysav}\ge 1$.
The values provided in the parameter ysav on return from the integrator.
4:     acor(neq) – double array
neq, the dimension of the array, must satisfy the constraint 1neqldysav$1\le {\mathbf{neq}}\le \mathit{ldysav}$.
The value returned in position (ldysav + 50 + i)$\left(\mathit{ldysav}+50+\mathit{i}\right)$, for i = 1,2,,neq$\mathit{i}=1,2,\dots ,{\mathbf{neq}}$, of the parameter 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 acor(i)${\mathbf{acor}}\left(\mathit{i}\right)$ must contain the value given in position (i,2)$\left(\mathit{i},2\right)$ of the monitr parameter acor, for i = 1,2,,neq$\mathit{i}=1,2,\dots ,{\mathbf{neq}}$ (e.g., see nag_ode_ivp_stiff_exp_fulljac (d02nb)).
5:     x – double scalar
The latest value at which the solution has been computed, as provided in the parameter tcur on return from the optional output nag_ode_ivp_stiff_integ_diag (d02ny).
6:     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 parameter nqu on return from the optional output nag_ode_ivp_stiff_integ_diag (d02ny).
Constraint: nqu1${\mathbf{nqu}}\ge 1$.
7:     hu – double scalar
The last successful step used, that is the step used in the integration to get to x, as provided in the parameter hu on return from the optional output nag_ode_ivp_stiff_integ_diag (d02ny).
8:     h – double scalar
The next step size to be attempted in the integration, as provided in the parameter h on return from the optional output nag_ode_ivp_stiff_integ_diag (d02ny).

### Optional Input Parameters

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

ldysav

### Output Parameters

1:     sol(m) – double array
The calculated value of the i$\mathit{i}$th component of the solution at xsol, for i = 1,2,,m$\mathit{i}=1,2,\dots ,m$.
2:     ifail – int64int32nag_int scalar
${\mathrm{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$1$ before entry. It is then essential to test the value of ifail on exit for ${\mathbf{ifail}}={\mathbf{1}}$ or 2${\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.

ifail = 1${\mathbf{ifail}}=1$
 On entry, m < 1${\mathbf{m}}<1$, or neq < 1${\mathbf{neq}}<1$, or ldysav < 1$\mathit{ldysav}<1$, or neq > ldysav${\mathbf{neq}}>\mathit{ldysav}$, or m > neq${\mathbf{m}}>{\mathbf{neq}}$, or nqu < 1${\mathbf{nqu}}<1$, or sdysav < nqu + 1${\mathbf{sdysav}}<{\mathbf{nqu}}+1$, or the BDF integrator was not previously used, or the Petzold error test, if applicable, was used.
ifail = 2${\mathbf{ifail}}=2$
On entry, hu = 0.0${\mathbf{hu}}=0.0$ or h = 0.0${\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 ifail = 3${\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.

## 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 C1${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 C0${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 nag_ode_ivp_stiff_c1_interp_example
neq = 3;
t = 0;
tout = 10;
xout = 2;
iout = 2;
y = [1; 0; 0];
ydot = [0; 0; 0];
rwork = zeros(62,1);
rtol = [0.0001];
atol = [1e-07];
itol = int64(1);
inform = zeros(23,1,'int64');
ysave = zeros(3, 6);
wkjac = zeros(12,1);
jacpvt = [int64(0)];
imon = int64(8185424);
inln = int64(8184256);
ires = int64(1);
irevcm = int64(0);
itrace = int64(0);

lacorb=53;
lacor1 = lacorb + 1;
lacor2 = lacorb + 2;
lacor3 = lacorb + 3;
lsavrb = 56;
lsavr1 = lsavrb + 1;
lsavr2 = lsavrb + 2;
lsavr3 = lsavrb + 3;
[const, rwork, ifail] = ...
nag_ode_ivp_stiff_bdf(int64(3), int64(6), int64(5), 'Newton', false, zeros(6), ...
0, 1e-10, 10, 0, int64(200), int64(5), 'Average-L2', rwork);
[rwork, ifail] = ...
nag_ode_ivp_stiff_fulljac_setup(int64(3), int64(3), 'Numerical', int64(12), rwork);

fprintf('\n      x           y(1)          y(2)          y(3)\n');
fprintf(' %8.3f %13.5f %13.5f %13.5f\n', t, y(1), y(2), y(3));

[t, y, ydot, rwork, inform, ysave, wkjac, jacpvt, imon, inln, ires, irevcm, ifail] = ...
nag_ode_ivp_stiff_exp_revcom(t, tout, y, ydot, rwork, rtol, atol, itol, inform, ysave, ...
wkjac, jacpvt, imon, inln, ires, irevcm, itask, itrace);
while (irevcm ~= 0)
if (irevcm == 1  ||  irevcm == 3)
%   equivalent to fcn evaluation in forward communication routines
rwork(lsavr1) = -0.04*y(1) + 1.0d4*y(2)*y(3);
rwork(lsavr2) = 0.04*y(1) - 1.0d4*y(2)*y(3) - 3.0d7*y(2)*y(2);
rwork(lsavr3) = 3.0d7*y(2)*y(2);
elseif (irevcm == 4)
%   equivalent to fcn evaluation in forward communication routines
rwork(lacor1) = -0.04*y(1) + 1.0d4*y(2)*y(3);
rwork(lacor2) = 0.04*y(1) - 1.0d4*y(2)*y(3) - 3.0d7*y(2)*y(2);
rwork(lacor3) = 3.0d7*y(2)*y(2);
elseif (irevcm == 5)
%   equivalent to fcn evaluation in forward communication routines
ydot(1) = -0.04*y(1) + 1.0d4*y(2)*y(3);
ydot(2) = 0.04*y(1) - 1.0d4*y(2)*y(3) - 3.0d7*y(2)*y(2);
ydot(3) = 3.0d7*y(2)*y(2);
elseif (irevcm == 9)
%   equivalent to monitr call in forward communication routines
if (imon == 1)
tc = rwork(19);
hlast = rwork(15);
hnext = rwork(16);
nqu = int64(rwork(10));
while (iout < 6 && tc-hlast < xout && xout <= tc)
[sol, ifail] = ...
nag_ode_ivp_stiff_c1_interp(xout, int64(neq), ysave, rwork(lacor1:lacor1+neq-1), ...
tc, nqu, hlast, hnext);
if (ifail ~= 0)
imon = -2;
else
fprintf(' %8.3f %13.5f %13.5f %13.5f\n', xout, sol(1), sol(2), sol(3));
iout = iout + 1;
xout = double(iout)*2.0;
end
end
end
end
[t, y, ydot, rwork, inform, ysave, wkjac, jacpvt, imon, inln, ires, irevcm, ifail] = ...
nag_ode_ivp_stiff_exp_revcom(t, tout, y, ydot, rwork, rtol, atol, itol, inform, ...
ysave, wkjac, jacpvt, imon, inln, ires, irevcm, itask, itrace);
end
```
```

x           y(1)          y(2)          y(3)
0.000       1.00000       0.00000       0.00000
2.000       0.94161       0.00003       0.05836
6.000       0.87926       0.00002       0.12072
8.000       0.85854       0.00002       0.14144
10.000       0.84135       0.00002       0.15863

```
```function d02xk_example
neq = 3;
t = 0;
tout = 10;
xout = 2;
iout = 2;
y = [1; 0; 0];
ydot = [0; 0; 0];
rwork = zeros(62,1);
rtol = [0.0001];
atol = [1e-07];
itol = int64(1);
inform = zeros(23,1,'int64');
ysave = zeros(3, 6);
wkjac = zeros(12,1);
jacpvt = [int64(0)];
imon = int64(8185424);
inln = int64(8184256);
ires = int64(1);
irevcm = int64(0);
itrace = int64(0);

lacorb=53;
lacor1 = lacorb + 1;
lacor2 = lacorb + 2;
lacor3 = lacorb + 3;
lsavrb = 56;
lsavr1 = lsavrb + 1;
lsavr2 = lsavrb + 2;
lsavr3 = lsavrb + 3;
[const, rwork, ifail] = ...
d02nv(int64(3), int64(6), int64(5), 'Newton', false, zeros(6), ...
0, 1e-10, 10, 0, int64(200), int64(5), 'Average-L2', rwork);
[rwork, ifail] = d02ns(int64(3), int64(3), 'Numerical', int64(12), rwork);

fprintf('\n      x           y(1)          y(2)          y(3)\n');
fprintf(' %8.3f %13.5f %13.5f %13.5f\n', t, y(1), y(2), y(3));

[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);
while (irevcm ~= 0)
if (irevcm == 1  ||  irevcm == 3)
%   equivalent to fcn evaluation in forward communication routines
rwork(lsavr1) = -0.04*y(1) + 1.0d4*y(2)*y(3);
rwork(lsavr2) = 0.04*y(1) - 1.0d4*y(2)*y(3) - 3.0d7*y(2)*y(2);
rwork(lsavr3) = 3.0d7*y(2)*y(2);
elseif (irevcm == 4)
%   equivalent to fcn evaluation in forward communication routines
rwork(lacor1) = -0.04*y(1) + 1.0d4*y(2)*y(3);
rwork(lacor2) = 0.04*y(1) - 1.0d4*y(2)*y(3) - 3.0d7*y(2)*y(2);
rwork(lacor3) = 3.0d7*y(2)*y(2);
elseif (irevcm == 5)
%   equivalent to fcn evaluation in forward communication routines
ydot(1) = -0.04*y(1) + 1.0d4*y(2)*y(3);
ydot(2) = 0.04*y(1) - 1.0d4*y(2)*y(3) - 3.0d7*y(2)*y(2);
ydot(3) = 3.0d7*y(2)*y(2);
elseif (irevcm == 9)
%   equivalent to monitr call in forward communication routines
if (imon == 1)
tc = rwork(19);
hlast = rwork(15);
hnext = rwork(16);
nqu = int64(rwork(10));
while (iout < 6 && tc-hlast < xout && xout <= tc)
[sol, ifail] = ...
d02xk(xout, int64(neq), ysave, rwork(lacor1:lacor1+neq-1), ...
tc, nqu, hlast, hnext);
if (ifail ~= 0)
imon = -2;
else
fprintf(' %8.3f %13.5f %13.5f %13.5f\n', xout, sol(1), sol(2), sol(3));
iout = iout + 1;
xout = double(iout)*2.0;
end
end
end
end
[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);
end
```
```

x           y(1)          y(2)          y(3)
0.000       1.00000       0.00000       0.00000
2.000       0.94161       0.00003       0.05836
6.000       0.87926       0.00002       0.12072
8.000       0.85854       0.00002       0.14144
10.000       0.84135       0.00002       0.15863

```