d02 Chapter Contents
d02 Chapter Introduction
NAG Library Manual

NAG Library Function Documentnag_ode_ivp_rkts_interp (d02psc)

1  Purpose

nag_ode_ivp_rkts_interp (d02psc) computes the solution of a system of ordinary differential equations using interpolation anywhere on an integration step taken by nag_ode_ivp_rkts_onestep (d02pfc).

2  Specification

 #include #include
void  nag_ode_ivp_rkts_interp (Integer n, double twant, Nag_SolDeriv reqest, Integer nwant, double ywant[], double ypwant[],
 void (*f)(double t, Integer n, const double y[], double yp[], Nag_Comm *comm),
double wcomm[], Integer lwcomm, Nag_Comm *comm, Integer iwsav[], double rwsav[], NagError *fail)

3  Description

nag_ode_ivp_rkts_interp (d02psc) and its associated functions (nag_ode_ivp_rkts_onestep (d02pfc)nag_ode_ivp_rkts_setup (d02pqc)nag_ode_ivp_rkts_reset_tend (d02prc)nag_ode_ivp_rkts_diag (d02ptc) and nag_ode_ivp_rkts_errass (d02puc)) 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 $\mathit{n}$ solution components and $t$ is the independent variable.
nag_ode_ivp_rkts_onestep (d02pfc) computes the solution at the end of an integration step. Using the information computed on that step nag_ode_ivp_rkts_interp (d02psc) computes the solution by interpolation at any point on that step. It cannot be used if ${\mathbf{method}}=\mathrm{Nag_RK_7_8}$ was specified in the call to setup function nag_ode_ivp_rkts_setup (d02pqc).

4  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

5  Arguments

1:     nIntegerInput
On entry: $n$, the number of ordinary differential equations in the system to be solved by the integration function.
Constraint: ${\mathbf{n}}\ge 1$.
2:     twantdoubleInput
On entry: $t$, the value of the independent variable where a solution is desired.
3:     reqestNag_SolDerivInput
On entry: determines whether the solution and/or its first derivative are to be computed
${\mathbf{reqest}}=\mathrm{Nag_Sol}$
compute approximate solution.
${\mathbf{reqest}}=\mathrm{Nag_Der}$
compute approximate first derivative.
${\mathbf{reqest}}=\mathrm{Nag_SolDer}$
compute approximate solution and first derivative.
Constraint: ${\mathbf{reqest}}=\mathrm{Nag_Sol}$, $\mathrm{Nag_Der}$ or $\mathrm{Nag_SolDer}$.
4:     nwantIntegerInput
On entry: the number of components of the solution to be computed. The first nwant components are evaluated.
Constraint: $1\le {\mathbf{nwant}}\le {\mathbf{n}}$.
5:     ywant[nwant]doubleOutput
On exit: an approximation to the first nwant components of the solution at twant if ${\mathbf{reqest}}=\mathrm{Nag_Sol}$ or $\mathrm{Nag_SolDer}$. Otherwise ywant is not defined.
6:     ypwant[nwant]doubleOutput
On exit: an approximation to the first nwant components of the first derivative at twant if ${\mathbf{reqest}}=\mathrm{Nag_Der}$ or $\mathrm{Nag_SolDer}$. Otherwise ypwant is not defined.
7:     ffunction, supplied by the userExternal Function
f must evaluate the functions ${f}_{i}$ (that is the first derivatives ${y}_{i}^{\prime }$) for given values of the arguments $t,{y}_{i}$. It must be the same procedure as supplied to nag_ode_ivp_rkts_onestep (d02pfc).
The specification of f is:
 void f (double t, Integer n, const double y[], double yp[], Nag_Comm *comm)
1:     tdoubleInput
On entry: $t$, the current value of the independent variable.
2:     nIntegerInput
On entry: $\mathit{n}$, the number of ordinary differential equations in the system to be solved.
3:     y[n]const doubleInput
On entry: the current values of the dependent variables, ${y}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,\mathit{n}$.
4:     yp[n]doubleOutput
On exit: the values of ${f}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,\mathit{n}$.
5:     commNag_Comm *
Pointer to structure of type Nag_Comm; the following members are relevant to f.
userdouble *
iuserInteger *
pPointer
The type Pointer will be void *. Before calling nag_ode_ivp_rkts_interp (d02psc) you may allocate memory and initialize these pointers with various quantities for use by f when called from nag_ode_ivp_rkts_interp (d02psc) (see Section 3.2.1.1 in the Essential Introduction).
8:     wcomm[lwcomm]doubleCommunication Array
On entry: this array stores information that can be utilized on subsequent calls to nag_ode_ivp_rkts_interp (d02psc).
9:     lwcommIntegerInput
On entry: length of wcomm.
If in a previous call to nag_ode_ivp_rkts_setup (d02pqc):
• ${\mathbf{method}}=\mathrm{Nag_RK_2_3}$ then lwcomm must be at least $1$.
• ${\mathbf{method}}=\mathrm{Nag_RK_4_5}$ then lwcomm must be at least ${\mathbf{n}}+\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{n}},5×{\mathbf{nwant}}\right)$.
• ${\mathbf{method}}=\mathrm{Nag_RK_7_8}$ then wcomm and lwcomm are not referenced.
10:   commNag_Comm *Communication Structure
The NAG communication argument (see Section 3.2.1.1 in the Essential Introduction).
11:   iwsav[$130$]IntegerCommunication Array
12:   rwsav[$32×{\mathbf{n}}+350$]doubleCommunication Array
On entry: these must be the same arrays supplied in a previous call nag_ode_ivp_rkts_onestep (d02pfc). They must remain unchanged between calls.
On exit: information about the integration for use on subsequent calls to nag_ode_ivp_rkts_onestep (d02pfc), nag_ode_ivp_rkts_interp (d02psc) or other associated functions.
13:   failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

6  Error Indicators and Warnings

On entry, argument $⟨\mathit{\text{value}}⟩$ had an illegal value.
NE_INT
On entry, ${\mathbf{lwcomm}}=⟨\mathit{\text{value}}⟩$.
Constraint: for ${\mathbf{method}}=\mathrm{Nag_RK_2_3}$, ${\mathbf{lwcomm}}\ge 1$.
NE_INT_2
On entry, ${\mathbf{nwant}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: $1\le {\mathbf{nwant}}\le {\mathbf{n}}$.
NE_INT_3
On entry, ${\mathbf{lwcomm}}=⟨\mathit{\text{value}}⟩$, ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{nwant}}=⟨\mathit{\text{value}}⟩$.
Constraint: for ${\mathbf{method}}=\mathrm{Nag_RK_4_5}$, ${\mathbf{lwcomm}}\ge {\mathbf{n}}+\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{n}},5×{\mathbf{nwant}}\right)$.
NE_INT_CHANGED
On entry, ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$, but the value passed to the setup function was ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
NE_MISSING_CALL
You cannot call this function before you have called the step integrator.
NE_PREV_CALL
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.
NE_PREV_CALL_INI
You cannot call this function after the integrator has returned an error.
NE_RK_INVALID_CALL
You cannot call this function when you have specified, in the setup function, that the range integrator will be used.
NE_RK_NO_INTERP
${\mathbf{method}}=\mathrm{Nag_RK_7_8}$ in setup, but interpolation is not available for this method. Either use ${\mathbf{method}}=\mathrm{Nag_RK_4_5}$ in setup or use reset function to force the integrator to step to particular points.

7  Accuracy

The computed values will be of a similar accuracy to that computed by nag_ode_ivp_rkts_onestep (d02pfc).

8  Parallelism and Performance

nag_ode_ivp_rkts_interp (d02psc) is not threaded by NAG in any implementation.
nag_ode_ivp_rkts_interp (d02psc) makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.

None.

10  Example

This example solves the equation
 $y′′ = -y , y0=0, y′0=1$
reposed as
 $y1′ = y2$
 $y2′ = -y1$
over the range $\left[0,2\pi \right]$ with initial conditions ${y}_{1}=0.0$ and ${y}_{2}=1.0$. Relative error control is used with threshold values of $\text{1.0e−8}$ for each solution component. nag_ode_ivp_rkts_onestep (d02pfc) is used to integrate the problem one step at a time and nag_ode_ivp_rkts_interp (d02psc) is used to compute the first component of the solution and its derivative at intervals of length $\pi /8$ across the range whenever these points lie in one of those integration steps. A low order Runge–Kutta method (${\mathbf{method}}=\mathrm{Nag_RK_2_3}$) is also used with tolerances ${\mathbf{tol}}=\text{1.0e−4}$ and ${\mathbf{tol}}=\text{1.0e−5}$ in turn so that solutions may be compared.

10.1  Program Text

Program Text (d02psce.c)

10.2  Program Data

Program Data (d02psce.d)

10.3  Program Results

Program Results (d02psce.r)