Given the initial values D02LAF integrates a non-stiff system of second-order differential equations of the type
from to using a Runge–Kutta–Nystrom formula pair. The system is defined by FCN, which evaluates in terms of and , where are supplied at .
There are two Runge–Kutta–Nystrom formula pairs implemented in this routine. The lower order method is intended if you have moderate accuracy requirements and may be used in conjunction with the interpolation routine D02LZF to produce solutions and derivatives at user-specified points. The higher order method is intended if you have high accuracy requirements.
In one-step mode the routine returns approximations to the solution, derivative and at each integration point. In interval mode these values are returned at the end of the integration range. You select the order of the method, the mode of operation, the error control and various optional inputs by a prior call to D02LXF.
FCN must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which D02LAF is called. Parameters denoted as Input must not be changed by this procedure.
2: NEQ – INTEGERInput
On entry: the number of second-order ordinary differential equations to be solved by D02LAF. It must contain the same value as the parameter NEQ used in a prior call to D02LXF.
3: T – REAL (KIND=nag_wp)Input/Output
On entry: the initial value of the independent variable .
On exit: the value of the independent variable, which is usually TEND, unless an error has occurred or the code is operating in one-step mode. If the integration is to be continued, possibly with a new value for TEND, T must not be changed.
4: TEND – REAL (KIND=nag_wp)Input
On entry: the end point of the range of integration. If on initial entry, integration will proceed in the negative direction. TEND may be reset, in the direction of integration, before any continuation call.
On exit: the computed values of the derivatives at the exit value of T. If the integration is to be continued, possibly with a new value for TEND, these values must not be changed.
7: YDP(NEQ) – REAL (KIND=nag_wp) arrayInput/Output
On entry: must be unchanged from a previous call to D02LAF.
On exit: the computed values of the second derivative at the exit value of T, unless illegal input is detected, in which case the elements of YDP may not have been initialized. If the integration is to be continued, possibly with a new value for TEND, these values must not be changed.
8: RWORK(LRWORK) – REAL (KIND=nag_wp) arrayCommunication Array
This must be the same parameter RWORK as supplied to D02LXF. It is used to pass information from D02LXF to D02LAF, and from D02LAF to both D02LYF and D02LZF. Therefore the contents of this array must not be changed before the call to D02LAF or calling either of the routines D02LYF and D02LZF.
9: LRWORK – INTEGERInput
On entry: the dimension of the array RWORK as declared in the (sub)program from which D02LAF is called.
This must be the same parameter LRWORK as supplied to D02LXF.
10: IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to , . If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value is recommended. If the output of error messages is undesirable, then the value is recommended. Otherwise, because for this routine the values of the output parameters may be useful even if on exit, the recommended value is . When the value is used it is essential to test the value of IFAIL on exit.
On exit: unless the routine detects an error or a warning has been flagged (see Section 6).
6 Error Indicators and Warnings
If on entry or , explanatory error messages are output on the current error message unit (as defined by X04AAF).
Errors or warnings detected by the routine:
Illegal input detected, i.e., one of the following conditions:
on any call, , or the value of NEQ or LRWORK has been altered;
on a continuation call, the direction of integration has been changed;
D02LXF had not been called previously, or the previous call to D02LXF resulted in an error exit.
This error exit can be caused if elements of RWORK have been overwritten.
The maximum number of steps has been attempted. (See parameter MAXSTP in D02LXF.) If integration is to be continued then you need only reset IFAIL and call the routine again and a further MAXSTP steps will be attempted.
In order to satisfy the error requirements, the step size needed is too small for the machine precision being used.
The code has detected two successive error exits at the current value of and cannot proceed. Check all input variables.
The code has detected inefficient use of the integration method. The step size has been reduced by a significant amount too often in order to hit the output points specified by TEND. (Of the last or more successful steps more than are steps with sizes that have had to be reduced by a factor of greater than a half.)
The accuracy of integration is determined by the parameters TOL, THRES and THRESP in a prior call to D02LXF. Note that only the local error at each step is controlled by these parameters. 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 system. The code is designed so that a reduction in TOL should lead to an approximately proportional reduction in the error. You are strongly recommended to call D02LAF with more than one value for TOL 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. For a description of the error test see the specifications of the parameters TOL, THRES and THRESP in routine document D02LXF.
8 Further Comments
If D02LAF fails with then the value of TOL may be so small that a solution cannot be obtained, in which case the routine should be called again with a larger value for TOL. If the accuracy requested is really needed then you should consider whether there is a more fundamental difficulty. For example:
in the region of a singularity the solution components will usually be of a large magnitude. D02LAF 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;
if the solution contains fast oscillatory components, the routine 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 . The Runge–Kutta–Nystrom methods are not efficient in such cases and you should consider reposing your problem as a system of first-order ordinary differential equations and then using a routine from sub-chapter D02M–N with the Blend formulae (see D02MVF).
D02LAF can be used for producing results at short intervals (for example, for tabulation), in two ways. By far the less efficient is to call D02LAF successively over short intervals, to , although this is the only way if the higher order method has been selected and precisely not what it is intended for. A more efficient way, only for use when the lower order method has been selected, is to use D02LAF in one-step mode. The output values of parameters Y, YP, YDP, T and RWORK are set correctly for a call to D02LZF to compute the solution and derivative at the required points.
This example solves the following system (the two body problem)
over the range with initial conditions , , and where , the eccentricity, is . The system is solved using the lower order method with relative local error tolerances and and default threshold tolerances. D02LAF is used in one-step mode () and D02LZF provides solution values at intervals of .