NAG CL Interface
d02psc (ivp_​rkts_​interp)

Settings help

CL Name Style:

1 Purpose

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

2 Specification

#include <nag.h>
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.

3 Description

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=f(t,y)  given  y(t0)=y0  
where y is the vector of 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 method=Nag_RK_7_8 was specified in the call to setup function d02pqc.

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 function.
Constraint: n1.
2: twant double Input
On entry: t, the value of the independent variable where a solution is desired.
3: reqest Nag_SolDeriv Input
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: reqest=Nag_Sol, Nag_Der or Nag_SolDer.
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] double Output
On exit: an approximation to the first nwant components of the solution at twant if reqest=Nag_Sol or Nag_SolDer. Otherwise ywant is not defined.
6: ypwant[nwant] double Output
On exit: an approximation to the first nwant components of the first derivative at twant if reqest=Nag_Der or Nag_SolDer. Otherwise ypwant is not defined.
7: f function, supplied by the user External Function
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 d02pfc.
The specification of f is:
void  f (double t, Integer n, const double y[], double yp[], Nag_Comm *comm)
1: t double 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] const double Input
On entry: the current values of the dependent variables, yi, for i=1,2,,n.
4: yp[n] double Output
On exit: the values of fi, for i=1,2,,n.
5: comm Nag_Comm *
Pointer to structure of type Nag_Comm; the following members are relevant to f.
userdouble *
iuserInteger *
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: wcomm[lwcomm] double Communication Array
On entry: this array stores information that can be utilized on subsequent calls to d02psc.
9: lwcomm Integer Input
On entry: length of wcomm.
If in a previous call to d02pqc:
  • method=Nag_RK_2_3 then lwcomm must be at least 1.
  • method=Nag_RK_4_5 then lwcomm must be at least n+max(n,5×nwant).
  • method=Nag_RK_7_8 then wcomm and lwcomm are not referenced.
10: comm Nag_Comm *
The NAG communication argument (see Section 3.1.1 in the Introduction to the NAG Library CL Interface).
11: iwsav[130] Integer Communication Array
12: rwsav[32×n+350] 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: fail NagError * Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).

6 Error Indicators and Warnings

Dynamic memory allocation failed.
See Section 3.1.2 in the Introduction to the NAG Library CL Interface for further information.
On entry, argument value had an illegal value.
On entry, lwcomm=value.
Constraint: for method=Nag_RK_2_3, lwcomm1.
On entry, nwant=value and n=value.
Constraint: 1nwantn.
On entry, lwcomm=value, n=value and nwant=value.
Constraint: for method=Nag_RK_4_5, lwcommn+max(n,5×nwant).
On entry, n=value, but the value passed to the setup function was n=value.
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.
You cannot call this function before you have called the step integrator.
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.
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.
You cannot call this function after the integrator has returned an error.
You cannot call this function when you have specified, in the setup function, that the range integrator will be used.
method=Nag_RK_7_8 in setup, but interpolation is not available for this method. Either use method=Nag_RK_4_5 in setup or use reset function to force the integrator to step to particular points.

7 Accuracy

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

8 Parallelism 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.

9 Further Comments


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. 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 π/8 across the range whenever these points lie in one of those integration steps. A low order Runge–Kutta method (method=Nag_RK_2_3) 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 (d02psce.c)

10.2 Program Data

Program Data (d02psce.d)

10.3 Program Results

Program Results (d02psce.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