D02 Chapter Contents
D02 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentD02PSF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

## 1  Purpose

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

## 2  Specification

 SUBROUTINE D02PSF ( N, TWANT, IDERIV, NWANT, YWANT, YPWANT, F, WCOMM, LWCOMM, IUSER, RUSER, IWSAV, RWSAV, IFAIL)
 INTEGER N, IDERIV, NWANT, LWCOMM, IUSER(*), IWSAV(130), IFAIL REAL (KIND=nag_wp) TWANT, YWANT(NWANT), YPWANT(NWANT), WCOMM(LWCOMM), RUSER(*), RWSAV(32*N+350) EXTERNAL F

## 3  Description

D02PSF and its associated routines (D02PFF, D02PQF, D02PRF, D02PTF and D02PUF) solve the initial value problem for a first-order system of ordinary differential equations. The routines, 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.
D02PFF computes the solution at the end of an integration step. Using the information computed on that step D02PSF computes the solution by interpolation at any point on that step. It cannot be used if ${\mathbf{METHOD}}=3$ or $-3$ was specified in the call to setup routine D02PQF.
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  Parameters

1:     N – INTEGERInput
On entry: $n$, the number of ordinary differential equations in the system to be solved by the integration routine.
Constraint: ${\mathbf{N}}\ge 1$.
2:     TWANT – REAL (KIND=nag_wp)Input
On entry: $t$, the value of the independent variable where a solution is desired.
3:     IDERIV – INTEGERInput
On entry: determines whether the solution and/or its first derivative are to be computed
${\mathbf{IDERIV}}=0$
compute approximate solution.
${\mathbf{IDERIV}}=1$
compute approximate first derivative.
${\mathbf{IDERIV}}=2$
compute approximate solution and first derivative.
Constraint: ${\mathbf{IDERIV}}=0$, $1$ or $2$.
4:     NWANT – INTEGERInput
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) – REAL (KIND=nag_wp) arrayOutput
On exit: an approximation to the first NWANT components of the solution at TWANT if ${\mathbf{IDERIV}}=0$ or $2$. Otherwise YWANT is not defined.
6:     YPWANT(NWANT) – REAL (KIND=nag_wp) arrayOutput
On exit: an approximation to the first NWANT components of the first derivative at TWANT if ${\mathbf{IDERIV}}=1$ or $2$. Otherwise YPWANT is not defined.
7:     F – SUBROUTINE, supplied by the user.External Procedure
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 D02PFF.
The specification of F is:
 SUBROUTINE F ( T, N, Y, YP, IUSER, RUSER)
 INTEGER N, IUSER(*) REAL (KIND=nag_wp) T, Y(N), YP(N), RUSER(*)
1:     T – REAL (KIND=nag_wp)Input
On entry: $t$, the current value of the independent variable.
2:     N – INTEGERInput
On entry: $\mathit{n}$, the number of ordinary differential equations in the system to be solved.
3:     Y(N) – REAL (KIND=nag_wp) arrayInput
On entry: the current values of the dependent variables, ${y}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,\mathit{n}$.
4:     YP(N) – REAL (KIND=nag_wp) arrayOutput
On exit: the values of ${f}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,\mathit{n}$.
5:     IUSER($*$) – INTEGER arrayUser Workspace
6:     RUSER($*$) – REAL (KIND=nag_wp) arrayUser Workspace
F is called with the parameters IUSER and RUSER as supplied to D02PSF. You are free to use the arrays IUSER and RUSER to supply information to F as an alternative to using COMMON global variables.
F must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which D02PSF is called. Parameters denoted as Input must not be changed by this procedure.
8:     WCOMM(LWCOMM) – REAL (KIND=nag_wp) arrayCommunication Array
On entry: this array stores information that can be utilized on subsequent calls to D02PSF.
9:     LWCOMM – INTEGERInput
On entry: length of WCOMM.
${\mathbf{METHOD}}=1$ or $-1$
LWCOMM must be at least $1$.
${\mathbf{METHOD}}=2$ or $-2$
LWCOMM must be at least ${\mathbf{N}}+\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{N}},5×{\mathbf{NWANT}}\right)$.
10:   IUSER($*$) – INTEGER arrayUser Workspace
11:   RUSER($*$) – REAL (KIND=nag_wp) arrayUser Workspace
IUSER and RUSER are not used by D02PSF, but are passed directly to F and may be used to pass information to this routine as an alternative to using COMMON global variables.
12:   IWSAV($130$) – INTEGER arrayCommunication Array
13:   RWSAV($32×{\mathbf{N}}+350$) – REAL (KIND=nag_wp) arrayCommunication Array
On entry: these must be the same arrays supplied in a previous call D02PFF. They must remain unchanged between calls.
On exit: information about the integration for use on subsequent calls to D02PFF, D02PSF or other associated routines.
14:   IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value $-1\text{​ or ​}1$ is recommended. If the output of error messages is undesirable, then the value $1$ is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is $0$. When the value $-\mathbf{1}\text{​ or ​}\mathbf{1}$ is used it is essential to test the value of IFAIL on exit.
On exit: ${\mathbf{IFAIL}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6  Error Indicators and Warnings

If on entry ${\mathbf{IFAIL}}={\mathbf{0}}$ or $-{\mathbf{1}}$, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Errors or warnings detected by the routine:
${\mathbf{IFAIL}}=1$
$\left|{\mathbf{METHOD}}\right|=3$ in setup, but interpolation is not available for this method. Either use $\left|{\mathbf{METHOD}}\right|=2$ in setup or use reset routine to force the integrator to step to particular points.
On entry, a previous call to the setup routine 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, ${\mathbf{IDERIV}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{IDERIV}}=0$, $1$ or $2$.
On entry, ${\mathbf{LWCOMM}}=⟨\mathit{\text{value}}⟩$, ${\mathbf{N}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{NWANT}}=⟨\mathit{\text{value}}⟩$.
Constraint: for $\left|{\mathbf{METHOD}}\right|=2$, ${\mathbf{LWCOMM}}\ge {\mathbf{N}}+5{\mathbf{NWANT}}$.
On entry, ${\mathbf{LWCOMM}}=⟨\mathit{\text{value}}⟩$.
Constraint: For $\left|{\mathbf{METHOD}}\right|=1$, ${\mathbf{LWCOMM}}\ge 1$.
On entry, ${\mathbf{N}}=⟨\mathit{\text{value}}⟩$, but the value passed to the setup routine was ${\mathbf{N}}=⟨\mathit{\text{value}}⟩$.
On entry, ${\mathbf{NWANT}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{N}}=⟨\mathit{\text{value}}⟩$.
Constraint: $1\le {\mathbf{NWANT}}\le {\mathbf{N}}$.
You cannot call this routine after the integrator has returned an error.
You cannot call this routine before you have called the step integrator.
You cannot call this routine when you have specified, in the setup routine, that the range integrator will be used.

## 7  Accuracy

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

None.

## 9  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. D02PFF is used to integrate the problem one step at a time and D02PSF 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}}=-1$) is also used with tolerances ${\mathbf{TOL}}=\text{1.0E−3}$ and ${\mathbf{TOL}}=\text{1.0E−4}$ in turn so that solutions may be compared.

### 9.1  Program Text

Program Text (d02psfe.f90)

### 9.2  Program Data

Program Data (d02psfe.d)

### 9.3  Program Results

Program Results (d02psfe.r)