d02qfc is a function for integrating a non-stiff system of first order ordinary differential equations using a variable-order variable-step Adams' method. A root-finding facility is provided.
The function may be called by the names: d02qfc or nag_ode_ivp_adams_roots.
3Description
Given the initial values the function integrates a non-stiff system of first order ordinary differential equations of the type, , for , from to using a variable-order variable-step Adams' method. The system is defined by fcn, which evaluates in terms of and , and are supplied at . The function is capable of finding roots (values of ) of prescribed event functions of the form
Each is considered to be independent of the others so that roots are sought of each individually. The root reported by the function will be the first root encountered by any . Two techniques for determining the presence of a root in an integration step are available: the sophisticated method described in Watts (1985) and a simplified method whereby sign changes in each are looked for at the ends of each integration step. The event functions are defined by g, which evaluates in terms of and . In one-step mode the function returns an approximation to the solution at each integration point. In interval mode this value is returned at the end of the integration range. If a root is detected this approximation is given at the root. You need to select the mode of operation, the error control, the root-finding technique and various integration inputs with a prior call of the setup function d02qwc.
On entry: contains the current value of the argument , for .
4: – doubleOutput
On exit: must contain the value of , for .
5: – Nag_User *
Pointer to a structure of type Nag_User with the following member:
p – Pointer
On entry/exit: the pointer should be cast to the required type, e.g., struct user *s = (struct user *)comm → p, to obtain the original object's address with appropriate type.
Note:fcn should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by d02qfc. If your code inadvertently does return any NaNs or infinities, d02qfc is likely to produce unexpected results.
3: – double *Input/Output
On entry: after a call to d02qwc with (i.e., an initial entry), t must be set to the initial value of the independent variable .
On exit: the value of at which has been computed. This may be an intermediate output point, a root, tout, or a point at which an error has occurred. If the integration is to be continued, possibly with a new value for tout, t must not be changed.
4: – doubleInput/Output
On entry: the initial values of the solution .
On exit: the computed values of the solution at the exit value of t. If the integration is to be continued, possibly with a new value for tout, these values must not be changed.
5: – doubleInput
On entry: the next value of at which a computed solution is required. For the initial t, the input value of tout is used to determine the direction of integration. Integration is permitted in either direction. If on exit, tout must be reset beyond tin the direction of integration, before any continuation call.
6: – function, supplied by the userExternal Function
g must evaluate a given component of at a specified point.
If root-finding is not required the actual argument for gmust be the NAG defined null double function pointer NULLDFN.
g (Integer neqf,double x,const double y[],const double yp[],Integer k,Nag_User *comm)
1: – IntegerInput
On entry: the number of differential equations.
2: – doubleInput
On entry: the current value of the independent variable.
3: – const doubleInput
On entry: the current values of the dependent variables.
4: – const doubleInput
On entry: the current values of the derivatives of the dependent variables.
5: – IntegerInput
On entry: the component of which must be evaluated.
6: – Nag_User *
Pointer to a structure of type Nag_User with the following member:
p – Pointer
On entry/exit: the pointer should be cast to the required type, e.g., struct user *s = (struct user *)comm → p, to obtain the original object's address with appropriate type.
Note:g should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by d02qfc. If your code inadvertently does return any NaNs or infinities, d02qfc is likely to produce unexpected results.
7: – Nag_User *
Pointer to a structure of type Nag_User with the following member:
p – Pointer
On entry/exit: the pointer , of type Pointer, allows you to communicate information to and from fcn and g. An object of the required type should be declared, e.g., a structure, and its address assigned to the pointer by means of a cast to Pointer in the calling program. E.g. comm.p = (Pointer)&s.
8: – Nag_ODE_Adams *
Pointer to a structure of type Nag_ODE_Adams as initialized by the setup function d02qwc with the following members:
root – Nag_BooleanOutput
On exit: if root-finding was required ( in a call to the setup function d02qwc ), then specifies whether or not the output value of the argument t is a root of one of the event functions. If , then no root was detected, whereas indicates a root.
If root-finding was not required () then on exit .
If , then , , and are indeterminate.
index – IntegerOutput
On exit: the index of the event equation for which the root has been detected.
type – IntegerOutput
On exit: information about the root detected for the event equation defined by . The possible values of with their interpretations are as follows:
If , a simple root, or lack of distinguishing information available.
If , a root of even multiplicity is believed to have been detected, that is no change in sign of the event function was found.
If , a high order root of odd multiplicity.
If , 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 .
events – Integer *Output
On exit: array pointer containing information about the th event function on a very small interval containing the root, t. 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 , neqg, with their interpretations are as follows:
, the th event function did not have a root;
, the th event function changed sign from positive to negative about a root, in the direction of integration;
, the th event function changed sign from negative to positive about a root, in the direction of integration;
, a root was identified, but no change in sign was observed.
resids – doubleOutput
On exit: array pointer, , neqg, contains value of the th event function computed at the root, t.
yp – doubleOutput
On exit: array pointer to the approximate derivative of the solution component at the output value of t. These values are obtained by the evaluation of except when the output value of the argument t is tout and , in which case they are obtained by interpolation.
tcurr – doubleOutput
On exit: the value of the independent variable which the integrator has actually reached. will always be at least as far as the output value of the argument t in the direction of integration, but may be further.
hlast – doubleOutput
On exit: the last successful step size used in the integration.
hnext – doubleOutput
On exit: the next step size which the integration would attempt.
ord_last – IntegerOutput
On exit: the order of the method last used (successfully) in the integration.
ord_next – IntegerOutput
On exit: the order of the method which the integration would attempt on the next step.
nsuccess – IntegerOutput
On exit: the number of integration steps attempted that have been successful since the start of the current problem.
nfail – IntegerOutput
On exit: the number of integration steps attempted that have failed since the start of the current problem.
tolfac – doubleOutput
On exit: a tolerance scale factor, , returned when d02qfc exits with . If rtol and atol are uniformly scaled up by a factor of and d02qwc is called, the next call to d02qfc is deemed likely to succeed.
9: – NagError *Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).
6Error Indicators and Warnings
NE_DIRECTION_CHANGE
The value of tout, , indicates a change in the integration direction. This is not permitted on a continuation call.
NE_MAX_STEP
The maximum number of steps have been attempted.
If integration is to be continued then the function may be called again and a further max_step steps will be attempted (see d02qwc for details of max_step ).
NE_NEQF
The value of neqf supplied is not the same as that given to the setup function d02qwc. but the value given to d02qwc was .
NE_NO_G_FUN
Root finding has been requested by setting , , but argument g is a null function.
The error tolerances are too stringent. rtol and atol should be scaled up by the factor and the integration function re-entered. (see Section 9).
NE_SETUP_ERROR
The call to setup function d02qwc produced an error.
NE_SINGULAR_POINT
A change in sign of an event function has been detected but the root-finding process appears to have converged to a singular point of t rather than a root.
Integration may be continued by calling the function again.
NE_STIFF_PROBLEM
The problem appears to be stiff.
(See the D02 Chapter Introduction for a discussion of the term ‘stiff’). Although it is inefficient to use this integrator to solve stiff problems, integration may be continued by resetting fail and calling the function again.
NE_T_CHANGED
The value of t has been changed from to . This is not permitted on a continuation call.
but crit was set Nag_TRUE in setup call and integration cannot be attempted beyond .
NE_WEIGHT_ZERO
An error weight has become zero during the integration, see d02qwc document; was set to but is now . Integration successful as far as .
The value of the array index is returned in .
7Accuracy
The accuracy of integration is determined by the arguments vectol, rtol and atol in a prior call to d02qwc. Note that only the local error at each step is controlled by these arguments. The error estimates obtained are not strict bounds but are usually reliable over one step. Over a number of steps the overall error may accumulate in various ways, depending on the properties of the differential equation system. The code is designed so that a reduction in the tolerances should lead to an approximately proportional reduction in the error. You are strongly recommended to call d02qfc with more than one set of tolerances and to compare the results obtained to estimate their accuracy.
The accuracy obtained depends on the type of error test used. If the solution oscillates around zero a relative error test should be avoided, whereas if the solution is exponentially increasing an absolute error test should not be used. If different accuracies are required for different components of the solution then a component-wise error test should be used. For a description of the error test see the specifications of the arguments vectol, atol and rtol in the function document for d02qwc.
The accuracy of any roots located will depend on the accuracy of integration and may also be restricted by the numerical properties of . When evaluating you should try to write the code so that unnecessary cancellation errors will be avoided.
8Parallelism and Performance
d02qfc is not threaded in any implementation.
9Further Comments
If the function fails with , then the combination of atol and rtol may be so small that a solution cannot be obtained, in which case the function should be called again using larger values for rtol and/or atol when calling the setup function d02qwc. If the accuracy requested is really needed then you should consider whether there is a more fundamental difficulty. For example:
(a)in the region of a singularity the solution components will usually be of a large magnitude. The function could be used in one-step mode to monitor the size of the solution with the aim of trapping the solution before the singularity. In any case numerical integration cannot be continued through a singularity, and analytical treatment may be necessary;
(b)for ‘stiff’ equations, where the solution contains rapidly decaying components, the function will require a very small step size to preserve stability. This will usually be exhibited by excessive computing time and sometimes an error exit with , but usually an error exit with or NE_STIFF_PROBLEM. The Adams' methods are not efficient in such cases. A high proportion of failed steps (see argument ) may indicate stiffness but there may be other reasons for this phenomenon.
d02qfc can be used for producing results at short intervals (for example, for graph plotting); you should set and tcrit to the last output point required in a prior call to d02qwc and then set tout appropriately for each output point in turn in the call to d02qfc.
The structure opt will contain pointers which have been allocated memory by calls to d02qwc. This allocated memory is then accessed by d02qfc and, if required, d02qzc. When all calls to these functions have been completed the function d02qyc may be called to free memory allocated to the structure.
10Example
We solve the equation
reposed as
over the range with initial conditions and using vector error control () and computation of the solution at with (). Also, we use d02qfc to locate the positions where or where the first component has a turning point, that is .