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_bandjac_setup (d02nt)

## Purpose

nag_ode_ivp_stiff_bandjac_setup (d02nt) is a setup function which you must call prior to an integrator in sub-chapter D02M–N, if banded matrix linear algebra is required.

## Syntax

[rwork, ifail] = d02nt(neq, neqmax, jceval, ml, mu, nwkjac, njcpvt, rwork)
[rwork, ifail] = nag_ode_ivp_stiff_bandjac_setup(neq, neqmax, jceval, ml, mu, nwkjac, njcpvt, rwork)

## Description

nag_ode_ivp_stiff_bandjac_setup (d02nt) defines the linear algebra to be used as banded matrix linear algebra, permits you to specify the method for calculating the Jacobian and checks the validity of certain input values.

## References

See the D02M–N sub-chapter Introduction.

## Parameters

### Compulsory Input Parameters

1:     neq – int64int32nag_int scalar
The number of differential equations.
Constraint: 1neqneqmax$1\le {\mathbf{neq}}\le {\mathbf{neqmax}}$.
2:     neqmax – int64int32nag_int scalar
A bound on the maximum number of differential equations to be solved during the integration.
Constraint: ${\mathbf{neqmax}}\ge {\mathbf{neq}}$.
3:     jceval – string (length ≥ 1)
Specifies the technique to be used to compute the Jacobian as follows:
jceval = 'N'${\mathbf{jceval}}=\text{'N'}$
The Jacobian is to be evaluated numerically by the integrator. If this option is used, then the actual argument corresponding to jac in the call to nag_ode_ivp_stiff_exp_bandjac (d02nc) or nag_ode_ivp_stiff_imp_bandjac (d02nh) must be either nag_ode_ivp_stiff_exp_bandjac_dummy_jac (d02ncz) or nag_ode_ivp_stiff_imp_bandjac_dummy_jac (d02nhz) respectively.
jceval = 'A'${\mathbf{jceval}}=\text{'A'}$
You must supply a (sub)program to evaluate the Jacobian on a call to the integrator.
jceval = 'D'${\mathbf{jceval}}=\text{'D'}$
The default choice is to be made. In this case 'D' is interpreted as 'N'.
Only the first character of the actual parameter jceval is passed to nag_ode_ivp_stiff_bandjac_setup (d02nt); hence it is permissible for the actual argument to be more descriptive, e.g., ‘Numerical’, ‘Analytical’ or ‘Default’, on a call to nag_ode_ivp_stiff_bandjac_setup (d02nt).
Constraint: jceval = 'N'${\mathbf{jceval}}=\text{'N'}$, 'A'$\text{'A'}$ or 'D'$\text{'D'}$.
4:     ml – int64int32nag_int scalar
mL${m}_{L}$, the number of subdiagonals in the band.
Constraint: 0mlneq1$0\le {\mathbf{ml}}\le {\mathbf{neq}}-1$.
5:     mu – int64int32nag_int scalar
mU${m}_{U}$, the number of superdiagonals in the band.
Constraint: 0muneq1$0\le {\mathbf{mu}}\le {\mathbf{neq}}-1$.
6:     nwkjac – int64int32nag_int scalar
The size of the workspace array wkjac, which you are supplying to the integrator, as declared in the (sub)program from which nag_ode_ivp_stiff_bandjac_setup (d02nt) is called.
Constraint: nwkjac(2 × ml + mu + 1) × neqmax${\mathbf{nwkjac}}\ge \left(2×{\mathbf{ml}}+{\mathbf{mu}}+1\right)×{\mathbf{neqmax}}$.
7:     njcpvt – int64int32nag_int scalar
The size of the workspace array jacpvt, which you are supplying to the integrator, as declared in the (sub)program from which nag_ode_ivp_stiff_bandjac_setup (d02nt) is called.
Constraint: ${\mathbf{njcpvt}}\ge {\mathbf{neqmax}}$.
8:     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:     rwork(50 + 4 × neqmax$50+4×{\mathbf{neqmax}}$) – double array
2:     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, jceval ≠ 'N'${\mathbf{jceval}}\ne \text{'N'}$, 'A'$\text{'A'}$ or 'D'$\text{'D'}$, or neq < 1${\mathbf{neq}}<1$, or ml < 0${\mathbf{ml}}<0$ or ml > neq − 1${\mathbf{ml}}>{\mathbf{neq}}-1$, or mu < 0${\mathbf{mu}}<0$ or mu > neq − 1${\mathbf{mu}}>{\mathbf{neq}}-1$, or ${\mathbf{neq}}>{\mathbf{neqmax}}$, or ${\mathbf{njcpvt}}<{\mathbf{neqmax}}$, or nwkjac < (2 × ml + mu + 1) × neqmax${\mathbf{nwkjac}}<\left(2×{\mathbf{ml}}+{\mathbf{mu}}+1\right)×{\mathbf{neqmax}}$.

## Accuracy

Not applicable.

nag_ode_ivp_stiff_bandjac_setup (d02nt) must be called as a setup function before a call to either nag_ode_ivp_stiff_exp_bandjac (d02nc) or nag_ode_ivp_stiff_imp_bandjac (d02nh) and may be called as the linear algebra setup function before a call to either nag_ode_ivp_stiff_exp_revcom (d02nm) or nag_ode_ivp_stiff_imp_revcom (d02nn).

## Example

```function nag_ode_ivp_stiff_bandjac_setup_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', 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, 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 d02nt_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', 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, 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

```