D02PSF (PDF version)
D02 Chapter Contents
D02 Chapter Introduction
NAG Library Manual

NAG Library Routine Document


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.

+ Contents

    1  Purpose
    7  Accuracy

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


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 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 METHOD=3 or -3 was specified in the call to setup routine D02PQF.

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:     N – INTEGERInput
On entry: n, the number of ordinary differential equations in the system to be solved by the integration routine.
Constraint: N1.
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
compute approximate solution.
compute approximate first derivative.
compute approximate solution and first derivative.
Constraint: 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: 1NWANTN.
5:     YWANT(NWANT) – REAL (KIND=nag_wp) arrayOutput
On exit: an approximation to the first NWANT components of the solution at TWANT if 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 IDERIV=1 or 2. Otherwise YPWANT is not defined.
7:     F – SUBROUTINE, supplied by the user.External Procedure
F must evaluate the functions fi (that is the first derivatives yi) for given values of the arguments t,yi. It must be the same procedure as supplied to D02PFF.
The specification of F is:
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: 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, yi, for i=1,2,,n.
4:     YP(N) – REAL (KIND=nag_wp) arrayOutput
On exit: the values of fi, for i=1,2,,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.
METHOD=1 or -1
LWCOMM must be at least 1.
METHOD=2 or -2
LWCOMM must be at least N+maxN,5×NWANT.
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×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​ 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​ 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 -1​ or ​1 is used it is essential to test the value of IFAIL on exit.
On exit: IFAIL=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6  Error Indicators and Warnings

If on entry IFAIL=0 or -1, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Errors or warnings detected by the routine:
METHOD=3 in setup, but interpolation is not available for this method. Either use METHOD=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, IDERIV=value.
Constraint: IDERIV=0, 1 or 2.
On entry, LWCOMM=value, N=value and NWANT=value.
Constraint: for METHOD=2, LWCOMMN+5NWANT.
On entry, LWCOMM=value.
Constraint: For METHOD=1, LWCOMM1.
On entry, N=value, but the value passed to the setup routine was N=value.
On entry, NWANT=value and N=value.
Constraint: 1NWANTN.
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.

8  Further Comments


9  Example

This example solves the equation
y = -y ,   y0=0,   y0=1
reposed as
y1 = y2
y2 = -y1
over the range 0,2π with initial conditions y1=0.0 and y2=1.0. Relative error control is used with threshold values of 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 π/8 across the range whenever these points lie in one of those integration steps. A low order Runge–Kutta method (METHOD=-1) is also used with tolerances TOL=1.0E−3 and TOL=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)

Produced by GNUPLOT 4.4 patchlevel 0 -1 -0.5 0 0.5 1 0 1 2 3 4 5 6 7 Solution t Example Program Simple Sine Solution, TOL = 0.001 solution derivative

D02PSF (PDF version)
D02 Chapter Contents
D02 Chapter Introduction
NAG Library Manual

© The Numerical Algorithms Group Ltd, Oxford, UK. 2012