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_bdf (d02nv)

Purpose

nag_ode_ivp_stiff_bdf (d02nv) is a setup function which must be called prior to linear algebra setup functions and integrators from the SPRINT suite of functions, if Backward Differentiation Formulae (BDF) are to be used.

Syntax

[con, rwork, ifail] = d02nv(neqmax, sdysav, maxord, method, petzld, con, tcrit, hmin, hmax, h0, maxstp, mxhnil, norm_p, rwork)
[con, rwork, ifail] = nag_ode_ivp_stiff_bdf(neqmax, sdysav, maxord, method, petzld, con, tcrit, hmin, hmax, h0, maxstp, mxhnil, norm_p, rwork)

Description

An integrator setup function must be called before the call to any linear algebra setup function or integrator from the SPRINT suite of functions in this sub-chapter. This setup function, nag_ode_ivp_stiff_bdf (d02nv), makes the choice of the BDF integrator and permits you to define options appropriate to this choice. Alternative choices of integrator from this suite are the BLEND method and the DASSL implementation of the BDF method which can be chosen by initial calls to nag_ode_ivp_stiff_blend (d02nw) or nag_ode_ivp_stiff_dassl (d02mv) respectively.

References

See the D02M–N sub-chapter Introduction.

Parameters

Compulsory Input Parameters

1:     neqmax – int64int32nag_int scalar
A bound on the maximum number of differential equations to be solved.
Constraint: neqmax1neqmax1.
2:     sdysav – int64int32nag_int scalar
The second dimension of the array ysav that will be supplied to the integrator, as declared in the (sub)program from which the integrator is called.
Constraint: sdysavmaxord + 1sdysavmaxord+1.
3:     maxord – int64int32nag_int scalar
The maximum order to be used for the BDF method.
Constraint: 0 < maxord50<maxord5.
4:     method – string (length ≥ 1)
Specifies the method to be used to solve the system of nonlinear equations arising on each step of the BDF code.
method = 'N'method='N'
A modified Newton iteration is used.
method = 'F'method='F'
Functional iteration is used.
method = 'D'method='D'
A modified Newton iteration is used.
Note:  a linear algebra setup function must be called even when using functional iteration, since if difficulty is encountered a switch is made to a modified Newton method.
Only the first character of the actual parameter method is passed to nag_ode_ivp_stiff_bdf (d02nv); hence it is permissible for the actual argument to be more descriptive e.g., ‘Newton’, ‘Functional iteration’ or ‘Default’ in a call to nag_ode_ivp_stiff_bdf (d02nv).
Constraint: method = 'N'method='N', 'F''F' or 'D''D'.
5:     petzld – logical scalar
Specifies whether the Petzold local error test is to be used. If petzld is set to true on entry, then the Petzold local error test is used, otherwise a conventional test is used. The Petzold test results in extra overhead cost but is more stable and reliable for differential/algebraic equations.
6:     con(66) – double array
Values to be used to control step size choice during integration. If any con(i) = 0.0coni=0.0 on entry, it is replaced by its default value described below. In most cases this is the recommended setting.
con(1)con1, con(2)con2, and con(3)con3 are factors used to bound step size changes. If the current step size hh fails, then the modulus of the next step size is bounded by con(1) × |h|con1×|h|. The default value of con(1)con1 is 2.02.0. Note that the new step size may be used with a method of different order to the failed step. If the initial step size is hh, then the modulus of the step size on the second step is bounded by con(3) × |h|con3×|h|. At any other stage in the integration, if the current step size is hh, then the modulus of the next step size is bounded by con(2) × |h|con2×|h|. The default values are 10.010.0 for con(2)con2 and 1000.01000.0 for con(3)con3.
con(4)con4, con(5)con5 and con(6)con6 are ‘tuning’ constants used in determining the next order and step size. They are used to scale the error estimates used in determining whether to keep the same order of the BDF method, decrease the order or increase the order respectively. The larger the value of con(i)coni, for i = 4,5,6i=4,5,6, the less likely the choice of the corresponding order. The default values are: con(4) = 1.2con4=1.2, con(5) = 1.3con5=1.3, con(6) = 1.4con6=1.4.
Constraints:
These constraints must be satisfied after any zero values have been replaced by their default values.
  • 0.0 < con(1)con(2)con(3)0.0<con1con2con3;
  • con(i)1.0coni1.0, for i = 2,3,,6i=2,3,,6.
7:     tcrit – double scalar
A point beyond which integration must not be attempted. The use of tcrit is described under the parameter itask in the specification for the integrator (e.g., see nag_ode_ivp_stiff_exp_fulljac (d02nb)). A value, 0.00.0 say, must be specified even if itask subsequently specifies that tcrit will not be used.
8:     hmin – double scalar
The minimum absolute step size to be allowed. Set hmin = 0.0hmin=0.0 if this option is not required.
9:     hmax – double scalar
The maximum absolute step size to be allowed. Set hmax = 0.0hmax=0.0 if this option is not required.
10:   h0 – double scalar
The step size to be attempted on the first step. Set h0 = 0.0h0=0.0 if the initial step size is calculated internally.
11:   maxstp – int64int32nag_int scalar
The maximum number of steps to be attempted during one call to the integrator after which it will return with ifail = 2ifail=2. Set maxstp = 0maxstp=0 if no limit is to be imposed.
12:   mxhnil – int64int32nag_int scalar
The maximum number of warnings printed (if itrace0itrace0) per problem when t + h = tt+h=t on a step (h = h= current step size). If mxhnil0mxhnil0, a default value of 1010 is assumed.
13:   norm_p – string (length ≥ 1)
Indicates the type of norm to be used.
norm = 'M'norm='M'
Maximum norm.
norm = 'A'norm='A'
Averaged L2 norm.
norm = 'D'norm='D'
Is the same as norm = 'A'norm='A'.
If vnormvnorm denotes the norm of the vector vv of length nn, then for the averaged L2 norm
vnorm = sqrt(1/ni = 1n(vi / wi)2),
vnorm=1ni=1n(vi/wi)2,
while for the maximum norm
vnorm = max |vi / wi|.
i
vnorm=maxi|vi/wi|.
If you wish to weight the maximum norm or the L2 norm, then rtol and atol should be scaled appropriately on input to the integrator (see under itol in the specification of the integrator for the formulation of the weight vector wiwi from rtol and atol, e.g., see nag_ode_ivp_stiff_exp_fulljac (d02nb)).
Only the first character to the actual parameter norm_p is passed to nag_ode_ivp_stiff_bdf (d02nv); hence it is permissible for the actual argument to be more descriptive e.g., ‘Maximum’, ‘Average L2’ or ‘Default’ in a call to nag_ode_ivp_stiff_bdf (d02nv).
Constraint: norm = 'M'norm='M', 'A''A' or 'D''D'.
14:   rwork(50 + 4 × neqmax50+4×neqmax) – double array
This must be the same workspace array as the array rwork supplied to the integrator. It is used to pass information from the setup function to the integrator and therefore the contents of this array must not be changed before calling the integrator.

Optional Input Parameters

None.

Input Parameters Omitted from the MATLAB Interface

None.

Output Parameters

1:     con(66) – double array
The values actually used by nag_ode_ivp_stiff_bdf (d02nv).
2:     rwork(50 + 4 × neqmax50+4×neqmax) – double array
3:     ifail – int64int32nag_int scalar
ifail = 0ifail=0 unless the function detects an error (see [Error Indicators and Warnings]).

Error Indicators and Warnings

Errors or warnings detected by the function:
  ifail = 1ifail=1
On entry, an illegal input was detected.

Accuracy

Not applicable.

Further Comments

None.

Example

function nag_ode_ivp_stiff_bdf_example
t = 0;
tout = 10;
y = [1; 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);
itask = int64(4);
itrace = int64(0);
[const, rwork, ifail] = ...
    nag_ode_ivp_stiff_bdf(int64(3), int64(6), int64(5), 'Newton', false, zeros(6), ...
    10, 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);
[tOut, yOut, ydot, rworkOut, informOut, ysaveOut, wkjacOut, ifail] = ...
    nag_ode_ivp_stiff_exp_fulljac(t, tout, y, rwork, rtol, atol, itol, inform, @fcn, ...
    ysave, @jac, wkjac, 'nag_ode_ivp_stiff_exp_fulljac_dummy_monit', itask, itrace)

function [f, ires] = fcn(neq, t, y, ires)
% Evaluate derivative vector.
f = zeros(3,1);
f(1) = -0.04d0*y(1) + 1.0d4*y(2)*y(3);
f(2) = 0.04d0*y(1) - 1.0d4*y(2)*y(3) - 3.0d7*y(2)*y(2);
f(3) = 3.0d7*y(2)*y(2);
function p = jac(neq, t, y, h, d, p)
% Evaluate the Jacobian.
p = zeros(neq, neq);
hxd = h*d;
p(1,1) = 1.0d0 - hxd*(-0.04d0);
p(1,2) = -hxd*(1.0d4*y(3));
p(1,3) = -hxd*(1.0d4*y(2));
p(2,1) = -hxd*(0.04d0);
p(2,2) = 1.0d0 - hxd*(-1.0d4*y(3)-6.0d7*y(2));
p(2,3) = -hxd*(-1.0d4*y(2));
p(3,2) = -hxd*(6.0d7*y(2));
p(3,3) = 1.0d0 - hxd*(0.0d0);
 

tOut =

    10


yOut =

    0.8414
    0.0000
    0.1586


ydot =

   -0.0079
   -0.0000
    0.0079


rworkOut =

   1.0e+06 *

    0.0000
    0.0002
    0.0000
         0
         0
    0.0000
    0.0000
    0.0000
         0
    0.0000
    0.0000
    0.0000
    0.0000
    0.0000
    0.0000
    0.0000
    0.0000
    0.0000
    0.0000
         0
    0.0000
    0.0000
    0.0000
    0.0000
    0.0010
    0.0000
    0.0000
    0.0000
         0
         0
    0.0000
    0.0000
    0.0000
    0.0000
    0.0000
         0
         0
         0
         0
    0.0000
         0
         0
         0
         0
         0
    0.0000
    0.0000
         0
    0.0000
         0
    0.0118
    9.8370
    0.0643
   -0.0000
    0.0000
    0.0000
    0.0000
   -0.0000
   -0.0000
    0.0000
    0.0000
    0.0000


informOut =

                   55
                  132
                   17
                    3
                    3
                   79
                    0
                    3
                    0
                    0
                    0
                    0
                    0
                    0
                    0
                    0
                    0
                    0
                    0
                    0
                    0
                    0
                    0


ysaveOut =

    0.8414   -0.0041    0.0001   -0.0000    0.0000   -0.0000
    0.0000   -0.0000    0.0000   -0.0000    0.0000   -0.0000
    0.1586    0.0041   -0.0001    0.0000   -0.0000    0.0000


wkjacOut =

    1.0100
         0
   -0.0100
 -380.6996
 -247.4940
  629.1936
   -0.0408
   -0.0040
    2.5831
    1.0000
    3.0000
    3.0000


ifail =

                    0


function d02nv_example
t = 0;
tout = 10;
y = [1; 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);
itask = int64(4);
itrace = int64(0);
[const, rwork, ifail] = ...
    d02nv(int64(3), int64(6), int64(5), 'Newton', false, zeros(6), ...
    10, 1e-10, 10, 0, int64(200), int64(5), 'Average-L2', rwork);
[rwork, ifail] = ...
    d02ns(int64(3), int64(3), 'Numerical', int64(12), rwork);
[tOut, yOut, ydot, rworkOut, informOut, ysaveOut, wkjacOut, ifail] = ...
    d02nb(t, tout, y, rwork, rtol, atol, itol, inform, @fcn, ...
    ysave, @jac, wkjac, 'd02nby', itask, itrace)

function [f, ires] = fcn(neq, t, y, ires)
% Evaluate derivative vector.
f = zeros(3,1);
f(1) = -0.04d0*y(1) + 1.0d4*y(2)*y(3);
f(2) = 0.04d0*y(1) - 1.0d4*y(2)*y(3) - 3.0d7*y(2)*y(2);
f(3) = 3.0d7*y(2)*y(2);
function p = jac(neq, t, y, h, d, p)
% Evaluate the Jacobian.
p = zeros(neq, neq);
hxd = h*d;
p(1,1) = 1.0d0 - hxd*(-0.04d0);
p(1,2) = -hxd*(1.0d4*y(3));
p(1,3) = -hxd*(1.0d4*y(2));
p(2,1) = -hxd*(0.04d0);
p(2,2) = 1.0d0 - hxd*(-1.0d4*y(3)-6.0d7*y(2));
p(2,3) = -hxd*(-1.0d4*y(2));
p(3,2) = -hxd*(6.0d7*y(2));
p(3,3) = 1.0d0 - hxd*(0.0d0);
 

tOut =

    10


yOut =

    0.8414
    0.0000
    0.1586


ydot =

   -0.0079
   -0.0000
    0.0079


rworkOut =

   1.0e+06 *

    0.0000
    0.0002
    0.0000
         0
         0
    0.0000
    0.0000
    0.0000
         0
    0.0000
    0.0000
    0.0000
    0.0000
    0.0000
    0.0000
    0.0000
    0.0000
    0.0000
    0.0000
         0
    0.0000
    0.0000
    0.0000
    0.0000
    0.0010
    0.0000
    0.0000
    0.0000
         0
         0
    0.0000
    0.0000
    0.0000
    0.0000
    0.0000
         0
         0
         0
         0
    0.0000
         0
         0
         0
         0
         0
    0.0000
    0.0000
         0
    0.0000
         0
    0.0118
    9.8370
    0.0643
   -0.0000
    0.0000
    0.0000
    0.0000
   -0.0000
   -0.0000
    0.0000
    0.0000
    0.0000


informOut =

                   55
                  132
                   17
                    3
                    3
                   79
                    0
                    3
                    0
                    0
                    0
                    0
                    0
                    0
                    0
                    0
                    0
                    0
                    0
                    0
                    0
                    0
                    0


ysaveOut =

    0.8414   -0.0041    0.0001   -0.0000    0.0000   -0.0000
    0.0000   -0.0000    0.0000   -0.0000    0.0000   -0.0000
    0.1586    0.0041   -0.0001    0.0000   -0.0000    0.0000


wkjacOut =

    1.0100
         0
   -0.0100
 -380.6996
 -247.4940
  629.1936
   -0.0408
   -0.0040
    2.5831
    1.0000
    3.0000
    3.0000


ifail =

                    0



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