nag_ode_ivp_rkts_interp (d02ps) computes the solution of a system of ordinary differential equations using interpolation anywhere on an integration step taken by
nag_ode_ivp_rkts_onestep (d02pf).
nag_ode_ivp_rkts_interp (d02ps) and its associated functions (
nag_ode_ivp_rkts_onestep (d02pf),
nag_ode_ivp_rkts_setup (d02pq),
nag_ode_ivp_rkts_reset_tend (d02pr),
nag_ode_ivp_rkts_diag (d02pt) and
nag_ode_ivp_rkts_errass (d02pu)) 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
where
is the vector of
solution components and
is the independent variable.
nag_ode_ivp_rkts_onestep (d02pf) computes the solution at the end of an integration step. Using the information computed on that step
nag_ode_ivp_rkts_interp (d02ps) computes the solution by interpolation at any point on that step. It cannot be used if
or
was specified in the call to setup function
nag_ode_ivp_rkts_setup (d02pq).
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
-
-
Constraint: .
Constraint: for or , .
Constraint: for or , .
Constraint: , or .
or in setup, but interpolation is not available for this method. Either use or in setup or use reset function to force the integrator to step to particular points.
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, , but the value passed to the setup function was .
You cannot call this function after the integrator has returned an error.
You cannot call this function before you have called the step integrator.
You cannot call this function when you have specified, in the setup function, that the range integrator will be used.
The computed values will be of a similar accuracy to that computed by
nag_ode_ivp_rkts_onestep (d02pf).
None.
This example solves the equation
reposed as
over the range
with initial conditions
and
. Relative error control is used with threshold values of
for each solution component.
nag_ode_ivp_rkts_onestep (d02pf) is used to integrate the problem one step at a time and
nag_ode_ivp_rkts_interp (d02ps) is used to compute the first component of the solution and its derivative at intervals of length
across the range whenever these points lie in one of those integration steps. A low order Runge–Kutta method (
) is also used with tolerances
and
in turn so that solutions may be compared.
function d02ps_example
fprintf('d02ps example results\n\n');
method = int64(2);
tstart = 0;
tend = 2*pi;
yinit = [0;1];
hstart = 0;
thresh = [1e-08; 1e-08];
n = int64(2);
nwant = int64(1);
tol = 1.0E-2;
npts = 32;
wcomm = zeros(n+5*nwant, 1);
twant = zeros(npts+1, 1);
ywant = zeros(npts, nwant);
ypwant = zeros(npts, nwant);
tinc = (tend-tstart)/npts;
for i = 1:2
tol = tol*0.1;
[iwsav, rwsav, ifail] = d02pq(tstart, tend, yinit, tol, thresh, method);
twant(1) = tstart;
twant(2) = tstart + tinc;
ywant(1,1) = yinit(1);
ypwant(1,1) = yinit(2);
t = tstart;
j=1;
while t < tend
[t, y, yp, user, iwsav, rwsav, ifail] = d02pf(@f, n, iwsav, rwsav);
while twant(j+1) < t
j=j+1;
ideriv = int64(2);
[ywant(j, :), ypwant(j, :), wcomm, user, iwsav, rwsav, ifail] = ...
d02ps(n, twant(j), ideriv, nwant, @f, wcomm, iwsav, rwsav);
twant(j+1) = twant(j) + tinc;
end
end
[fevals, stepcost, waste, stepsok, hnext, iwsav, ifail] = d02pt(iwsav,rwsav);
fprintf('\nCalculation with TOL = %8.1e\n\n', tol);
fprintf(' Number of evaluations of f = %d\n', fevals);
end
fig1 = figure;
title('Simple Sine Solution, tol=1e-4');
hold on;
xlabel('t');
ylabel('Solution');
plot(twant(1:npts), ywant(:, 1), '-xr');
text(3, 0.25, 'Solution', 'Color', 'r');
plot(twant(1:npts), ypwant(:, 1), '-xg');
text(1.45, 0.25, 'Derivative', 'Color', 'g');
hold off
function [yp, user] = f(t, n, y, user)
yp = [y(2); -y(1)];