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_blend (d02nw)

## Purpose

nag_ode_ivp_stiff_blend (d02nw) is a setup function which must be called prior to linear algebra setup functions and integrators from the SPRINT suite of functions, if the BLEND formulae are to be used.

## Syntax

[con, rwork, ifail] = d02nw(neqmax, sdysav, maxord, con, tcrit, hmin, hmax, h0, maxstp, mxhnil, norm_p, rwork)
[con, rwork, ifail] = nag_ode_ivp_stiff_blend(neqmax, sdysav, maxord, 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_blend (d02nw), makes the choice of the BLEND integrator and permits you to define options appropriate to this choice. Alternative choices of integrator from this suite are the BDF method and the DASSL implementation of the BDF method which can be chosen by initial calls to nag_ode_ivp_stiff_bdf (d02nv) 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: neqmax1${\mathbf{neqmax}}\ge 1$.
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 (e.g., see nag_ode_ivp_stiff_exp_fulljac (d02nb)).
Constraint: sdysavmaxord + 3${\mathbf{sdysav}}\ge {\mathbf{maxord}}+3$.
3:     maxord – int64int32nag_int scalar
The maximum order to be used for the BLEND method.
Constraint: 0 < maxord11$0<{\mathbf{maxord}}\le 11$.
4:     con(6$6$) – double array
Values to be used to control step size choice during integration. If any con(i) = 0.0${\mathbf{con}}\left(i\right)=0.0$ on entry, it is replaced by its default value described below. In most cases this is the recommended setting.
con(1)${\mathbf{con}}\left(1\right)$, con(2)${\mathbf{con}}\left(2\right)$, and con(3)${\mathbf{con}}\left(3\right)$ are factors used to bound step size changes. If the current step size h$h$ fails, then the modulus of the next step size is bounded by con(1) × |h|${\mathbf{con}}\left(1\right)×|h|$. The default value of con(1)${\mathbf{con}}\left(1\right)$ is 2.0$2.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 h$h$, then the modulus of the step size on the second step is bounded by con(3) × |h|${\mathbf{con}}\left(3\right)×|h|$. At any other stage in the integration, if the current step size is h$h$, then the modulus of the next step size is bounded by con(2) × |h|${\mathbf{con}}\left(2\right)×|h|$. The default values are 10.0$10.0$ for con(2)${\mathbf{con}}\left(2\right)$ and 1000.0$1000.0$ for con(3)${\mathbf{con}}\left(3\right)$.
con(4)${\mathbf{con}}\left(4\right)$, con(5)${\mathbf{con}}\left(5\right)$ and con(6)${\mathbf{con}}\left(6\right)$ 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 BLEND method, decrease the order or increase the order respectively. The larger the value of con(i)${\mathbf{con}}\left(\mathit{i}\right)$, for i = 4,5,6$\mathit{i}=4,5,6$, the less likely the choice of the corresponding order. The default values are: con(4) = 1.2${\mathbf{con}}\left(4\right)=1.2$, con(5) = 1.3${\mathbf{con}}\left(5\right)=1.3$, con(6) = 1.4${\mathbf{con}}\left(6\right)=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<{\mathbf{con}}\left(1\right)\le {\mathbf{con}}\left(2\right)\le {\mathbf{con}}\left(3\right)$;
• con(i)1.0${\mathbf{con}}\left(\mathit{i}\right)\ge 1.0$, for i = 2,3,,6$\mathit{i}=2,3,\dots ,6$.
5:     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.0$0.0$ say, must be specified even if itask subsequently specifies that tcrit will not be used.
6:     hmin – double scalar
The minimum absolute step size to be allowed. Set hmin = 0.0${\mathbf{hmin}}=0.0$ if this option is not required.
7:     hmax – double scalar
The maximum absolute step size to be allowed. Set hmax = 0.0${\mathbf{hmax}}=0.0$ if this option is not required.
8:     h0 – double scalar
The step size to be attempted on the first step. Set h0 = 0.0${\mathbf{h0}}=0.0$ if the initial step size is calculated internally.
9:     maxstp – int64int32nag_int scalar
The maximum number of steps to be attempted during one call to the integrator after which it will return with ${\mathbf{ifail}}={\mathbf{2}}$. Set maxstp = 0${\mathbf{maxstp}}=0$ if no limit is to be imposed.
10:   mxhnil – int64int32nag_int scalar
The maximum number of warnings printed (if itrace0${\mathbf{itrace}}\ge 0$, e.g., see nag_ode_ivp_stiff_exp_fulljac (d02nb)) per problem when t + h = t$t+h=t$ on a step (h = ​ current step size$h=\text{​ current step size}$). If mxhnil0${\mathbf{mxhnil}}\le 0$, a default value of 10$10$ is assumed.
11:   norm_p – string (length ≥ 1)
Indicates the type of norm to be used.
norm = 'M'${\mathbf{norm}}=\text{'M'}$
Maximum norm.
norm = 'A'${\mathbf{norm}}=\text{'A'}$
Averaged L2 norm.
norm = 'D'${\mathbf{norm}}=\text{'D'}$
Is the same as 'A'.
If vnorm$\mathit{vnorm}$ denotes the norm of the vector v$v$ of length n$n$, then for the averaged L2 norm
 vnorm = sqrt(1/n ∑ i = 1n(vi / wi)2), $vnorm=1n∑i=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 wi${w}_{i}$ from rtol and atol, e.g., nag_ode_ivp_stiff_exp_fulljac (d02nb)).
Only the first character of the actual parameter norm_p is passed to nag_ode_ivp_stiff_blend (d02nw); 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_blend (d02nw).
Constraint: norm = 'M'${\mathbf{norm}}=\text{'M'}$, 'A'$\text{'A'}$ or 'D'$\text{'D'}$.
12:   rwork(50 + 4 × neqmax$50+4×{\mathbf{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.

None.

None.

### Output Parameters

1:     con(6$6$) – double array
The values actually used by nag_ode_ivp_stiff_blend (d02nw).
2:     rwork(50 + 4 × neqmax$50+4×{\mathbf{neqmax}}$) – double array
3:     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$
On entry, an illegal input was detected.

Not applicable.

None.

## Example

```function nag_ode_ivp_stiff_blend_example
t = 0;
tout = 5;
y = [1; 0; 0];
rwork = zeros(62, 1);
rtol = [0.0001];
atol = [1e-07; 1e-08; 1e-07];
itol = int64(2);
inform = zeros(23, 1, 'int64');
ysave = zeros(3, 14);
wkjac = zeros(15, 1);
jacpvt = zeros(3, 1, 'int64');
itrace = int64(0);
[const, rwork, ifail] = ...
nag_ode_ivp_stiff_blend(int64(3), int64(14), int64(11), zeros(6), 0, 1e-10, 10, 0, ...
int64(200), int64(5), 'Average-L2', rwork);
[rwork, ifail] = ...
nag_ode_ivp_stiff_bandjac_setup(int64(3), int64(3), 'Analytical', int64(1), int64(2), int64(15), ...
int64(3), rwork);
[tOut, yOut, ydot, rworkOut, informOut, ysaveOut, wkjacOut, jacpvtOut, ifail] = ...
nag_ode_ivp_stiff_exp_bandjac(t, tout, y, rwork, rtol, atol, itol, inform, ...
@fcn, ysave, @jac, wkjac, jacpvt, 'nag_ode_ivp_stiff_exp_fulljac_dummy_monit', ...

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, ml, mu, pIn)
% Evaluate the Jacobian.
p = zeros(ml+mu+1, neq);
hxd = h*d;
p(1,1) = 1.0d0 - hxd*(-0.04d0);
p(2,1) = -hxd*(1.0d4*y(3));
p(3,1) = -hxd*(1.0d4*y(2));
p(1,2) = -hxd*(0.04d0);
p(2,2) = 1.0d0 - hxd*(-1.0d4*y(3)-6.0d7*y(2));
p(3,2) = -hxd*(-1.0d4*y(2));
p(1,3) = -hxd*(6.0d7*y(2));
p(2,3) = 1.0d0 - hxd*(0.0d0);
```
```

tOut =

5

yOut =

0.8915
0.0000
0.1085

ydot =

-0.0124
-0.0000
0.0124

rworkOut =

1.0e+07 *

0
0.0000
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.0000
0.0000
0.0000
0.0000
0.0000
0.0001
0.0000
0.0000
0.0000
0.0000
0
0
0
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0
0.0000
0
0
0
0
0
0.0000
0.0000
0
0.0000
0
0.0011
8.2671
0.0092
0.0000
0.0000
-0.0000
0.0000
-0.0000
-0.0000
0.0000
0.0000
0.0000

informOut =

57
248
12
4
4
246
0
3
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

ysaveOut =

Columns 1 through 9

0.8864   -0.0092    0.0004   -0.0000    0.0000         0         0         0         0
0.0000   -0.0000    0.0000   -0.0000    0.0000         0         0         0         0
0.1136    0.0092   -0.0004    0.0000   -0.0000         0         0         0         0

Columns 10 through 14

0         0    0.0000    0.0000    0.0000
0         0    0.0000    0.0000    0.0000
0         0   -0.0000   -0.0000   -0.0000

wkjacOut =

0.9934
-142.7005
-0.0387
0
0.0027
0.0385
0
0
0.9767
0
0
0
-0.0066
-0.6194
0.0043

jacpvtOut =

1
2
3

ifail =

0

```
```function d02nw_example
t = 0;
tout = 5;
y = [1; 0; 0];
rwork = zeros(62, 1);
rtol = [0.0001];
atol = [1e-07; 1e-08; 1e-07];
itol = int64(2);
inform = zeros(23, 1, 'int64');
ysave = zeros(3, 14);
wkjac = zeros(15, 1);
jacpvt = zeros(3, 1, 'int64');
itrace = int64(0);
[const, rwork, ifail] = ...
d02nw(int64(3), int64(14), int64(11), zeros(6), 0, 1e-10, 10, 0, ...
int64(200), int64(5), 'Average-L2', rwork);
[rwork, ifail] = ...
d02nt(int64(3), int64(3), 'Analytical', int64(1), int64(2), int64(15), ...
int64(3), rwork);
[tOut, yOut, ydot, rworkOut, informOut, ysaveOut, wkjacOut, jacpvtOut, ifail] = ...
d02nc(t, tout, y, rwork, rtol, atol, itol, inform, ...
@fcn, ysave, @jac, wkjac, jacpvt, 'd02nby', ...

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, ml, mu, pIn)
% Evaluate the Jacobian.
p = zeros(ml+mu+1, neq);
hxd = h*d;
p(1,1) = 1.0d0 - hxd*(-0.04d0);
p(2,1) = -hxd*(1.0d4*y(3));
p(3,1) = -hxd*(1.0d4*y(2));
p(1,2) = -hxd*(0.04d0);
p(2,2) = 1.0d0 - hxd*(-1.0d4*y(3)-6.0d7*y(2));
p(3,2) = -hxd*(-1.0d4*y(2));
p(1,3) = -hxd*(6.0d7*y(2));
p(2,3) = 1.0d0 - hxd*(0.0d0);
```
```

tOut =

5

yOut =

0.8915
0.0000
0.1085

ydot =

-0.0124
-0.0000
0.0124

rworkOut =

1.0e+07 *

0
0.0000
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.0000
0.0000
0.0000
0.0000
0.0000
0.0001
0.0000
0.0000
0.0000
0.0000
0
0
0
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0
0.0000
0
0
0
0
0
0.0000
0.0000
0
0.0000
0
0.0011
8.2671
0.0092
0.0000
0.0000
-0.0000
0.0000
-0.0000
-0.0000
0.0000
0.0000
0.0000

informOut =

57
248
12
4
4
246
0
3
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

ysaveOut =

Columns 1 through 9

0.8864   -0.0092    0.0004   -0.0000    0.0000         0         0         0         0
0.0000   -0.0000    0.0000   -0.0000    0.0000         0         0         0         0
0.1136    0.0092   -0.0004    0.0000   -0.0000         0         0         0         0

Columns 10 through 14

0         0    0.0000    0.0000    0.0000
0         0    0.0000    0.0000    0.0000
0         0   -0.0000   -0.0000   -0.0000

wkjacOut =

0.9934
-142.7005
-0.0387
0
0.0027
0.0385
0
0
0.9767
0
0
0
-0.0066
-0.6194
0.0043

jacpvtOut =

1
2
3

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