# NAG CL Interfaced02psc (ivp_​rkts_​interp)

## 1Purpose

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

## 2Specification

 #include
void  d02psc (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)
The function may be called by the names: d02psc or nag_ode_ivp_rkts_interp.

## 3Description

d02psc and its associated functions (d02pfc, d02pqc, d02prc, d02ptc and 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.
d02pfc computes the solution at the end of an integration step. Using the information computed on that step 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 d02pqc.

## 4References

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

## 5Arguments

1: $\mathbf{n}$Integer Input
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: $\mathbf{twant}$double Input
On entry: $t$, the value of the independent variable where a solution is desired.
3: $\mathbf{reqest}$Nag_SolDeriv Input
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: $\mathbf{nwant}$Integer Input
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: $\mathbf{ywant}\left[{\mathbf{nwant}}\right]$double Output
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: $\mathbf{ypwant}\left[{\mathbf{nwant}}\right]$double Output
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: $\mathbf{f}$function, supplied by the user External 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 d02pfc.
The specification of f is:
 void f (double t, Integer n, const double y[], double yp[], Nag_Comm *comm)
1: $\mathbf{t}$double Input
On entry: $t$, the current value of the independent variable.
2: $\mathbf{n}$Integer Input
On entry: $\mathit{n}$, the number of ordinary differential equations in the system to be solved.
3: $\mathbf{y}\left[{\mathbf{n}}\right]$const double Input
On entry: the current values of the dependent variables, ${y}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,\mathit{n}$.
4: $\mathbf{yp}\left[{\mathbf{n}}\right]$double Output
On exit: the values of ${f}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,\mathit{n}$.
5: $\mathbf{comm}$Nag_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 d02psc you may allocate memory and initialize these pointers with various quantities for use by f when called from d02psc (see Section 3.1.1 in the Introduction to the NAG Library CL Interface).
Note: f should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by d02psc. If your code inadvertently does return any NaNs or infinities, d02psc is likely to produce unexpected results.
8: $\mathbf{wcomm}\left[{\mathbf{lwcomm}}\right]$double Communication Array
On entry: this array stores information that can be utilized on subsequent calls to d02psc.
9: $\mathbf{lwcomm}$Integer Input
On entry: length of wcomm.
If in a previous call to 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: $\mathbf{comm}$Nag_Comm *
The NAG communication argument (see Section 3.1.1 in the Introduction to the NAG Library CL Interface).
11: $\mathbf{iwsav}\left[130\right]$Integer Communication Array
12: $\mathbf{rwsav}\left[32×{\mathbf{n}}+350\right]$double Communication Array
On entry: these must be the same arrays supplied in a previous call d02pfc. They must remain unchanged between calls.
On exit: information about the integration for use on subsequent calls to d02pfc, d02psc or other associated functions.
13: $\mathbf{fail}$NagError * Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).

## 6Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 3.1.2 in the Introduction to the NAG Library CL Interface for further information.
NE_BAD_PARAM
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.
See Section 7.5 in the Introduction to the NAG Library CL Interface for further information.
NE_MISSING_CALL
You cannot call this function before you have called the step integrator.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library CL Interface for further information.
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.

## 7Accuracy

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

## 8Parallelism and Performance

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.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this function. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

None.

## 10Example

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. d02pfc is used to integrate the problem one step at a time and 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.1Program Text

Program Text (d02psce.c)

### 10.2Program Data

Program Data (d02psce.d)

### 10.3Program Results

Program Results (d02psce.r)