naginterfaces.library.ode.ivp_rkts_setup¶
- naginterfaces.library.ode.ivp_rkts_setup(tstart, tend, yinit, tol, thresh, method, hstart=0.0)[source]¶
ivp_rkts_setup
is a setup function which must be called prior to the first call of either of the integration functionsivp_rkts_range()
,ivp_rkts_onestep()
andivp_rk_step_revcomm()
.For full information please refer to the NAG Library document for d02pq
https://www.nag.com/numeric/nl/nagdoc_28.6/flhtml/d02/d02pqf.html
- Parameters
- tstartfloat
The initial value of the independent variable, .
- tendfloat
The final value of the independent variable, , at which the solution is required. and together determine the direction of integration.
- yinitfloat, array-like, shape
, the initial values of the solution, , for .
- tolfloat
A relative error tolerance. The actual tolerance used is ; that is, the minimum tolerance is set at times machine precision and the maximum tolerance is set at .
- threshfloat, array-like, shape
A vector of thresholds. For the th component, the actual threshold used is , where is the value returned by
machine.real_safe
.- methodint
The Runge–Kutta method to be used.
or
A pair is used.
or
A pair is used.
or
A pair is used.
- hstartfloat, optional
A value for the size of the first step in the integration to be attempted. The absolute value of is used with the direction being determined by and . The actual first step taken by the integrator may be different to if the underlying algorithm determines that is unsuitable. If then the size of the first step is computed automatically.
- Returns
- commdict, communication object
Communication structure.
- Raises
- NagValueError
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, is too close to .
, but this quantity should be at least .
- (errno )
On entry, .
Constraint: , , , , or .
- (errno )
On entry, too much workspace required.
Workspace provided was , workspace required is .
- Notes
ivp_rkts_setup
and its associated functions (ivp_rkts_range()
,ivp_rkts_onestep()
,ivp_rk_step_revcomm()
,ivp_rk_interp_setup()
,ivp_rk_interp_eval()
,ivp_rkts_reset_tend()
,ivp_rkts_interp()
,ivp_rkts_diag()
andivp_rkts_errass()
) solve the initial value problem for a first-order system of ordinary differential equations. The functions, based on Runge–Kutta methods and derived from RKSUITE (see Brankin et al. (1991)), integratewhere is the vector of solution components and is the independent variable.
The integration proceeds by steps from the initial point towards the final point . An approximate solution is computed at each step. For each component , for , the error made in the step, i.e., the local error, is estimated. The step size is chosen automatically so that the integration will proceed efficiently while keeping this local error estimate smaller than a tolerance that you specify by means of arguments and .
ivp_rkts_range()
can be used to solve the ‘usual task’, namely integrating the system of differential equations to obtain answers at points you specify.ivp_rkts_onestep()
is used for more ‘complicated’ tasks where can readily be coded within a function argument and high-order interpolation is not required.ivp_rk_step_revcomm()
is used for the most ‘complicated’ tasks where is best evaluated outside the integrator or where high-order interpolation is required.You should consider carefully how you want the local error to be controlled. Essentially the code uses relative local error control, with being the desired relative accuracy. For reliable computation, the code must work with approximate solutions that have some correct digits, so there is an upper bound on the value used for . It is impossible to compute a numerical solution that is more accurate than the correctly rounded value of the true solution, so you are not allowed to specify too small for the precision you are using. The magnitude of the local error in on any step will not be greater than where is an average magnitude of over the step. If is smaller than the current value of , this is a relative error test and indicates how many significant digits you want in . If is larger than the current value of , this is an absolute error test with tolerance . Relative error control is the recommended mode of operation, but pure relative error control, , is not permitted. See Further Comments for further information about error control.
ivp_rkts_range()
,ivp_rkts_onestep()
andivp_rk_step_revcomm()
control local error rather than the true (global) error, the difference between the numerical and true solution. Control of the local error controls the true error indirectly. Roughly speaking, the code produces a solution that satisfies the differential equation with a discrepancy bounded in magnitude by the error tolerance. What this implies about how close the numerical solution is to the true solution depends on the stability of the problem. Most practical problems are at least moderately stable, and the true error is then comparable to the error tolerance. To judge the accuracy of the numerical solution, you could reduce substantially, e.g., use , and solve the problem again. This will usually result in a rather more accurate solution, and the true error of the first integration can be estimated by comparison. Alternatively, a global error assessment can be computed automatically using the argument . Because indirect control of the true error by controlling the local error is generally satisfactory and because both ways of assessing true errors cost twice, or more, the cost of the integration itself, such assessments are used mostly for spot checks, selecting appropriate tolerances for local error control, and exploratory computations.ivp_rkts_range()
,ivp_rkts_onestep()
andivp_rk_step_revcomm()
each implement three Runge–Kutta formula pairs, and you must select one for the integration. The best choice for depends on the problem. The order of accuracy is , and respectively. As a rule, the smaller is, the larger you should take the order of the . If the components are small enough that you are effectively specifying relative error control, experience suggestsefficient
order and pair
order and pair
order and pair
The overlap in the ranges of tolerances appropriate for a given merely reflects the dependence of efficiency on the problem being solved. Making smaller will normally make the integration more expensive. However, in the range of tolerances appropriate to a , the increase in cost is modest. There are situations for which one , or even this kind of code, is a poor choice. You should not specify a very small value for , when the th solution component might vanish. In particular, you should not do this when . If you do, the code will have to work hard with any value for to compute significant digits, but the lowest order method is a particularly poor choice in this situation. All three methods are inefficient when the problem is ‘stiff’. If it is only mildly stiff, you can solve it with acceptable efficiency with the order and pair, but if it is moderately or very stiff, a code designed specifically for such problems will be much more efficient. The higher the order the more smoothness is required of the solution in order for the method to be efficient.
When assessment of the true (global) error is requested, this error assessment is updated at each step. Its value can be obtained at any time by a call to
ivp_rkts_errass()
. The code monitors the computation of the global error assessment and reports any doubts it has about the reliability of the results. The assessment scheme requires some smoothness of , and it can be deceived if is insufficiently smooth. At very crude tolerances the numerical solution can become so inaccurate that it is impossible to continue assessing the accuracy reliably. At very stringent tolerances the effects of finite precision arithmetic can make it impossible to assess the accuracy reliably. The cost of this is roughly twice the cost of the integration itself with the 5th and 8th order methods, and three times with the 3rd order method.The first step of the integration is critical because it sets the scale of the problem. The integrator will find a starting step size automatically if you set the argument to . Automatic selection of the first step is so effective that you should normally use it. Nevertheless, you might want to specify a trial value for the first step to be certain that the code recognizes the scale on which phenomena occur near the initial point. Also, automatic computation of the first step size involves some cost, so supplying a good value for this step size will result in a less expensive start. If you are confident that you have a good value, provide it via the argument .
- References
Brankin, R W, Gladwell, I and Shampine, L F, 1991, RKSUITE: A suite of Runge–Kutta codes for the initial value problems for ODEs, SoftReport 91-S1, Southern Methodist University