Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_ode_ivp_rk_range (d02pc)

## Purpose

nag_ode_ivp_rk_range (d02pc) solves an initial value problem for a first-order system of ordinary differential equations using Runge–Kutta methods.
Note: this function is scheduled to be withdrawn, please see d02pc in Advice on Replacement Calls for Withdrawn/Superseded Routines..

## Syntax

[tgot, ygot, ypgot, ymax, work, ifail] = d02pc(f, neq, twant, ygot, ymax, work)
[tgot, ygot, ypgot, ymax, work, ifail] = nag_ode_ivp_rk_range(f, neq, twant, ygot, ymax, work)

## Description

nag_ode_ivp_rk_range (d02pc) and its associated functions (nag_ode_ivp_rk_setup (d02pv), nag_ode_ivp_rk_diag (d02py) and nag_ode_ivp_rk_errass (d02pz)) solve an 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′ = f(t,y)  given  y(t0) = y0 $y′=f(t,y) given y(t0)=y0$
where y$y$ is the vector of n$\mathit{n}$ solution components and t$t$ is the independent variable.
nag_ode_ivp_rk_range (d02pc) is designed for the usual task, namely to compute an approximate solution at a sequence of points. You must first call nag_ode_ivp_rk_setup (d02pv) to specify the problem and how it is to be solved. Thereafter you call nag_ode_ivp_rk_range (d02pc) repeatedly with successive values of twant, the points at which you require the solution, in the range from tstart to tend (as specified in nag_ode_ivp_rk_setup (d02pv)). In this manner nag_ode_ivp_rk_range (d02pc) returns the point at which it has computed a solution tgot (usually twant), the solution there (ygot) and its derivative (ypgot). If nag_ode_ivp_rk_range (d02pc) encounters some difficulty in taking a step toward twant, then it returns the point of difficulty (tgot) and the solution and derivative computed there (ygot and ypgot, respectively).
In the call to nag_ode_ivp_rk_setup (d02pv) you can specify either the first step size for nag_ode_ivp_rk_range (d02pc) to attempt or that it compute automatically an appropriate value. Thereafter nag_ode_ivp_rk_range (d02pc) estimates an appropriate step size for its next step. This value and other details of the integration can be obtained after any call to nag_ode_ivp_rk_range (d02pc) by a call to nag_ode_ivp_rk_diag (d02py). The local error is controlled at every step as specified in nag_ode_ivp_rk_setup (d02pv). If you wish to assess the true error, you must set errass = true${\mathbf{errass}}=\mathbf{true}$ in the call to nag_ode_ivp_rk_setup (d02pv). This assessment can be obtained after any call to nag_ode_ivp_rk_range (d02pc) by a call to nag_ode_ivp_rk_errass (d02pz).
For more complicated tasks, you are referred to functions nag_ode_ivp_rk_onestep (d02pd), nag_ode_ivp_rk_reset_tend (d02pw) and nag_ode_ivp_rk_interp (d02px), all of which are used by nag_ode_ivp_rk_range (d02pc).

## 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:     f – function handle or string containing name of m-file
f must evaluate the functions fi${f}_{i}$ (that is the first derivatives yi${y}_{i}^{\prime }$) for given values of the arguments t$t$, yi${y}_{i}$.
[yp] = f(t, y)

Input Parameters

1:     t – double scalar
t$t$, the current value of the independent variable.
2:     y( : $:$) – double array
The current values of the dependent variables, yi${y}_{\mathit{i}}$, for i = 1,2,,n$\mathit{i}=1,2,\dots ,\mathit{n}$.

Output Parameters

1:     yp( : $:$) – double array
The values of fi${f}_{\mathit{i}}$, for i = 1,2,,n$\mathit{i}=1,2,\dots ,\mathit{n}$.
2:     neq – int64int32nag_int scalar
n$n$, the number of ordinary differential equations in the system to be solved by the integration function.
Constraint: neq1${\mathbf{neq}}\ge 1$.
3:     twant – double scalar
t$t$, the next value of the independent variable where a solution is desired.
Constraint: twant must be closer to tend than the previous value of tgot (or tstart on the first call to nag_ode_ivp_rk_range (d02pc)); see nag_ode_ivp_rk_setup (d02pv) for a description of tstart and tend. twant must not lie beyond tend in the direction of integration.
4:     ygot( : $:$) – double array
Note: the dimension of the array ygot must be at least n$\mathit{n}$.
On the first call to nag_ode_ivp_rk_range (d02pc), ygot need not be set. On all subsequent calls ygot must remain unchanged.
5:     ymax( : $:$) – double array
Note: the dimension of the array ymax must be at least n$\mathit{n}$.
On the first call to nag_ode_ivp_rk_range (d02pc), ymax need not be set. On all subsequent calls ymax must remain unchanged.
6:     work( : $:$) – double array
Note: the dimension of the array work must be at least lenwrk${\mathbf{lenwrk}}$ (see nag_ode_ivp_rk_setup (d02pv)).
This must be the same array as supplied to nag_ode_ivp_rk_setup (d02pv). It must remain unchanged between calls.

None.

None.

### Output Parameters

1:     tgot – double scalar
t$t$, the value of the independent variable at which a solution has been computed. On successful exit with ${\mathbf{ifail}}={\mathbf{0}}$, tgot will equal twant. On exit with ${\mathbf{ifail}}>{\mathbf{1}}$, a solution has still been computed at the value of tgot but in general tgot will not equal twant.
2:     ygot( : $:$) – double array
Note: the dimension of the array ygot must be at least n$\mathit{n}$.
An approximation to the true solution at the value of tgot. At each step of the integration to tgot, the local error has been controlled as specified in nag_ode_ivp_rk_setup (d02pv). The local error has still been controlled even when ${\mathbf{tgot}}\ne {\mathbf{twant}}$, that is after a return with ${\mathbf{ifail}}>{\mathbf{1}}$.
3:     ypgot( : $:$) – double array
Note: the dimension of the array ypgot must be at least n$\mathit{n}$.
An approximation to the first derivative of the true solution at tgot.
4:     ymax( : $:$) – double array
Note: the dimension of the array ymax must be at least n$\mathit{n}$.
ymax(i)${\mathbf{ymax}}\left(i\right)$ contains the largest value of |yi|$|{y}_{i}|$ computed at any step in the integration so far.
5:     work( : $:$) – double array
Note: the dimension of the array work must be at least lenwrk${\mathbf{lenwrk}}$ (see nag_ode_ivp_rk_setup (d02pv)).
Information about the integration for use on subsequent calls to nag_ode_ivp_rk_range (d02pc) or other associated functions.
6:     ifail – int64int32nag_int scalar
${\mathrm{ifail}}={\mathbf{0}}$ unless the function detects an error (see [Error Indicators and Warnings]).

## Error Indicators and Warnings

Errors or warnings detected by the function:

Cases prefixed with W are classified as warnings and do not generate an error of type NAG:error_n. See nag_issue_warnings.

ifail = 1${\mathbf{ifail}}=1$
On entry, an invalid input value for twant was detected or an invalid call to nag_ode_ivp_rk_range (d02pc) was made, for example without a previous call to the setup function nag_ode_ivp_rk_setup (d02pv). You cannot continue integrating the problem.
W ifail = 2${\mathbf{ifail}}=2$
This return is possible only when method = 3${\mathbf{method}}=3$ has been selected in the preceding call of nag_ode_ivp_rk_setup (d02pv). nag_ode_ivp_rk_range (d02pc) is being used inefficiently because the step size has been reduced drastically many times to get answers at many values of twant. If you really need the solution at this many points, you should change to method = 2${\mathbf{method}}=2$ because it is (much) more efficient in this situation. To change method, restart the integration from tgot, ygot by a call to nag_ode_ivp_rk_setup (d02pv). If you wish to continue with method = 3${\mathbf{method}}=3$, just call nag_ode_ivp_rk_range (d02pc) again without altering any of the arguments. The monitor of this kind of inefficiency will be reset automatically so that the integration can proceed.
W ifail = 3${\mathbf{ifail}}=3$
A considerable amount of work has been expended in the (primary) integration. This is measured by counting the number of calls to the supplied function f. At least 5000$5000$ calls have been made since the last time this counter was reset. Calls to f in a secondary integration for global error assessment (when errass = true${\mathbf{errass}}=\mathbf{true}$ in the call to nag_ode_ivp_rk_setup (d02pv)) are not counted in this total. The integration was interrupted, so tgot is not equal to twant. If you wish to continue on towards twant, just call nag_ode_ivp_rk_range (d02pc) again without altering any of the arguments. The counter measuring work will be reset to zero automatically.
W ifail = 4${\mathbf{ifail}}=4$
It appears that this problem is stiff. The methods implemented in nag_ode_ivp_rk_range (d02pc) can solve such problems, but they are inefficient. You should change to another code based on methods appropriate for stiff problems. The integration was interrupted so tgot is not equal to twant. If you want to continue on towards twant, just call nag_ode_ivp_rk_range (d02pc) again without altering any of the arguments. The stiffness monitor will be reset automatically.
W ifail = 5${\mathbf{ifail}}=5$
It does not appear possible to achieve the accuracy specified by tol and thres in the call to nag_ode_ivp_rk_setup (d02pv) with the precision available on the computer being used and with this value of method. You cannot continue integrating this problem. A larger value for method, if possible, will permit greater accuracy with this precision. To increase method and/or continue with larger values of tol and/or thres, restart the integration from tgot, ygot by a call to nag_ode_ivp_rk_setup (d02pv).
W ifail = 6${\mathbf{ifail}}=6$
(This error exit can only occur if errass = true${\mathbf{errass}}=\mathbf{true}$ in the call to nag_ode_ivp_rk_setup (d02pv).) The global error assessment may not be reliable beyond the current integration point tgot. This may occur because either too little or too much accuracy has been requested or because f(t,y)$f\left(t,y\right)$ is not smooth enough for values of t$t$ just past tgot and current values of the solution y$y$. The integration cannot be continued. This return does not mean that you cannot integrate past tgot, rather that you cannot do it with = true$=\mathbf{true}$. However, it may also indicate problems with the primary integration.

## Accuracy

The accuracy of integration is determined by the parameters tol and thres in a prior call to nag_ode_ivp_rk_setup (d02pv) (see the function document for nag_ode_ivp_rk_setup (d02pv) for further details and advice). 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 properties of the differential system.

If nag_ode_ivp_rk_range (d02pc) returns with ${\mathbf{ifail}}={\mathbf{5}}$ and the accuracy specified by tol and thres is really required then you should consider whether there is a more fundamental difficulty. For example, the solution may contain a singularity. In such a region the solution components will usually be large in magnitude. Successive output values of ygot and ymax should be monitored (or nag_ode_ivp_rk_onestep (d02pd) should be used since this takes one integration step at a time) 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.
Performance statistics are available after any return from nag_ode_ivp_rk_range (d02pc) by a call to nag_ode_ivp_rk_diag (d02py). If errass = true${\mathbf{errass}}=\mathbf{true}$ in the call to nag_ode_ivp_rk_setup (d02pv), global error assessment is available after any return from nag_ode_ivp_rk_range (d02pc) (except when ${\mathbf{ifail}}={\mathbf{1}}$) by a call to nag_ode_ivp_rk_errass (d02pz).
After a failure with ${\mathbf{ifail}}={\mathbf{5}}$ or 6${\mathbf{6}}$ the diagnostic functions nag_ode_ivp_rk_diag (d02py) and nag_ode_ivp_rk_errass (d02pz) may be called only once.
If nag_ode_ivp_rk_range (d02pc) returns with ${\mathbf{ifail}}={\mathbf{4}}$ then it is advisable to change to another code more suited to the solution of stiff problems. nag_ode_ivp_rk_range (d02pc) will not return with ${\mathbf{ifail}}={\mathbf{4}}$ if the problem is actually stiff but it is estimated that integration can be completed using less function evaluations than already computed.

## Example

This example solves the equation
 y ′ ′ = − y,  y(0) = 0,   y′(0) = 1 $y′′=-y, y(0)=0, y′(0)=1$
reposed as
 y1 ′ = y2 $y1′=y2$
 y2 ′ = − y1 $y2′=-y1$
over the range [0,2π]$\left[0,2\pi \right]$ with initial conditions y1 = 0.0${y}_{1}=0.0$ and y2 = 1.0${y}_{2}=1.0$. Relative error control is used with threshold values of 1.0e−8$\text{1.0e−8}$ for each solution component and compute the solution at intervals of length π / 4$\pi /4$ across the range. A low-order Runge–Kutta method (method = 1${\mathbf{method}}=1$, see nag_ode_ivp_rk_setup (d02pv)) is also used with tolerances tol = 1.0e−3${\mathbf{tol}}=\text{1.0e−3}$ and tol = 1.0e−4${\mathbf{tol}}=\text{1.0e−4}$ in turn so that the solutions can be compared. The value of π$\pi$ is obtained by using nag_math_pi (x01aa).
Note that the length of work is large enough for any valid combination of input arguments to nag_ode_ivp_rk_setup (d02pv).
```function nag_ode_ivp_rk_range_example
% Initialize variables and arrays.
tstart = 0;
ystart = [0; 1];
hstart = 0;
tend = 2*pi;
tol = 0.001;
thres = [1e-08; 1e-08];
method = 1;
errass = false;
lenwrk = 64;
neq = 2;
twant = 0.7853981633974483;
ygot = [0; 0];
ymax = [0; 0];

fprintf('nag_ode_ivp_rk_range example program results \n\n');

% We run through the calculation twice; the first time with a small
% number of points (when we'll output the results), and the second time
% with a larger number (when we'll plot them).
npts = [8, 40];
for ipts = 1:2
tinc = (tend-tstart)/npts(ipts);

ncall = [0, 0];
y1keep = [ystart(1),ystart(1)];
y2keep = [ystart(2),ystart(2)];
err = [0, 0];
tolkeep = [1];
tkeep = [tstart];

for i = 1:2
if (i == 1)
tol = double(1e-3);
elseif (i == 2)
tol = double(1e-4);
end
tolkeep(i) = tol;

% nag_ode_ivp_rk_setup is a setup routine to be called prior to nag_ode_ivp_rk_range.
[work, ifail] = nag_ode_ivp_rk_setup(tstart, ystart, tend, tol, thres, ...
int64(method), task, errass, int64(lenwrk), 'neq', ...
int64(neq), 'hstart', hstart);
if ifail ~= 0
% Illegal input.  Print message and exit.
error('Warning: nag_ode_ivp_rk_setup returned with ifail = %1d ',ifail);
end

if ipts == 1
fprintf('Calculation with tol = %1.3e\n\n',tol);
disp('   t         y1        y2');
fprintf(' %1.3f %9.3f %9.3f\n', tstart, ystart(1), ystart(2));
end
for j = npts(ipts)-1:-1:0
twant = tend - j*tinc;

[tgot, ygot, ypgot, ymax, work, ifail] = ...
nag_ode_ivp_rk_range(@f, int64(neq), twant, ygot, ymax, work);
if ifail ~= 0
% Illegal input.  Print message and exit.
error('Warning: nag_ode_ivp_rk_range returned with ifail = %1d ',...
ifail);
end

if ipts == 1
fprintf(' %1.3f %9.3f %9.3f\n', tgot, ygot(1), ygot(2));
end

% Store results for plotting (second time around).
ncall(i) = ncall(i) + 1;
y1keep(ncall(i),i) = ygot(1);
y2keep(ncall(i),i) = ygot(2);
err(ncall(i),i) = ygot(1)-sin(tgot);
tkeep(ncall(i),i) = tgot;
end

% nag_ode_ivp_rk_diag is a diagnostic routine.
[totfcn, stpcst, waste, stpsok, hnext, ifail] = nag_ode_ivp_rk_diag;

if ipts == 1
fprintf(['\nCost of the integration in evaluations of ', ...
'F is %1.0f\n\n\n'], totfcn);
end
end
end
% Plot results.
fig = figure('Number', 'off');
display_plot(tkeep, y1keep, y2keep, err);

function [yp] = f(t, y)
% Evaluate derivative vector.
yp = zeros(2, 1);
yp(1) =  y(2);
yp(2) = -y(1);
function display_plot(tkeep, y1keep, y2keep, error1)
% Formatting for title and axis labels.
titleFmt = {'FontName', 'Helvetica', 'FontWeight', 'Bold', 'FontSize', 14};
labFmt = {'FontName', 'Helvetica', 'FontWeight', 'Bold', 'FontSize', 13};
set(gca, 'FontSize', 13); % for legend, axis tick labels, etc.
% Plot two of the curves and then add the other one.
[haxes, hline1, hline2] = plotyy(tkeep(:,1), y1keep(:,2), tkeep(:,1), ...
abs(error1(:,1)), 'plot', 'semilogy');
hold on
hline3 = plot(haxes(1), tkeep(:,1), y2keep(:,2));
% Select the required y axis, and plot the fourth curve.
axes(haxes(2));
hold on
hline4 = plot(tkeep(:,1), abs(error1(:,2)));
% Set the axis limits and the tick specifications to beautify the plot.
set(haxes(1), 'YLim', [-1 1.2]);
set(haxes(1), 'YMinorTick', 'on');
set(haxes(1), 'YTick', [-1 -0.6 -0.2 0.2 0.6 1.0]);
set(haxes(2), 'YLim', [1e-7 1e-2]);
set(haxes(2), 'YMinorTick', 'on');
set(haxes(2), 'YTick', [1e-7 1e-6 1e-5 1e-4 1e-3 1e-2]);
for iaxis = 1:2
% These properties must be the same for both sets of axes.
set(haxes(iaxis), 'XLim', [0 7]);
set(haxes(iaxis), 'XTick', [0 1 2 3 4 5 6 7]);
set(haxes(iaxis), 'FontSize', 13);
end
set(gca, 'box', 'off'); % so ticks aren't shown on opposite axes.
title(['1st-order ODEs using RK ', ...
'Low-order Method with 2 Tolerances'], titleFmt{:})
% Label the x axis, and both y axes.
xlabel('t', labFmt{:});
ylabel(haxes(1),'Solution (y,y'')', labFmt{:});
ylabel(haxes(2),'abs(Error)', labFmt{:});
legend('y-error (tol= 0.001)','y-error (tol= 0.0001)','y','y''', ...
'Location','Best')
% Set some features of the lines.
set(hline1, 'Linewidth', 0.5, 'Marker', '+','LineStyle','-');
set(hline2, 'Linewidth', 0.5, 'Marker', 's','LineStyle','--');
set(hline3, 'Linewidth', 0.5, 'Marker', 'x','LineStyle','-.');
set(hline4, 'Linewidth', 0.5, 'Marker', '*','LineStyle',':');
```
```
nag_ode_ivp_rk_range example program results

Calculation with tol = 1.000e-03

t         y1        y2
0.000     0.000     1.000
0.785     0.707     0.707
1.571     0.999    -0.000
2.356     0.706    -0.706
3.142    -0.000    -0.999
3.927    -0.706    -0.706
4.712    -0.998     0.000
5.498    -0.705     0.706
6.283     0.001     0.997

Cost of the integration in evaluations of F is 124

Calculation with tol = 1.000e-04

t         y1        y2
0.000     0.000     1.000
0.785     0.707     0.707
1.571     1.000    -0.000
2.356     0.707    -0.707
3.142    -0.000    -1.000
3.927    -0.707    -0.707
4.712    -1.000     0.000
5.498    -0.707     0.707
6.283     0.000     1.000

Cost of the integration in evaluations of F is 235

```
```function d02pc_example
% Initialize variables and arrays.
tstart = 0;
ystart = [0; 1];
hstart = 0;
tend = 2*pi;
tol = 0.001;
thres = [1e-08; 1e-08];
method = 1;
errass = false;
lenwrk = 64;
neq = 2;
twant = 0.7853981633974483;
ygot = [0; 0];
ymax = [0; 0];

fprintf('d02pc example program results \n\n');

% We run through the calculation twice; the first time with a small
% number of points (when we'll output the results), and the second time
% with a larger number (when we'll plot them).
npts = [8, 40];
for ipts = 1:2
tinc = (tend-tstart)/npts(ipts);

ncall = [0, 0];
y1keep = [ystart(1),ystart(1)];
y2keep = [ystart(2),ystart(2)];
err = [0, 0];
tolkeep = [1];
tkeep = [tstart];

for i = 1:2
if (i == 1)
tol = double(1e-3);
elseif (i == 2)
tol = double(1e-4);
end
tolkeep(i) = tol;

% d02pv is a setup routine to be called prior to d02pc.
[work, ifail] = d02pv(tstart, ystart, tend, tol, thres, ...
int64(method), task, errass, int64(lenwrk), 'neq', ...
int64(neq), 'hstart', hstart);
if ifail ~= 0
% Illegal input.  Print message and exit.
error('Warning: d02pv returned with ifail = %1d ',ifail);
end

if ipts == 1
fprintf('Calculation with tol = %1.3e\n\n',tol);
disp('   t         y1        y2');
fprintf(' %1.3f %9.3f %9.3f\n', tstart, ystart(1), ystart(2));
end
for j = npts(ipts)-1:-1:0
twant = tend - j*tinc;

[tgot, ygot, ypgot, ymax, work, ifail] = ...
d02pc(@f, int64(neq), twant, ygot, ymax, work);
if ifail ~= 0
% Illegal input.  Print message and exit.
error('Warning: d02pc returned with ifail = %1d ',...
ifail);
end

if ipts == 1
fprintf(' %1.3f %9.3f %9.3f\n', tgot, ygot(1), ygot(2));
end

% Store results for plotting (second time around).
ncall(i) = ncall(i) + 1;
y1keep(ncall(i),i) = ygot(1);
y2keep(ncall(i),i) = ygot(2);
err(ncall(i),i) = ygot(1)-sin(tgot);
tkeep(ncall(i),i) = tgot;
end

% d02py is a diagnostic routine.
[totfcn, stpcst, waste, stpsok, hnext, ifail] = d02py;

if ipts == 1
fprintf(['\nCost of the integration in evaluations of ', ...
'F is %1.0f\n\n\n'], totfcn);
end
end
end
% Plot results.
fig = figure('Number', 'off');
display_plot(tkeep, y1keep, y2keep, err);

function [yp] = f(t, y)
% Evaluate derivative vector.
yp = zeros(2, 1);
yp(1) =  y(2);
yp(2) = -y(1);
function display_plot(tkeep, y1keep, y2keep, error1)
% Formatting for title and axis labels.
titleFmt = {'FontName', 'Helvetica', 'FontWeight', 'Bold', 'FontSize', 14};
labFmt = {'FontName', 'Helvetica', 'FontWeight', 'Bold', 'FontSize', 13};
set(gca, 'FontSize', 13); % for legend, axis tick labels, etc.
% Plot two of the curves and then add the other one.
[haxes, hline1, hline2] = plotyy(tkeep(:,1), y1keep(:,2), tkeep(:,1), ...
abs(error1(:,1)), 'plot', 'semilogy');
hold on
hline3 = plot(haxes(1), tkeep(:,1), y2keep(:,2));
% Select the required y axis, and plot the fourth curve.
axes(haxes(2));
hold on
hline4 = plot(tkeep(:,1), abs(error1(:,2)));
% Set the axis limits and the tick specifications to beautify the plot.
set(haxes(1), 'YLim', [-1 1.2]);
set(haxes(1), 'YMinorTick', 'on');
set(haxes(1), 'YTick', [-1 -0.6 -0.2 0.2 0.6 1.0]);
set(haxes(2), 'YLim', [1e-7 1e-2]);
set(haxes(2), 'YMinorTick', 'on');
set(haxes(2), 'YTick', [1e-7 1e-6 1e-5 1e-4 1e-3 1e-2]);
for iaxis = 1:2
% These properties must be the same for both sets of axes.
set(haxes(iaxis), 'XLim', [0 7]);
set(haxes(iaxis), 'XTick', [0 1 2 3 4 5 6 7]);
set(haxes(iaxis), 'FontSize', 13);
end
set(gca, 'box', 'off'); % so ticks aren't shown on opposite axes.
title(['1st-order ODEs using RK ', ...
'Low-order Method with 2 Tolerances'], titleFmt{:})
% Label the x axis, and both y axes.
xlabel('t', labFmt{:});
ylabel(haxes(1),'Solution (y,y'')', labFmt{:});
ylabel(haxes(2),'abs(Error)', labFmt{:});
legend('y-error (tol= 0.001)','y-error (tol= 0.0001)','y','y''', ...
'Location','Best')
% Set some features of the lines.
set(hline1, 'Linewidth', 0.5, 'Marker', '+','LineStyle','-');
set(hline2, 'Linewidth', 0.5, 'Marker', 's','LineStyle','--');
set(hline3, 'Linewidth', 0.5, 'Marker', 'x','LineStyle','-.');
set(hline4, 'Linewidth', 0.5, 'Marker', '*','LineStyle',':');
```
```
d02pc example program results

Calculation with tol = 1.000e-03

t         y1        y2
0.000     0.000     1.000
0.785     0.707     0.707
1.571     0.999    -0.000
2.356     0.706    -0.706
3.142    -0.000    -0.999
3.927    -0.706    -0.706
4.712    -0.998     0.000
5.498    -0.705     0.706
6.283     0.001     0.997

Cost of the integration in evaluations of F is 124

Calculation with tol = 1.000e-04

t         y1        y2
0.000     0.000     1.000
0.785     0.707     0.707
1.571     1.000    -0.000
2.356     0.707    -0.707
3.142    -0.000    -1.000
3.927    -0.707    -0.707
4.712    -1.000     0.000
5.498    -0.707     0.707
6.283     0.000     1.000

Cost of the integration in evaluations of F is 235

```