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_2nd_rkn_setup (d02lx)

Purpose

nag_ode_ivp_2nd_rkn_setup (d02lx) is a setup function which must be called prior to the first call of the integrator nag_ode_ivp_2nd_rkn (d02la) and may be called prior to any continuation call to nag_ode_ivp_2nd_rkn (d02la).

Syntax

[start, rwork, ifail] = d02lx(h, tol, thres, thresp, maxstp, start, onestp, high, rwork, 'neq', neq)
[start, rwork, ifail] = nag_ode_ivp_2nd_rkn_setup(h, tol, thres, thresp, maxstp, start, onestp, high, rwork, 'neq', neq)
Note: the interface to this routine has changed since earlier releases of the toolbox:
Mark 22: lrwork has been removed from the interface
.

Description

nag_ode_ivp_2nd_rkn_setup (d02lx) permits you to set optional inputs prior to any call of nag_ode_ivp_2nd_rkn (d02la). It must be called before the first call of function nag_ode_ivp_2nd_rkn (d02la) and it may be called before any continuation call of function nag_ode_ivp_2nd_rkn (d02la).

References

None.

Parameters

Compulsory Input Parameters

1:     h – double scalar
If start = truestart=true, h may specify an initial step size to be attempted in nag_ode_ivp_2nd_rkn (d02la).
If start = falsestart=false, h may specify a step size to override the choice of next step attempted made internally to nag_ode_ivp_2nd_rkn (d02la).
The sign of h is not important, as the absolute value of h is chosen and the appropriate sign is selected by nag_ode_ivp_2nd_rkn (d02la).
If this option is not required then you must set h = 0.0h=0.0.
2:     tol – double scalar
Must be set to a relative tolerance for controlling the error in the integration by nag_ode_ivp_2nd_rkn (d02la). nag_ode_ivp_2nd_rkn (d02la) has been designed so that, for most problems, a reduction in tol leads to an approximately proportional reduction in the error in the solution. However the actual relation between tol and the accuracy of the solution cannot be guaranteed. You are strongly recommended to repeat the integration with a smaller value of tol and compare the results. See the description of thres and thresp for further details of how tol is used.
Constraint: 10 × εtol1.010×εtol1.0 (εε is the machine precision, see nag_machine_precision (x02aj)).
3:     thres(neq) – double array
4:     thresp(neq) – double array
neq, the dimension of the array, must satisfy the constraint neq1neq1.
thres and thresp may be set to thresholds for use in the error control of nag_ode_ivp_2nd_rkn (d02la). At each step in the numerical integration estimates of the local errors E1(i)E1(i) and E2(i)E2(i) in the solution, yiyi, and its derivative, yiyi, respectively are computed, for i = 1,2,,neqi=1,2,,neq. For the step to be accepted conditions of the following type must be satisfied:
max1ineq  ((E1(i))/(max (thres(i),|yi|))) tol,
max1ineq  ((E2(i))/(max (thresp(i),|yi|))) tol.
max1ineq ( E1(i) max(thresi,|yi|) ) tol, max1ineq ( E2(i) max(threspi,|yi|) ) tol.
If one or both of these is not satisfied then the step size is reduced and the solution is recomputed.
If thres(1)0.0thres10.0 on entry, then a value of 50.0 × ε50.0×ε is used for thres(i)thresi, for i = 1,2,,neqi=1,2,,neq, where εε is machine precision. Similarly for thresp.
Constraints:
  • thres(1)0.0thres10.0 or thres(i) > 0.0thresi>0.0, for i = 1,2,,neqi=1,2,,neq;
  • thresp(1)0.0thresp10.0 or thresp(i) > 0.0threspi>0.0, for i = 1,2,,neqi=1,2,,neq.
5:     maxstp – int64int32nag_int scalar
A bound on the number of steps attempted in any one call of nag_ode_ivp_2nd_rkn (d02la).
If maxstp0maxstp0 on entry, a value of 10001000 is used.
6:     start – logical scalar
Specifies whether or not the call of nag_ode_ivp_2nd_rkn (d02la) is for a new problem. start = truestart=true indicates that a new problem is to be solved. start = falsestart=false indicates the call of nag_ode_ivp_2nd_rkn_setup (d02lx) is prior to a continuation call of nag_ode_ivp_2nd_rkn (d02la).
7:     onestp – logical scalar
The mode of operation for nag_ode_ivp_2nd_rkn (d02la).
onestp = trueonestp=true
nag_ode_ivp_2nd_rkn (d02la) will operate in one-step mode, that is it will return after each successful step.
onestp = falseonestp=false
nag_ode_ivp_2nd_rkn (d02la) will operate in interval mode, that is it will return at the end of the integration interval.
8:     high – logical scalar
If high = truehigh=true, a high-order method will be used, whereas if high = falsehigh=false, a low-order method will be used. (See the specification of nag_ode_ivp_2nd_rkn (d02la) for further details.)
9:     rwork(lrwork) – double array
lrwork, the dimension of the array, must satisfy the constraint
  • if high = truehigh=true, lrwork16 + 20 × neqlrwork16+20×neq;
  • if high = falsehigh=false, lrwork16 + 11 × neqlrwork16+11×neq.
This must be the same parameter rwork supplied to nag_ode_ivp_2nd_rkn (d02la). It is used to pass information to nag_ode_ivp_2nd_rkn (d02la) and therefore the contents of this array must not be changed before calling nag_ode_ivp_2nd_rkn (d02la).

Optional Input Parameters

1:     neq – int64int32nag_int scalar
Default: The dimension of the arrays thres, thresp. (An error is raised if these dimensions are not equal.)
The number of second-order ordinary differential equations to be solved by nag_ode_ivp_2nd_rkn (d02la).
Constraint: neq1neq1.

Input Parameters Omitted from the MATLAB Interface

lrwork

Output Parameters

1:     start – logical scalar
start = falsestart=false.
2:     rwork(lrwork) – double array
3:     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
thres(1) > 0.0thres1>0.0 and for some ii thres(i)0.0thresi0.0, 1ineq1ineq, and/or, thresp(1) > 0.0thresp1>0.0 and for some ii thresp(i)0.0threspi0.0, 1ineq1ineq.
  ifail = 2ifail=2
lrwork is too small.
  ifail = 3ifail=3
tol does not satisfy 10 × εtol1.010×εtol1.0 (εε is the machine precision, see nag_machine_precision (x02aj))

Accuracy

Not applicable.

Further Comments

Prior to a continuation call of nag_ode_ivp_2nd_rkn (d02la), you may reset any of the optional parameters by calling nag_ode_ivp_2nd_rkn_setup (d02lx) with start = falsestart=false. You may reset:
h to override the internal step size selection;
tol, thres, thresp to change the error requirements;
maxstp to increase or decrease the number of steps attempted before an error exit is returned;
onestp to change the mode of operation of nag_ode_ivp_2nd_rkn (d02la);
high to change the order of the method being used.

Example

function nag_ode_ivp_2nd_rkn_setup_example
t = 0;
tend = 20;
y = [0.5;
     0];
yp = [0;
     1.732050807568877];
ydp = zeros(2, 1);
rwork = zeros(56,1);
[startOut, rwork, ifail] = ...
    nag_ode_ivp_2nd_rkn_setup(0, 1e-4, zeros(2,1), zeros(2,1), int64(0), true, true, false, rwork);
[tOut, yOut, ypOut, ydpOut, rworkOut, ifail] = ...
    nag_ode_ivp_2nd_rkn(@fcn, t, tend, y, yp, ydp, rwork)

function ydp = fcn(neq, t, y)
% Evaluate second derivatives.
r = sqrt(y(1)^2+y(2)^2)^3;
f = zeros(2,1);
ydp(1) = -y(1)/r;
ydp(2) = -y(2)/r;
 

tOut =

    0.0624


yOut =

    0.4923
    0.1075


ypOut =

   -0.2464
    1.7054


ydpOut =

   -3.8480
   -0.8406


rworkOut =

   1.0e+03 *

    0.0001
    0.0001
    0.0001
    0.0010
         0
    1.0000
         0
    0.0010
         0
         0
    0.0020
    0.0000
    0.0000
         0
    0.0020
    0.0560
    0.0005
         0
         0
    0.0017
   -0.0040
         0
   -0.0002
    0.0017
    0.0000
    0.0000
    0.0000
    0.0000
   -0.0040
   -0.0001
   -0.0040
   -0.0002
   -0.0039
   -0.0006
   -0.0039
   -0.0008
   -0.0038
   -0.0008
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0


ifail =

                    0


function d02lx_example
t = 0;
tend = 20;
y = [0.5;
     0];
yp = [0;
     1.732050807568877];
ydp = zeros(2, 1);
rwork = zeros(56,1);
[startOut, rwork, ifail] = ...
    d02lx(0, 1e-4, zeros(2,1), zeros(2,1), int64(0), true, true, false, rwork);
[tOut, yOut, ypOut, ydpOut, rworkOut, ifail] = ...
    d02la(@fcn, t, tend, y, yp, ydp, rwork)

function ydp = fcn(neq, t, y)
% Evaluate second derivatives.
r = sqrt(y(1)^2+y(2)^2)^3;
f = zeros(2,1);
ydp(1) = -y(1)/r;
ydp(2) = -y(2)/r;
 

tOut =

    0.0624


yOut =

    0.4923
    0.1075


ypOut =

   -0.2464
    1.7054


ydpOut =

   -3.8480
   -0.8406


rworkOut =

   1.0e+03 *

    0.0001
    0.0001
    0.0001
    0.0010
         0
    1.0000
         0
    0.0010
         0
         0
    0.0020
    0.0000
    0.0000
         0
    0.0020
    0.0560
    0.0005
         0
         0
    0.0017
   -0.0040
         0
   -0.0002
    0.0017
    0.0000
    0.0000
    0.0000
    0.0000
   -0.0040
   -0.0001
   -0.0040
   -0.0002
   -0.0039
   -0.0006
   -0.0039
   -0.0008
   -0.0038
   -0.0008
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         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