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_diag (d02ly)

Purpose

nag_ode_ivp_2nd_rkn_diag (d02ly) is a diagnostic function which may be called after a call of the integrator nag_ode_ivp_2nd_rkn (d02la).

Syntax

[hnext, hused, hstart, nsucc, nfail, natt, thres, thresp, ifail] = d02ly(neq, rwork)
[hnext, hused, hstart, nsucc, nfail, natt, thres, thresp, ifail] = nag_ode_ivp_2nd_rkn_diag(neq, rwork)
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_diag (d02ly) permits you to extract information about the performance of nag_ode_ivp_2nd_rkn (d02la) and the setting of some optional parameters. It may be called only after a call of nag_ode_ivp_2nd_rkn (d02la).

References

None.

Parameters

Compulsory Input Parameters

1:     neq – int64int32nag_int scalar
The number of second-order ordinary differential equations solved by nag_ode_ivp_2nd_rkn (d02la). It must be the same as the parameter neq supplied to nag_ode_ivp_2nd_rkn (d02la) and nag_ode_ivp_2nd_rkn_setup (d02lx).
2:     rwork(lrwork) – double array
This must be the same parameter rwork as supplied to nag_ode_ivp_2nd_rkn (d02la). It is used to pass information from nag_ode_ivp_2nd_rkn (d02la) to nag_ode_ivp_2nd_rkn_diag (d02ly) and therefore the contents of this array must not be changed before calling nag_ode_ivp_2nd_rkn_diag (d02ly).

Optional Input Parameters

None.

Input Parameters Omitted from the MATLAB Interface

lrwork

Output Parameters

1:     hnext – double scalar
The next step size which nag_ode_ivp_2nd_rkn (d02la), if called, would attempt.
2:     hused – double scalar
The last successful step size used by nag_ode_ivp_2nd_rkn (d02la).
3:     hstart – double scalar
The initial step size used on the current integration problem by nag_ode_ivp_2nd_rkn (d02la).
4:     nsucc – int64int32nag_int scalar
The number of steps attempted by nag_ode_ivp_2nd_rkn (d02la) that have been successful since the start of the current problem.
5:     nfail – int64int32nag_int scalar
The number of steps attempted by nag_ode_ivp_2nd_rkn (d02la) that have failed since the start of the current problem.
6:     natt – int64int32nag_int scalar
The number of steps attempted before the initial step was successful. Over a large number of problems the cost of an attempted step of this type is approximately half that of a normal attempted step.
7:     thres(neq) – double array
The iith solution threshold value used in the error control strategy. (See nag_ode_ivp_2nd_rkn_setup (d02lx).)
8:     thresp(neq) – double array
The iith derivative threshold value used in the error control strategy. (See nag_ode_ivp_2nd_rkn_setup (d02lx).)
9:     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
nag_ode_ivp_2nd_rkn (d02la) has not been called, or one or both of the parameters neq and lrwork does not match the corresponding parameter supplied to nag_ode_ivp_2nd_rkn_setup (d02lx).
This error exit can be caused if elements of rwork have been overwritten.

Accuracy

Not applicable.

Further Comments

None.

Example

function nag_ode_ivp_2nd_rkn_diag_example
t = 0;
tend = 20;
y = [0.5;
     0];
yp = [0;
     1.732050807568877];
ydp = zeros(2, 1);
rwork = zeros(56,1);
twant = 2;
tnext = 2;
nwant = int64(2);
[startOut, rwork, ifail] = ...
    nag_ode_ivp_2nd_rkn_setup(0, 1e-4, zeros(2,1), zeros(2,1), int64(0), true, true, false, rwork);
fprintf('\n  T       Y(1)       Y(2)\n');
fprintf('%4.1f %10.5f %10.5f\n', t, y(1), y(2));
while (t < tend && ifail == 0)
  [t, y, yp, ydp, rwork, ifail] = nag_ode_ivp_2nd_rkn(@fcn, t, tend, y, yp, ydp, rwork);
  while (tnext <= t && ifail == 0)
    [ywant, ypwant, ifail] = nag_ode_ivp_2nd_rkn_interp(t, y, yp, nwant, tnext, rwork);
    fprintf('%4.1f %10.5f %10.5f\n', tnext, ywant(1), ywant(2));
    tnext = tnext + 2;
  end
end

if (ifail == 0)
  [hnext, hused, hstart, nsucc, nfail, natt, thres, thresp, ifail] = ...
    nag_ode_ivp_2nd_rkn_diag(nwant, rwork);

  fprintf('\n Number of successful steps = %d\n', nsucc);
  fprintf(' Number of failed steps     = %d\n', nfail);
end



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;
 

  T       Y(1)       Y(2)
 0.0    0.50000    0.00000
 2.0   -1.20573    0.61357
 4.0   -1.33476   -0.47685
 6.0    0.35748   -0.44558
 8.0   -1.03762    0.73022
10.0   -1.42617   -0.32658
12.0    0.05515   -0.72032
14.0   -0.82880    0.81788
16.0   -1.48103   -0.16788
18.0   -0.26719   -0.84223
20.0   -0.57803    0.86339

 Number of successful steps = 108
 Number of failed steps     = 16

function d02ly_example
t = 0;
tend = 20;
y = [0.5;
     0];
yp = [0;
     1.732050807568877];
ydp = zeros(2, 1);
rwork = zeros(56,1);
twant = 2;
tnext = 2;
nwant = int64(2);
[startOut, rwork, ifail] = ...
    d02lx(0, 1e-4, zeros(2,1), zeros(2,1), int64(0), true, true, false, rwork);
fprintf('\n  T       Y(1)       Y(2)\n');
fprintf('%4.1f %10.5f %10.5f\n', t, y(1), y(2));
while (t < tend && ifail == 0)
  [t, y, yp, ydp, rwork, ifail] = d02la(@fcn, t, tend, y, yp, ydp, rwork);
  while (tnext <= t && ifail == 0)
    [ywant, ypwant, ifail] = d02lz(t, y, yp, nwant, tnext, rwork);
    fprintf('%4.1f %10.5f %10.5f\n', tnext, ywant(1), ywant(2));
    tnext = tnext + 2;
  end
end

if (ifail == 0)
  [hnext, hused, hstart, nsucc, nfail, natt, thres, thresp, ifail] = ...
    d02ly(nwant, rwork);

  fprintf('\n Number of successful steps = %d\n', nsucc);
  fprintf(' Number of failed steps     = %d\n', nfail);
end



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;
 

  T       Y(1)       Y(2)
 0.0    0.50000    0.00000
 2.0   -1.20573    0.61357
 4.0   -1.33476   -0.47685
 6.0    0.35748   -0.44558
 8.0   -1.03762    0.73022
10.0   -1.42617   -0.32658
12.0    0.05515   -0.72032
14.0   -0.82880    0.81788
16.0   -1.48103   -0.16788
18.0   -0.26719   -0.84223
20.0   -0.57803    0.86339

 Number of successful steps = 108
 Number of failed steps     = 16


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