D02 Chapter Contents
D02 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentD02PXF

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

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

## 2  Specification

 SUBROUTINE D02PXF ( TWANT, REQEST, NWANT, YWANT, YPWANT, F, WORK, WRKINT, LENINT, IFAIL)
 INTEGER NWANT, LENINT, IFAIL REAL (KIND=nag_wp) TWANT, YWANT(*), YPWANT(*), WORK(*), WRKINT(LENINT) CHARACTER(1) REQEST EXTERNAL F

## 3  Description

D02PXF and its associated routines (D02PDF, D02PVF, D02PWF, D02PYF and D02PZF) 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.
D02PDF computes the solution at the end of an integration step. Using the information computed on that step D02PXF computes the solution by interpolation at any point on that step. It cannot be used if ${\mathbf{METHOD}}=3$ was specified in the call to setup routine D02PVF.

## 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  Parameters

1:     TWANT – REAL (KIND=nag_wp)Input
On entry: $t$, the value of the independent variable where a solution is desired.
2:     REQEST – CHARACTER(1)Input
On entry: determines whether the solution and/or its first derivative are to be computed.
${\mathbf{REQEST}}=\text{'S'}$
Compute the approximate solution only.
${\mathbf{REQEST}}=\text{'D'}$
Compute the approximate first derivative of the solution only.
${\mathbf{REQEST}}=\text{'B'}$
Compute both the approximate solution and its first derivative.
Constraint: ${\mathbf{REQEST}}=\text{'S'}$, $\text{'D'}$ or $\text{'B'}$.
3:     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 \mathit{n}$, where $\mathit{n}$ is specified by NEQ in the prior call to D02PVF.
4:     YWANT($*$) – REAL (KIND=nag_wp) arrayOutput
Note: the dimension of the array YWANT must be at least ${\mathbf{NWANT}}$ if ${\mathbf{REQEST}}=\text{'S'}$ or $\text{'B'}$, and at least $1$ otherwise.
On exit: an approximation to the first NWANT components of the solution at TWANT if ${\mathbf{REQEST}}=\text{'S'}$ or $\text{'B'}$. Otherwise YWANT is not defined.
5:     YPWANT($*$) – REAL (KIND=nag_wp) arrayOutput
Note: the dimension of the array YPWANT must be at least ${\mathbf{NWANT}}$ if ${\mathbf{REQEST}}=\text{'D'}$ or $\text{'B'}$, and at least $1$ otherwise.
On exit: an approximation to the first NWANT components of the first derivative at TWANT if ${\mathbf{REQEST}}=\text{'D'}$ or $\text{'B'}$. Otherwise YPWANT is not defined.
6:     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 D02PDF.
The specification of F is:
 SUBROUTINE F ( T, Y, YP)
 REAL (KIND=nag_wp) T, Y(*), YP(*)
In the description of the parameters of D02PXF below, $\mathit{n}$ denotes the value of NEQ in the call of D02PVF.
1:     T – REAL (KIND=nag_wp)Input
On entry: $t$, the current value of the independent variable.
2:     Y($*$) – 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}$.
3:     YP($*$) – REAL (KIND=nag_wp) arrayOutput
On exit: the values of ${f}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,\mathit{n}$.
F must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which D02PXF is called. Parameters denoted as Input must not be changed by this procedure.
7:     WORK($*$) – REAL (KIND=nag_wp) arrayInput/Output
Note: the dimension of the array WORK must be at least ${\mathbf{LENWRK}}$ (see D02PVF).
On entry: this must be the same array as supplied to D02PDF and must remain unchanged between calls.
On exit: contains information about the integration for use on subsequent calls to D02PDF or other associated routines.
8:     WRKINT(LENINT) – REAL (KIND=nag_wp) arrayInput/Output
On entry: must be the same array as supplied in previous calls, if any, and must remain unchanged between calls to D02PXF.
On exit: the contents are modified.
9:     LENINT – INTEGERInput
On entry: the dimension of the array WRKINT as declared in the (sub)program from which D02PXF is called.
Constraints:
• ${\mathbf{LENINT}}\ge 1$ if ${\mathbf{METHOD}}=1$ in the prior call to D02PVF;
• ${\mathbf{LENINT}}\ge \mathit{n}+5×{\mathbf{NWANT}}$ if ${\mathbf{METHOD}}=2$ and $\mathit{n}$ is specified by NEQ in the prior call to D02PVF.
10:   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$
On entry, an invalid input value for NWANT or LENINT was detected or an invalid call to D02PXF was made, for example without a previous call to the integration routine D02PDF, or after an error return from D02PDF, or if D02PDF was being used with ${\mathbf{METHOD}}=3$. You cannot continue integrating the problem.

## 7  Accuracy

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

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. D02PDF is used to integrate the problem one step at a time and D02PXF 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 moderate order Runge–Kutta method (${\mathbf{METHOD}}=2$) 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. The value of $\pi$ is obtained by using X01AAF.
Note that the length of WORK is large enough for any valid combination of input arguments to D02PVF and the length of WRKINT is large enough for any valid value of the parameter NWANT.

### 9.1  Program Text

Program Text (d02pxfe.f90)

### 9.2  Program Data

Program Data (d02pxfe.d)

### 9.3  Program Results

Program Results (d02pxfe.r)