nag_ode_ivp_rk_interp (d02pxc) (PDF version)
d02 Chapter Contents
d02 Chapter Introduction
NAG Library Manual

NAG Library Function Document

nag_ode_ivp_rk_interp (d02pxc)

+ Contents

    1  Purpose
    7  Accuracy

1  Purpose

nag_ode_ivp_rk_interp (d02pxc) is a function to compute the solution of a system of ordinary differential equations using interpolation anywhere on an integration step taken by nag_ode_ivp_rk_onestep (d02pdc).

2  Specification

#include <nag.h>
#include <nagd02.h>
void  nag_ode_ivp_rk_interp (Integer neq, double twant, Nag_SolDeriv request, Integer nwant, double ywant[], double ypwant[],
void (*f)(Integer neq, double t, const double y[], double yp[], Nag_User *comm),
Nag_ODE_RK *opt, Nag_User *comm, NagError *fail)

3  Description

nag_ode_ivp_rk_interp (d02pxc) and its associated functions (nag_ode_ivp_rk_setup (d02pvc), nag_ode_ivp_rk_onestep (d02pdc), nag_ode_ivp_rk_reset_tend (d02pwc), nag_ode_ivp_rk_errass (d02pzc) ) 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 (Brankin et al. (1991)) integrate
y = f t,y  given  y t 0 = y 0
where y  is the vector of neq solution components and t  is the independent variable.
nag_ode_ivp_rk_onestep (d02pdc) computes the solution at the end of an integration step. Using the information computed on that step nag_ode_ivp_rk_interp (d02pxc) 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 nag_ode_ivp_rk_setup (d02pvc).

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:     neqIntegerInput
On entry: the number of ordinary differential equations in the system.
Constraint: neq1 .
2:     twantdoubleInput
On entry: the value of the independent variable, t , where a solution is desired.
3:     requestNag_SolDerivInput
On entry: determines whether the solution and/or its first derivative are computed as follows:
  • request=Nag_Sol – compute approximate solution only;
  • request=Nag_Der – compute approximate first derivative of the solution only;
  • request=Nag_SolDer – compute both approximate solution and first derivative.
Constraint: request=Nag_Sol, Nag_Der or Nag_SolDer.
4:     nwantIntegerInput
On entry: the number of components of the solution to be computed. The first nwant components are evaluated.
Constraint: 1 nwant neq .
5:     ywant[nwant]doubleOutput
On exit: an approximation to the first nwant components of the solution at twant when specified by request.
6:     ypwant[nwant]doubleOutput
On exit: an approximation to the first nwant components of the first derivative of the solution at twant when specified by request.
7:     ffunction, supplied by the userExternal Function
f must evaluate the functions f i  (that is the first derivatives y i ) for given values of the arguments t , y i . It must be the same procedure as supplied to nag_ode_ivp_rk_onestep (d02pdc).
The specification of f is:
void  f (Integer neq, double t, const double y[], double yp[], Nag_User *comm)
1:     neqIntegerInput
On entry: the number of differential equations.
2:     tdoubleInput
On entry: the current value of the independent variable, t.
3:     y[neq]const doubleInput
On entry: the current values of the dependent variables, y i  for i = 1 , 2 , , neq .
4:     yp[neq]doubleOutput
On exit: the values of f i  for i = 1 , 2 , , neq .
5:     commNag_User *
Pointer to a structure of type Nag_User with the following member:
pPointer 
On entry/exit: the pointer commp  should be cast to the required type, e.g., struct user *s = (struct user *)comm → p, to obtain the original object's address with appropriate type. (See the argument comm below.)
8:     optNag_ODE_RK *Input/Output
On entry: the structure of type Nag_ODE_RK as output from nag_ode_ivp_rk_onestep (d02pdc). You must not change this structure.
On exit: some members of opt are changed internally.
9:     commNag_User *
Pointer to a structure of type Nag_User with the following member:
pPointer 
On entry/exit: the pointer commp, of type Pointer, allows you to communicate information to and from f. An object of the required type should be declared, e.g., a structure, and its address assigned to the pointer commp by means of a cast to Pointer in the calling program, e.g., comm.p = (Pointer)&s. The type pointer will be void * with a C compiler that defines void * and char * otherwise.
10:   failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

6  Error Indicators and Warnings

NE_2_INT_ARG_GT
On entry, nwant=value  while neq=value . These arguments must satisfy neqnwant .
NE_ALLOC_FAIL
Dynamic memory allocation failed.
NE_BAD_PARAM
On entry, argument request had an illegal value.
NE_INT_ARG_LT
On entry, nwant=value.
Constraint: nwant1.
NE_MEMORY_FREED
Internally allocated memory has been freed by a call to nag_ode_ivp_rk_free (d02ppc) without a subsequent call to the setup function nag_ode_ivp_rk_setup (d02pvc).
NE_MISSING_CALL
Previous call to nag_ode_ivp_rk_onestep (d02pdc) has not been made, hence nag_ode_ivp_rk_interp (d02pxc) must not be called.
NE_NEQ
The value of neq supplied is not the same as that given to the setup function nag_ode_ivp_rk_setup (d02pvc). neq=value  but the value given to nag_ode_ivp_rk_setup (d02pvc) was value.
NE_PREV_CALL
The previous call to a function had resulted in a severe error. You must call nag_ode_ivp_rk_setup (d02pvc) to start another problem.
NE_PREV_CALL_INI
The previous call to the function nag_ode_ivp_rk_onestep (d02pdc) resulted in a severe error. You must call nag_ode_ivp_rk_setup (d02pvc) to start another problem.
NE_RK_INVALID_CALL
The function to be called as specified in the setup function nag_ode_ivp_rk_setup (d02pvc) was nag_ode_ivp_rk_range (d02pcc). However the actual call was made to nag_ode_ivp_rk_interp (d02pxc). This is not permitted.
NE_RK_PX_METHOD
Interpolation is not available with method=Nag_RK_7_8. Either use method=Nag_RK_2_3 or Nag_RK_4_5 for which interpolation is available. Alternatively use nag_ode_ivp_rk_reset_tend (d02pwc) to make nag_ode_ivp_rk_onestep (d02pdc) step exactly to the points where you want output.

7  Accuracy

The computed values will be of a similar accuracy to that computed by nag_ode_ivp_rk_onestep (d02pdc).

8  Parallelism and Performance

Not applicable.

9  Further Comments

None.

10  Example

We solve the equation
y = -y ,   y 0 = 0 , y 0 = 1
reposed as
y 1 = y 2 y 2 = - y 1
over the range 0,2π  with initial conditions y 1 = 0.0  and y 2 = 1.0 . We use relative error control with threshold values of 1.0e−8  for each solution component. nag_ode_ivp_rk_onestep (d02pdc) is used to integrate the problem one step at a time and nag_ode_ivp_rk_interp (d02pxc) 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. We use a moderate order Runge–Kutta method (method=Nag_RK_4_5) with tolerances tol = 1.0e−3  and tol = 1.0e−4  in turn so that we may compare the solutions. The value of π  is obtained by using nag_pi (X01AAC).

10.1  Program Text

Program Text (d02pxce.c)

10.2  Program Data

None.

10.3  Program Results

Program Results (d02pxce.r)


nag_ode_ivp_rk_interp (d02pxc) (PDF version)
d02 Chapter Contents
d02 Chapter Introduction
NAG Library Manual

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