hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
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 C1C1 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 mm components of the solution of a system of ordinary differential equations at any point using C1C1 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.

References

None.

Parameters

Compulsory Input Parameters

1:     xsol – double scalar
The point at which the first mm components of the solution are to be evaluated. xsol should not be an extrapolation point, that is xsol should satisfy (xsolx) × hu0.0(xsol-x)×hu0.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 mm components are evaluated.
Constraint: 1mneq1mneq.
3:     ysav(ldysav,sdysav) – double array
ldysav, the first dimension of the array, must satisfy the constraint ldysav1ldysav1.
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 1neqldysav1neqldysav.
The value returned in position (ldysav + 50 + i)(ldysav+50+i), for i = 1,2,,neqi=1,2,,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)acori must contain the value given in position (i,2)(i,2) of the monitr parameter acor, for i = 1,2,,neqi=1,2,,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: nqu1nqu1.
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 + 1sdysavnqu+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: 1neqldysav1neqldysav.

Input Parameters Omitted from the MATLAB Interface

ldysav

Output Parameters

1:     sol(m) – double array
The calculated value of the iith component of the solution at xsol, for i = 1,2,,mi=1,2,,m.
2:     ifail – int64int32nag_int scalar
ifail = 0ifail=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 11 before entry. It is then essential to test the value of ifail on exit for ifail = 1ifail=1 or 22.

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 = 1ifail=1
On entry,m < 1m<1,
orneq < 1neq<1,
orldysav < 1ldysav<1,
orneq > ldysavneq>ldysav,
orm > neqm>neq,
ornqu < 1nqu<1,
orsdysav < nqu + 1sdysav<nqu+1,
orthe BDF integrator was not previously used,
orthe Petzold error test, if applicable, was used.
  ifail = 2ifail=2
On entry, hu = 0.0hu=0.0 or h = 0.0h=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 = 3ifail=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.

Further Comments

nag_ode_ivp_stiff_c1_interp (d02xk) provides a C1C1 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 C0C0 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);
itask = int64(1);
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);
itask = int64(1);
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


PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2013