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_rkts_errass (d02pu)

 Contents

    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example

Purpose

nag_ode_ivp_rkts_errass (d02pu) provides details about global error assessment computed during an integration with either nag_ode_ivp_rkts_range (d02pe) or nag_ode_ivp_rkts_onestep (d02pf).

Syntax

[rmserr, errmax, terrmx, iwsav, rwsav, ifail] = d02pu(n, iwsav, rwsav)
[rmserr, errmax, terrmx, iwsav, rwsav, ifail] = nag_ode_ivp_rkts_errass(n, iwsav, rwsav)

Description

nag_ode_ivp_rkts_errass (d02pu) and its associated functions (nag_ode_ivp_rkts_range (d02pe), nag_ode_ivp_rkts_onestep (d02pf), nag_ode_ivp_rkts_setup (d02pq), nag_ode_ivp_rkts_reset_tend (d02pr), nag_ode_ivp_rkts_interp (d02ps) and nag_ode_ivp_rkts_diag (d02pt)) 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)), integrate
y=ft,y  given  yt0=y0  
where y is the vector of n solution components and t is the independent variable.
After a call to nag_ode_ivp_rkts_range (d02pe) or nag_ode_ivp_rkts_onestep (d02pf), nag_ode_ivp_rkts_errass (d02pu) can be called for information about error assessment, if this assessment was specified in the setup function nag_ode_ivp_rkts_setup (d02pq). A more accurate ‘true’ solution y^ is computed in a secondary integration. The error is measured as specified in nag_ode_ivp_rkts_setup (d02pq) for local error control. At each step in the primary integration, an average magnitude μi of component yi is computed, and the error in the component is
yi-y^i maxμi,threshi .  
It is difficult to estimate reliably the true error at a single point. For this reason the RMS (root-mean-square) average of the estimated global error in each solution component is computed. This average is taken over all steps from the beginning of the integration through to the current integration point. If all has gone well, the average errors reported will be comparable to tol (see nag_ode_ivp_rkts_setup (d02pq)). The maximum error seen in any component in the integration so far and the point where the maximum error first occurred are also reported.

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

Parameters

Compulsory Input Parameters

1:     n int64int32nag_int scalar
n, the number of ordinary differential equations in the system to be solved by the integration function.
Constraint: n1.
2:     iwsav130 int64int32nag_int array
3:     rwsav32×n+350 – double array
These must be the same arrays supplied in a previous call to nag_ode_ivp_rkts_range (d02pe) or nag_ode_ivp_rkts_onestep (d02pf). They must remain unchanged between calls.

Optional Input Parameters

None.

Output Parameters

1:     rmserrn – double array
rmserri approximates the RMS average of the true error of the numerical solution for the ith solution component, for i=1,2,,n. The average is taken over all steps from the beginning of the integration to the current integration point.
2:     errmax – double scalar
The maximum weighted approximate true error taken over all solution components and all steps.
3:     terrmx – double scalar
The first value of the independent variable where an approximate true error attains the maximum value, errmax.
4:     iwsav130 int64int32nag_int array
5:     rwsav32×n+350 – double array
Information about the integration for use on subsequent calls to nag_ode_ivp_rkts_range (d02pe) or nag_ode_ivp_rkts_onestep (d02pf) or other associated functions.
6:     ifail int64int32nag_int scalar
ifail=0 unless the function detects an error (see Error Indicators and Warnings).

Error Indicators and Warnings

Errors or warnings detected by the function:
   ifail=1
No error assessment is available since the integrator has not actually taken any successful steps.
No error assessment is available since you did not ask for it in your call to the setup function.
On entry, a previous call to the setup function has not been made or the communication arrays have become corrupted, or a catastrophic error has already been detected elsewhere.
You cannot continue integrating the problem.
On entry, n=_, but the value passed to the setup function was .
You cannot call this function before you have called the integrator.
You have already made one call to this function after the integrator could not achieve specified accuracy.
You cannot call this function again.
   ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
   ifail=-399
Your licence key may have expired or may not have been installed correctly.
   ifail=-999
Dynamic memory allocation failed.

Accuracy

Not applicable.

Further Comments

If the integration has proceeded ‘well’ and the problem is smooth enough, stable and not too difficult then the values returned in the arguments rmserr and errmax should be comparable to the value of tol specified in the prior call to nag_ode_ivp_rkts_setup (d02pq).

Example

This example integrates a two body problem. The equations for the coordinates xt,yt of one body as functions of time t in a suitable frame of reference are
x=-xr3  
y=-yr3,   r=x2+y2.  
The initial conditions
x0=1-ε, x0=0 y0=0, y0= 1+ε 1-ε  
lead to elliptic motion with 0<ε<1. ε=0.7 is selected and the system of ODEs is reposed as
y1=y3 y2=y4 y3=- y1r3 y4=- y2r3  
over the range 0,3π. Relative error control is used with threshold values of 1.0e−10 for each solution component and a high-order Runge–Kutta method (method=3) with tolerance tol=1.0e−6.
Note that for illustration purposes since it is not necessary for this problem, this example integrates to the end of the range regardless of efficiency concerns (i.e., returns from nag_ode_ivp_rkts_range (d02pe) with ifail=2, 3 or 4).
function d02pu_example


fprintf('d02pu example results\n\n');

% Set initial conditions and input
n      = int64(4);
method = int64(3);
tstart = 0;
tend   = 3*pi;
ecc    = 0.7;
yinit  = [1-ecc; 0; 0; sqrt((1+ecc)/(1-ecc))];
hstart = 0;
thresh = [1e-10; 1e-10; 1e-10; 1e-10];
npts   = 96;
ygot   = zeros(n, 1);
ymax   = zeros(n, 1);


% Set control for output
tol    = 1e-6;
tinc   = (tend-tstart)/npts;



% Call setup function
[iwsav, rwsav, ifail] = d02pq( ...
                              tstart, tend, yinit, tol, thresh, method);

fprintf('\nCalculation with TOL = %8.1e\n\n', tol);
fprintf('    t         y1         y2         y3         y4\n');
fprintf(' %6.3f   %8.4f   %8.4f   %8.4f   %8.4f\n', tstart, yinit);

twant = tend;

ifail = int64(3);
while ifail == 2 || ifail == 3 || ifail == 4
  [tgot, ygot, ypgot, ymax, user, iwsav, rwsav, ifail] = ...
    d02pe(@f, twant, ygot, ymax, iwsav, rwsav);
end


% Print Solution
fprintf(' %6.3f   %8.4f   %8.4f   %8.4f   %8.4f\n', tgot, ygot);

% Compute and print error estimates.
[rmserr, errmax, terrmx, iwsav, rwsav, ifail] = d02pu(n, iwsav, rwsav);

fprintf('\nComponentwise error assessment\n');
fprintf('%9.2e ', rmserr);
fprintf('\nMaximum global error, at t = %6.3f, was %9.2e\n', terrmx, errmax);

[fevals, stepcost, waste, stepsok, hnext, iwsav, ifail] = ...
    d02pt(iwsav, rwsav);
fprintf('\nCost of the integration in evaluations of f is %d\n', fevals);



function [yp, user] = f(t, n, y, user)
  r = sqrt(y(1)^2+y(2)^2);
  yp = [y(3); y(4); -y(1)/r^3; -y(2)/r^3];
d02pu example results


Calculation with TOL =  1.0e-06

    t         y1         y2         y3         y4
  0.000     0.3000     0.0000     0.0000     2.3805
  9.425    -1.7000     0.0000    -0.0000    -0.4201

Componentwise error assessment
 3.81e-06  7.10e-06  6.92e-06  2.10e-06 
Maximum global error, at t =  6.302, was  3.43e-05

Cost of the integration in evaluations of f is 1361

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–2015