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_rootdiag (d02qy)

Purpose

nag_ode_ivp_adams_rootdiag (d02qy) is a diagnostic function which may be called after a call to the integrator functions nag_ode_ivp_adams_roots (d02qf) or nag_ode_ivp_adams_roots_revcom (d02qg).

Syntax

[index, itype, events, resids, ifail] = d02qy(neqg, rwork, iwork)
[index, itype, events, resids, ifail] = nag_ode_ivp_adams_rootdiag(neqg, rwork, iwork)
Note: the interface to this routine has changed since earlier releases of the toolbox:
Mark 22: lrwork, liwork have been removed from the interface
.

Description

nag_ode_ivp_adams_rootdiag (d02qy) should be called only after a call to nag_ode_ivp_adams_roots (d02qf) or nag_ode_ivp_adams_roots_revcom (d02qg) results in the output value root = trueroot=true, indicating that a root has been detected. nag_ode_ivp_adams_rootdiag (d02qy) permits you to examine information about the root detected, such as the indices of the event equations for which there is a root, the type of root (odd or even) and the residuals of the event equations.

References

None.

Parameters

Compulsory Input Parameters

1:     neqg – int64int32nag_int scalar
The number of event functions defined for the integration function. It must be the same parameter neqg supplied to the setup function nag_ode_ivp_adams_setup (d02qw) and to the integration function (nag_ode_ivp_adams_roots (d02qf) or nag_ode_ivp_adams_roots_revcom (d02qg)).
2:     rwork(lrwork) – double array
This must be the same parameter rwork as supplied to nag_ode_ivp_adams_roots (d02qf) or nag_ode_ivp_adams_roots_revcom (d02qg). It is used to pass information from the integration function to nag_ode_ivp_adams_rootdiag (d02qy) and therefore the contents of this array must not be changed before calling nag_ode_ivp_adams_rootdiag (d02qy).
3:     iwork(liwork) – int64int32nag_int array
This must be the same parameter iwork as supplied to nag_ode_ivp_adams_roots (d02qf) or nag_ode_ivp_adams_roots_revcom (d02qg). It is used to pass information from the integration function to nag_ode_ivp_adams_rootdiag (d02qy) and therefore the contents of this array must not be changed before calling nag_ode_ivp_adams_rootdiag (d02qy).

Optional Input Parameters

None.

Input Parameters Omitted from the MATLAB Interface

lrwork liwork

Output Parameters

1:     index – int64int32nag_int scalar
The index kk of the event equation gk(x,y,y) = 0gk(x,y,y)=0 for which the root has been detected.
2:     itype – int64int32nag_int scalar
Information about the root detected for the event equation defined by index. The possible values of itype with their interpretations are as follows:
itype = 1itype=1
A simple root, or lack of distinguishing information available.
itype = 2itype=2
A root of even multiplicity is believed to have been detected, that is no change in sign of the event function was found.
itype = 3itype=3
A high-order root of odd multiplicity.
itype = 4itype=4
A possible root, but due to high multiplicity or a clustering of roots accurate evaluation of the event function was prohibited by round-off error and/or cancellation.
In general, the accuracy of the root is less reliable for values of itype > 1itype>1.
3:     events(neqg) – int64int32nag_int array
Information about the kkth event function on a very small interval containing the root, t (see nag_ode_ivp_adams_roots (d02qf) and nag_ode_ivp_adams_roots_revcom (d02qg)), as output from the integration function. All roots lying in this interval are considered indistinguishable numerically and therefore should be regarded as defining a root at t. The possible values of events(k)eventsk with their interpretations are as follows:
events(k) = 0eventsk=0
The kkth event function did not have a root.
events(k) = 1eventsk=-1
The kkth event function changed sign from positive to negative about a root, in the direction of integration.
events(k) = 1eventsk=1
The kkth event function changed sign from negative to positive about a root, in the direction of integration.
events(k) = 2eventsk=2
A root was identified, but no change in sign was observed.
4:     resids(neqg) – double array
The value of the kkth event function computed at the root, t (see nag_ode_ivp_adams_roots (d02qf) and nag_ode_ivp_adams_roots_revcom (d02qg)).
5:     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
An integration function (nag_ode_ivp_adams_roots (d02qf) or nag_ode_ivp_adams_roots_revcom (d02qg)) has not been called, no root was detected or one or more of the parameters lrwork, liwork and neqg does not match the corresponding values supplied to nag_ode_ivp_adams_setup (d02qw). Values for the arguments index, itype, events and resids will not have been set.
This error exit may be caused by overwriting elements of iwork.

Accuracy

Not applicable.

Further Comments

None.

Example

function nag_ode_ivp_adams_rootdiag_example
t = 0;
y = [0; 1];
tout = 10;
rwork = zeros(97,1);
iwork = zeros(29, 1, 'int64');
neqf = int64(2);
neqg = int64(2);

[statefOut, altergOut, rwork, iwork, ifail] = ...
    nag_ode_ivp_adams_setup('S', int64(2), true, [1e-06;1e-06], [0.0001; 0.0001], false, true, ...
    10, 0, int64(0), int64(2), false, true, rwork, iwork);
[t, y, root, rwork, iwork, ifail] = ...
    nag_ode_ivp_adams_roots(@fcn, t, y, tout, @g, neqg, rwork, iwork);
[yp, tcurr, hlast, hnext, odlast, odnext, nsucc, nfail, tolfac, badcmp, ifail] = ...
    nag_ode_ivp_adams_diag(neqf, rwork, iwork);
[index, itype, events, resids, ifail] = nag_ode_ivp_adams_rootdiag(neqg, rwork, iwork)




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);
  else
    result = y(1);
  end
 

index =

                    2


itype =

                    1


events =

                    0
                    2


resids =

     1
     0


ifail =

                    0


function d02qy_example
t = 0;
y = [0; 1];
tout = 10;
rwork = zeros(97,1);
iwork = zeros(29, 1, 'int64');
neqf = int64(2);
neqg = int64(2);

[statefOut, altergOut, rwork, iwork, ifail] = ...
    d02qw('S', int64(2), true, [1e-06;1e-06], [0.0001; 0.0001], false, true, ...
    10, 0, int64(0), int64(2), false, true, rwork, iwork);
[t, y, root, rwork, iwork, ifail] = ...
    d02qf(@fcn, t, y, tout, @g, neqg, rwork, iwork);
[yp, tcurr, hlast, hnext, odlast, odnext, nsucc, nfail, tolfac, badcmp, ifail] = ...
    d02qx(neqf, rwork, iwork);
[index, itype, events, resids, ifail] = d02qy(neqg, rwork, iwork)




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);
  else
    result = y(1);
  end
 

index =

                    2


itype =

                    1


events =

                    0
                    2


resids =

     1
     0


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