NAG FL Interface
d02psf (ivp_​rkts_​interp)

Settings help

FL Name Style:


FL Specification Language:


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

Fortran Interface
Subroutine d02psf ( n, twant, ideriv, nwant, ywant, ypwant, f, wcomm, lwcomm, iuser, ruser, iwsav, rwsav, ifail)
Integer, Intent (In) :: n, ideriv, nwant, lwcomm
Integer, Intent (Inout) :: iuser(*), iwsav(130), ifail
Real (Kind=nag_wp), Intent (In) :: twant
Real (Kind=nag_wp), Intent (Inout) :: wcomm(lwcomm), ruser(*), rwsav(32*n+350)
Real (Kind=nag_wp), Intent (Out) :: ywant(nwant), ypwant(nwant)
External :: f
C Header Interface
#include <nag.h>
void  d02psf_ (const Integer *n, const double *twant, const Integer *ideriv, const Integer *nwant, double ywant[], double ypwant[],
void (NAG_CALL *f)(const double *t, const Integer *n, const double y[], double yp[], Integer iuser[], double ruser[]),
double wcomm[], const Integer *lwcomm, Integer iuser[], double ruser[], Integer iwsav[], double rwsav[], Integer *ifail)
The routine may be called by the names d02psf or nagf_ode_ivp_rkts_interp.

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=f(t,y)  given  y(t0)=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 Arguments

1: n Integer Input
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 Integer Input
On entry: determines whether the solution and/or its first derivative are to be computed
ideriv=0
compute approximate solution.
ideriv=1
compute approximate first derivative.
ideriv=2
compute approximate solution and first derivative.
Constraint: ideriv=0, 1 or 2.
4: nwant Integer Input
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) array Output
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) array Output
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:
Fortran Interface
Subroutine f ( t, n, y, yp, iuser, ruser)
Integer, Intent (In) :: n
Integer, Intent (Inout) :: iuser(*)
Real (Kind=nag_wp), Intent (In) :: t, y(n)
Real (Kind=nag_wp), Intent (Inout) :: ruser(*)
Real (Kind=nag_wp), Intent (Out) :: yp(n)
C Header Interface
void  f (const double *t, const Integer *n, const double y[], double yp[], Integer iuser[], double ruser[])
1: t Real (Kind=nag_wp) Input
On entry: t, the current value of the independent variable.
2: n Integer Input
On entry: n, the number of ordinary differential equations in the system to be solved.
3: y(n) Real (Kind=nag_wp) array Input
On entry: the current values of the dependent variables, yi, for i=1,2,,n.
4: yp(n) Real (Kind=nag_wp) array Output
On exit: the values of fi, for i=1,2,,n.
5: iuser(*) Integer array User Workspace
6: ruser(*) Real (Kind=nag_wp) array User Workspace
f is called with the arguments iuser and ruser as supplied to d02psf. You should use the arrays iuser and ruser to supply information to f.
f must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which d02psf is called. Arguments denoted as Input must not be changed by this procedure.
Note: f should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by d02psf. If your code inadvertently does return any NaNs or infinities, d02psf is likely to produce unexpected results.
8: wcomm(lwcomm) Real (Kind=nag_wp) array Communication Array
On entry: this array stores information that can be utilized on subsequent calls to d02psf.
9: lwcomm Integer Input
On entry: length of wcomm.
If in a previous call to d02pqf:
  • method=1 or -1 then lwcomm must be at least 1.
  • method=2 or -2 then lwcomm must be at least n+max(n,5×nwant).
  • method=3 or -3 then wcomm and lwcomm are not referenced.
10: iuser(*) Integer array User Workspace
11: ruser(*) Real (Kind=nag_wp) array User 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.
12: iwsav(130) Integer array Communication Array
13: rwsav(32×n+350) Real (Kind=nag_wp) array Communication 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 Integer Input/Output
On entry: ifail must be set to 0, -1 or 1 to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of 0 causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of -1 means that an error message is printed while a value of 1 means that it is not.
If halting is not appropriate, the value -1 or 1 is recommended. If message printing is undesirable, then the value 1 is recommended. Otherwise, the value 0 is recommended. 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:
ifail=1
method=-3 or 3 in setup, but interpolation is not available for this method. Either use method=-2 or 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 or 2, lwcommn+max(n,5×nwant).
On entry, lwcomm=value.
Constraint: for method=-1 or 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.
ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
ifail=-399
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
ifail=-999
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

7 Accuracy

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

8 Parallelism and Performance

d02psf 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 routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

9 Further Comments

None.

10 Example

This example solves the equation
y = -y ,   y(0)=0,   y(0)=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−4 and tol=1.0E−5 in turn so that solutions may be compared.

10.1 Program Text

Program Text (d02psfe.f90)

10.2 Program Data

Program Data (d02psfe.d)

10.3 Program Results

Program Results (d02psfe.r)
GnuplotProduced by GNUPLOT 4.6 patchlevel 3 −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 gnuplot_plot_1 gnuplot_plot_2