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_adams_setup (d02qw)

 Contents

    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example

Purpose

nag_ode_ivp_adams_setup (d02qw) is a setup function which must be called prior to the first call of either of the integrators nag_ode_ivp_adams_roots (d02qf) and nag_ode_ivp_adams_roots_revcom (d02qg) and may be called prior to any continuation call to these functions.

Syntax

[statef, alterg, rwork, iwork, ifail] = d02qw(statef, neqf, vectol, atol, rtol, onestp, crit, tcrit, hmax, maxstp, neqg, alterg, sophst, rwork, iwork, 'latol', latol, 'lrtol', lrtol)
[statef, alterg, rwork, iwork, ifail] = nag_ode_ivp_adams_setup(statef, neqf, vectol, atol, rtol, onestp, crit, tcrit, hmax, maxstp, neqg, alterg, sophst, rwork, iwork, 'latol', latol, 'lrtol', lrtol)
Note: the interface to this routine has changed since earlier releases of the toolbox:
At Mark 22: lrwork and liwork were removed from the interface

Description

nag_ode_ivp_adams_setup (d02qw) permits initialization of the integration method and setting of optional inputs prior to any call of nag_ode_ivp_adams_roots (d02qf) or nag_ode_ivp_adams_roots_revcom (d02qg). It must be called before the first call of either of the functions nag_ode_ivp_adams_roots (d02qf) or nag_ode_ivp_adams_roots_revcom (d02qg) and it may be called before any continuation call of either of the functions nag_ode_ivp_adams_roots (d02qf) or nag_ode_ivp_adams_roots_revcom (d02qg).

References

None.

Parameters

Compulsory Input Parameters

1:     statef – string (length ≥ 1)
Specifies whether the integration function (nag_ode_ivp_adams_roots (d02qf) or nag_ode_ivp_adams_roots_revcom (d02qg)) is to start a new system of ordinary differential equations, restart a system or continue with a system.
statef='S'
Start integration with a new differential system.
statef='R'
Restart integration with the current differential system.
statef='C'
Continue integration with the current differential system.
Constraint: statef='S', 'R' or 'C'.
2:     neqf int64int32nag_int scalar
The number of ordinary differential equations to be solved by the integration function. neqf must remain unchanged on subsequent calls to nag_ode_ivp_adams_setup (d02qw) with statef='C' or 'R'.
Constraint: neqf1.
3:     vectol – logical scalar
Specifies whether vector or scalar error control is to be employed for the local error test in the integration.
If vectol=true, then vector error control will be used and you must specify values of rtoli and atoli, for i=1,2,,neqf.
Otherwise scalar error control will be used and you must specify values of just rtol1 and atol1.
The error test to be satisfied is of the form
i=1neqf eiwi 21.0.  
where wi is defined as follows:
vectol wi
true rtoli×yi+atoli
false rtol1×yi+atol1
and ei is an estimate of the local error in yi, computed internally. vectol must remain unchanged on subsequent calls to nag_ode_ivp_adams_setup (d02qw) with statef='C' or 'R'.
4:     atollatol – double array
The absolute local error tolerance (see vectol).
Constraint: atoli0.0.
5:     rtollrtol – double array
The relative local error tolerance (see vectol).
Constraints:
  • rtoli0.0;
  • if atoli=0.0, rtoli4.0×machine precision.
6:     onestp – logical scalar
The mode of operation of the integration function. If onestp=true, the integration function will operate in one-step mode, that is it will return after each successful step. Otherwise the integration function will operate in interval mode, that is it will return at the end of the integration interval.
7:     crit – logical scalar
Specifies whether or not there is a value for the independent variable beyond which integration is not to be attempted. Setting crit=true indicates that there is such a point, whereas crit=false indicates that there is no such restriction.
8:     tcrit – double scalar
With crit=true, tcrit must be set to a value of the independent variable beyond which integration is not to be attempted. Otherwise tcrit is not referenced.
9:     hmax – double scalar
If hmax0.0, a bound on the absolute step size during the integration is taken to be hmax.
If hmax=0.0, no bound is assumed on the step size during the integration.
A bound may be required if there are features of the solution on very short ranges of integration which may be missed. You should try hmax=0.0 first.
Note:  this argument only affects the step size if the option crit=true is being used.
10:   maxstp int64int32nag_int scalar
A bound on the number of attempted steps in any one call to the integration function. If maxstp0 on entry, a value of 1000 is used.
11:   neqg int64int32nag_int scalar
Specifies whether or not root-finding is required in nag_ode_ivp_adams_roots (d02qf) or nag_ode_ivp_adams_roots_revcom (d02qg).
neqg0
No root-finding is attempted.
neqg>0
Root-finding is required and neqg event functions will be specified for the integration function.
12:   alterg – logical scalar
Specifies whether or not the event functions have been redefined. alterg need not be set if statef='S'. On subsequent calls to nag_ode_ivp_adams_setup (d02qw), if neqg has been set positive, then alterg=false specifies that the event functions remain unchanged, whereas alterg=true specifies that the event functions have changed. Because of the expense in reinitializing the root searching procedure, alterg should be set to true only if the event functions really have been altered. alterg need not be set if the root-finding option is not used.
13:   sophst – logical scalar
The type of search technique to be used in the root-finding. If sophst=true then a sophisticated and reliable but expensive technique will be used, whereas for sophst=false a simple but less reliable technique will be used. If neqg0, sophst is not referenced.
14:   rworklrwork – double array
lrwork, the dimension of the array, must satisfy the constraint lrwork21×1+neqf+2×j+k×neqg+2, where
j= neqf if ​vectol=true 1 if ​vectol=false  
and
k= 14 if ​ sophst=true 5 if ​ sophst=false  
.
This must be the same argument rwork supplied to the integration function. It is used to pass information to the integration function and therefore the contents of this array must not be changed before calling the integration function.
15:   iworkliwork int64int32nag_int array
liwork, the dimension of the array, must satisfy the constraint
  • if sophst=true, liwork21+4×neqg;
  • if sophst=false, liwork21+neqg.
This must be the same argument iwork supplied to the integration function. It is used to pass information to the integration function and therefore the contents of this array must not be changed before calling the integration function.

Optional Input Parameters

1:     latol int64int32nag_int scalar
Default: the dimension of the array atol.
The dimension of the array atol.
Constraints:
  • if vectol=true, latolneqf;
  • if vectol=false, latol1.
2:     lrtol int64int32nag_int scalar
Default: the dimension of the array rtol.
The dimension of the array rtol.
Constraints:
  • if vectol=true, lrtolneqf;
  • if vectol=false, lrtol1.

Output Parameters

1:     statef – string (length ≥ 1)
Is set to 'C', except that if an error is detected, statef is unchanged.
2:     alterg – logical scalar
Is set to false.
3:     rworklrwork – double array
4:     iworkliwork int64int32nag_int array
5:     ifail int64int32nag_int scalar
ifail=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
Illegal input detected.
   ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
   ifail=-399
Your licence key may have expired or may not have been installed correctly.
   ifail=-999
Dynamic memory allocation failed.

Accuracy

Not applicable.

Further Comments

Prior to a continuation call of the integration function, you may reset any of the optional parameters by calling nag_ode_ivp_adams_setup (d02qw) with statef='C'. You may reset:
hmax to alter the maximum step size selection;
rtol, atol to change the error requirements;
maxstp to increase or decrease the number of attempted steps before an error exit is returned;
onestp to change the operation mode of the integration function;
crit, tcrit to alter the point beyond which integration must not be attempted; and
neqg, alterg, sophst to alter the number and type of event functions, and also the search method.
If the behaviour of the system of differential equations has altered and you wish to restart the integration method from the value of t output from the integration function (see nag_ode_ivp_adams_roots (d02qf) and nag_ode_ivp_adams_roots_revcom (d02qg)), then statef should be set to statef='R' and any of the optional parameters may be reset also. If you want to redefine the system of differential equations or start a new integration problem, then statef should be set to statef='S'. Resetting statef='R' or 'S' on normal continuation calls causes a restart in the integration process, which is very inefficient when not needed.

Example

See Example in nag_ode_ivp_adams_roots (d02qf) and nag_ode_ivp_adams_roots_revcom (d02qg).
function d02qw_example


fprintf('d02qw example results\n\n');

% Initialize parameters for Adams method setup
neqf   = int64(2);
neqg   = int64(2);
vectol = true;
atol   = [1e-06;  1e-06];
rtol   = [0.0001; 0.0001];
onestp = false;
crit   = true;
tcrit  = 10;
hmax   = 0;
maxstp = int64(0);
lrwork = 23*(1+neqf) + 14*neqg;
alterg = false;
sophst = true;

lrwork = 23*(1+neqf) + 14*neqg;
rwork  = zeros(lrwork,1);
liwork = 21 + 4*neqg;
iwork  = zeros(liwork, 1, 'int64');

% Adams method setup
[statefOut, altergOut, rwork, iwork, ifail] = ...
  d02qw('Start', neqf, vectol, atol, rtol, onestp, crit, tcrit, hmax, ...
        maxstp, neqg, alterg, sophst, rwork, iwork);

% Adams method integration
t      = 0;
y      = [0; 1];
tout   = 10;
[t, y, root, rwork, iwork, ifail] = ...
  d02qf(@fcn, t, y, tout, @g, neqg, rwork, iwork);

% Display results.
fprintf('Solution and root functions at t = %7.4f is:\n',t);
fprintf('\n y :');
fprintf('%10.4f',y);
yp = fcn(neqf,t,y);
fprintf('\n y'':');
fprintf('%10.4f',yp);
fprintf('\n g :');
for i=1:neqg
  root = g(neqf,t,y,yp,i);
  fprintf('%10.4f',root);
end
fprintf('\n');



function f = fcn(neqf, x, y)
  f=zeros(neqf,1);
  f(1)=y(2);
  f(2)=-y(1);

function result = g(neqf, x, y, yp, k)
  if (k == 1)
    result = yp(1)+0.5;
  else
    result = y(1)-sqrt(0.5);
  end
d02qw example results

Solution and root functions at t =  0.7854 is:

 y :    0.7071    0.7071
 y':    0.7071   -0.7071
 g :    1.2071    0.0000

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–2015