NAG CL Interface
d01skc (dim1_​osc)

Note: this function is deprecated and will be withdrawn at Mark 31.3. Replaced by d01rkc.
d01rkc requires the user-supplied function f to calculate a vector of abscissae at once for greater efficiency and returns additional information on the computation (in the arrays rinfo and iinfo rather than qp previously).
Settings help

CL Name Style:


1 Purpose

d01skc is an adaptive integrator, especially suited to oscillating, nonsingular integrands, which calculates an approximation to the integral of a function f (x) over a finite interval [a,b] :
I = a b f (x) dx .  

2 Specification

#include <nag.h>
void  d01skc (
double (*f)(double x, Nag_User *comm),
double a, double b, double epsabs, double epsrel, Integer max_num_subint, double *result, double *abserr, Nag_QuadProgress *qp, Nag_User *comm, NagError *fail)
The function may be called by the names: d01skc, nag_quad_dim1_osc or nag_1d_quad_osc_1.

3 Description

d01skc is based upon the QUADPACK routine QAG (Piessens et al. (1983)). It is an adaptive function, using the Gauss 30-point and Kronrod 61-point rules. A ‘global’ acceptance criterion (as defined by Malcolm and Simpson (1976)) is used. The local error estimation is described by Piessens et al. (1983).
As this function is based on integration rules of high order, it is especially suitable for nonsingular oscillating integrands.
This function requires you to supply a function to evaluate the integrand at a single point.

4 References

Malcolm M A and Simpson R B (1976) Local versus global strategies for adaptive quadrature ACM Trans. Math. Software 1 129–146
Piessens R (1973) An algorithm for automatic integration Angew. Inf. 15 399–401
Piessens R, de Doncker–Kapenga E, Überhuber C and Kahaner D (1983) QUADPACK, A Subroutine Package for Automatic Integration Springer–Verlag

5 Arguments

1: f function, supplied by the user External Function
f must return the value of the integrand f at a given point.
The specification of f is:
double  f (double x, Nag_User *comm)
1: x double Input
On entry: the point at which the integrand f must be evaluated.
2: comm Nag_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.)
Note: f should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by d01skc. If your code inadvertently does return any NaNs or infinities, d01skc is likely to produce unexpected results.
2: a double Input
On entry: the lower limit of integration, a .
3: b double Input
On entry: the upper limit of integration, b . It is not necessary that a<b .
4: epsabs double Input
On entry: the absolute accuracy required. If epsabs is negative, the absolute value is used. See Section 7.
5: epsrel double Input
On entry: the relative accuracy required. If epsrel is negative, the absolute value is used. See Section 7.
6: max_num_subint Integer Input
On entry: the upper bound on the number of sub-intervals into which the interval of integration may be divided by the function. The more difficult the integrand, the larger max_num_subint should be.
Constraint: max_num_subint1 .
7: result double * Output
On exit: the approximation to the integral I .
8: abserr double * Output
On exit: an estimate of the modulus of the absolute error, which should be an upper bound for |I-result| .
9: qp Nag_QuadProgress *
Pointer to structure of type Nag_QuadProgress with the following members:
num_subintIntegerOutput
On exit: the actual number of sub-intervals used.
fun_countIntegerOutput
On exit: the number of function evaluations performed by d01skc.
sub_int_beg_ptsdouble *Output
sub_int_end_ptsdouble *Output
sub_int_resultdouble *Output
sub_int_errordouble *Output
On exit: these pointers are allocated memory internally with max_num_subint elements. If an error exit other than NE_INT_ARG_LT or NE_ALLOC_FAIL occurs, these arrays will contain information which may be useful. For details, see Section 9.
Before a subsequent call to d01skc is made, or when the information contained in these arrays is no longer useful, you should free the storage allocated by these pointers using the NAG macro NAG_FREE.
10: comm Nag_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 is void *.
11: 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

NE_ALLOC_FAIL
Dynamic memory allocation failed.
NE_INT_ARG_LT
On entry, max_num_subint must not be less than 1: max_num_subint=value .
NE_QUAD_BAD_SUBDIV
Extremely bad integrand behaviour occurs around the sub-interval (value,value) .
The same advice applies as in the case of NE_QUAD_MAX_SUBDIV.
NE_QUAD_MAX_SUBDIV
The maximum number of subdivisions has been reached: max_num_subint=value .
The maximum number of subdivisions has been reached without the accuracy requirements being achieved. Look at the integrand in order to determine the integration difficulties. If the position of a local difficulty within the interval can be determined (e.g., a singularity of the integrand or its derivative, a peak, a discontinuity, etc.) you will probably gain from splitting up the interval at this point and calling the integrator on the sub-intervals. If necessary, another integrator, which is designed for handling the type of difficulty involved, must be used. Alternatively, consider relaxing the accuracy requirements specified by epsabs and epsrel, or increasing the value of max_num_subint.
NE_QUAD_ROUNDOFF_TOL
Round-off error prevents the requested tolerance from being achieved: epsabs=value , epsrel=value .
The error may be underestimated. Consider relaxing the accuracy requirements specified by epsabs and epsrel.

7 Accuracy

d01skc cannot guarantee, but in practice usually achieves, the following accuracy:
|I-result| tol  
where
tol = max{|epsabs|, |epsrel| × |I| }  
and epsabs and epsrel are user-specified absolute and relative error tolerances. Moreover it returns the quantity abserr which, in normal circumstances, satisfies
|I-result| abserr tol .  

8 Parallelism and Performance

Background information to multithreading can be found in the Multithreading documentation.
d01skc is not threaded in any implementation.

9 Further Comments

The time taken by d01skc depends on the integrand and the accuracy required.
If the function fails with an error exit other than NE_INT_ARG_LT or NE_ALLOC_FAIL, then you may wish to examine the contents of the structure qp. These contain the end-points of the sub-intervals used by d01skc along with the integral contributions and error estimates over these sub-intervals.
Specifically, i=1,2,,n, let r i denote the approximation to the value of the integral over the sub-interval [ a i , b i ] in the partition of [a,b] and e i be the corresponding absolute error estimate.
Then, a i b i f (x) dx r i and result = i=1 n r i . The value of n is returned in qpnum_subint, and the values a i , b i , r i and e i are stored in the structure qp as

10 Example

This example computes
0 2π sin(30x) cosx dx .  

10.1 Program Text

Program Text (d01skce.c)

10.2 Program Data

None.

10.3 Program Results

Program Results (d01skce.r)