NAG Library Function Document
nag_1d_quad_brkpts_1 (d01slc)
1 Purpose
nag_1d_quad_brkpts_1 (d01slc) is a general purpose integrator which calculates an approximation to the integral of a function
$f\left(x\right)$ over a finite interval
$\left[a,b\right]$:
where the integrand may have local singular behaviour at a finite number of points within the integration interval.
2 Specification
#include <nag.h> 
#include <nagd01.h> 
void 
nag_1d_quad_brkpts_1 (
double 
(*f)(double x,
Nag_User *comm),


double a,
double b,
Integer nbrkpts,
const double brkpts[],
double epsabs,
double epsrel,
Integer max_num_subint,
double *result,
double *abserr,
Nag_QuadProgress *qp,
Nag_User *comm,
NagError *fail) 

3 Description
nag_1d_quad_brkpts_1 (d01slc) is based upon the QUADPACK routine QAGP (
Piessens et al. (1983)). It is very similar to
nag_1d_quad_gen_1 (d01sjc), but allows you to supply ‘breakpoints’, points at which the function is known to be difficult. It is an adaptive function, using the Gauss 10point and Kronrod 21point rules. The algorithm described by
de Doncker (1978), incorporates a global acceptance criterion (as defined by
Malcolm and Simpson (1976)) together with the
$\epsilon $algorithm (
Wynn (1956)) to perform extrapolation. The usersupplied ‘breakpoints’ always occur as the endpoints of some subinterval during the adaptive process. The local error estimation is described by
Piessens et al. (1983).
4 References
de Doncker E (1978) An adaptive extrapolation algorithm for automatic integration ACM SIGNUM Newsl. 13(2) 12–18
Malcolm M A and Simpson R B (1976) Local versus global strategies for adaptive quadrature ACM Trans. Math. Software 1 129–146
Piessens R, de Doncker–Kapenga E, Überhuber C and Kahaner D (1983) QUADPACK, A Subroutine Package for Automatic Integration Springer–Verlag
Wynn P (1956) On a device for computing the ${e}_{m}\left({S}_{n}\right)$ transformation Math. Tables Aids Comput. 10 91–96
5 Arguments
 1:
f – function, supplied by the userExternal 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 – doubleInput

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:
 p – Pointer

On entry/exit: the pointer
$\mathbf{comm}\mathbf{\to}\mathbf{p}$ 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.)
 2:
a – doubleInput

On entry: the lower limit of integration, $a$.
 3:
b – doubleInput

On entry: the upper limit of integration, $b$. It is not necessary that $a<b$.
 4:
nbrkpts – IntegerInput
On entry: the number of usersupplied breakpoints within the integration interval.
Constraint:
${\mathbf{nbrkpts}}\ge 0$.
 5:
brkpts[nbrkpts] – const doubleInput

On entry: the userspecified breakpoints.
Constraint:
the breakpoints must all lie within the interval of integration (but may be supplied in any order).
 6:
epsabs – doubleInput

On entry: the absolute accuracy required. If
epsabs is negative, the absolute value is used. See
Section 7.
 7:
epsrel – doubleInput

On entry: the relative accuracy required. If
epsrel is negative, the absolute value is used. See
Section 7.
 8:
max_num_subint – IntegerInput

On entry: the upper bound on the number of subintervals 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:
${\mathbf{max\_num\_subint}}\ge 1$.
 9:
result – double *Output

On exit: the approximation to the integral $I$.
 10:
abserr – double *Output

On exit: an estimate of the modulus of the absolute error, which should be an upper bound for $\leftI{\mathbf{result}}\right$.
 11:
qp – Nag_QuadProgress *

Pointer to structure of type Nag_QuadProgress with the following members:
 num_subint – IntegerOutput

On exit: the actual number of subintervals used.
 fun_count – IntegerOutput

On exit: the number of function evaluations performed by nag_1d_quad_brkpts_1 (d01slc).
 sub_int_beg_pts – double *Output
 sub_int_end_pts – double *Output
 sub_int_result – double *Output
 sub_int_error – double *Output

On exit: these pointers are allocated memory internally with
max_num_subint elements. If an error exit other than
NE_INT_ARG_LT,
NE_2_INT_ARG_LE or
NE_ALLOC_FAIL occurs, these arrays will contain information which may be useful. For details, see
Section 9.
Before a subsequent call to nag_1d_quad_brkpts_1 (d01slc) 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.
 12:
comm – Nag_User *

Pointer to a structure of type Nag_User with the following member:
 p – Pointer

On entry/exit: the pointer
$\mathbf{comm}\mathbf{\to}\mathbf{p}$, 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
$\mathbf{comm}\mathbf{\to}\mathbf{p}$ by means of a cast to Pointer in the calling program, e.g.,
comm.p = (Pointer)&s. The type Pointer is
void *.
 13:
fail – NagError *Input/Output

The NAG error argument (see
Section 3.6 in the Essential Introduction).
6 Error Indicators and Warnings
 NE_2_INT_ARG_LE

On entry, ${\mathbf{max\_num\_subint}}=\u27e8\mathit{\text{value}}\u27e9$ while ${\mathbf{nbrkpts}}=\u27e8\mathit{\text{value}}\u27e9$. These arguments must satisfy ${\mathbf{max\_num\_subint}}>{\mathbf{nbrkpts}}$.
 NE_ALLOC_FAIL

Dynamic memory allocation failed.
 NE_INT_ARG_LT

On entry,
max_num_subint must not be less than 1:
${\mathbf{max\_num\_subint}}=\u27e8\mathit{\text{value}}\u27e9$.
On entry, ${\mathbf{nbrkpts}}=\u27e8\mathit{\text{value}}\u27e9$.
Constraint: ${\mathbf{nbrkpts}}\ge 0$.
 NE_QUAD_BAD_SUBDIV

Extremely bad integrand behaviour occurs around the subinterval
$\left(\u27e8\mathit{\text{value}}\u27e9,\u27e8\mathit{\text{value}}\u27e9\right)$.
The same advice applies as in the case of
NE_QUAD_MAX_SUBDIV.
 NE_QUAD_BRKPTS_INVAL

On entry, breakpoints outside (
a,
b):
${\mathbf{a}}=\u27e8\mathit{\text{value}}\u27e9$,
${\mathbf{b}}=\u27e8\mathit{\text{value}}\u27e9$.
 NE_QUAD_MAX_SUBDIV

The maximum number of subdivisions has been reached: ${\mathbf{max\_num\_subint}}=\u27e8\mathit{\text{value}}\u27e9$.
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 subintervals. 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_NO_CONV

The integral is probably divergent, or slowly convergent.
Please note that divergence can occur with any error exit other than
NE_INT_ARG_LT,
NE_2_INT_ARG_LE and
NE_ALLOC_FAIL.

Roundoff error is detected during extrapolation.
The requested tolerance cannot be achieved, because the extrapolation does not increase the accuracy satisfactorily; the returned result is the best that can be obtained.
The same advice applies as in the case of
NE_QUAD_MAX_SUBDIV.
 NE_QUAD_ROUNDOFF_TOL

Roundoff error prevents the requested tolerance from being achieved:
${\mathbf{epsabs}}=\u27e8\mathit{\text{value}}\u27e9$,
${\mathbf{epsrel}}=\u27e8\mathit{\text{value}}\u27e9$.
The error may be underestimated. Consider relaxing the accuracy requirements specified by
epsabs and
epsrel.
7 Accuracy
nag_1d_quad_brkpts_1 (d01slc) cannot guarantee, but in practice usually achieves, the following accuracy:
where
and
epsabs and
epsrel are userspecified absolute and relative error tolerances. Moreover it returns the quantity
abserr which, in normal circumstances, satisfies
8 Parallelism and Performance
Not applicable.
The time taken by nag_1d_quad_brkpts_1 (d01slc) depends on the integrand and the accuracy required.
If the function fails with an error exit other than
NE_INT_ARG_LT,
NE_2_INT_ARG_LE or
NE_ALLOC_FAIL, then you may wish to examine the contents of the structure
qp. These contain the endpoints of the subintervals used by nag_1d_quad_brkpts_1 (d01slc) along with the integral contributions and error estimates over the subintervals.
Specifically, $i=1,2,\dots n$, let ${r}_{i}$ denote the approximation to the value of the integral over the subinterval $\left[{a}_{i},{b}_{i}\right]$ in the partition of $\left[a,b\right]$ and ${e}_{i}$ be the corresponding absolute error estimate.
Then,
${\int}_{{a}_{i}}^{{b}_{i}}f\left(x\right)dx\simeq {r}_{i}$ and
${\mathbf{result}}={\sum}_{i=1}^{n}{r}_{i}$ unless the function terminates while testing for divergence of the integral (see Section 3.4.3 of
Piessens et al. (1983)). In this case,
result (and
abserr) are taken to be the values returned from the extrapolation process. The value of
$n$ is returned in
$\mathbf{qp}\mathbf{\to}\mathbf{num\_subint}$, and the values
${a}_{i}$,
${b}_{i}$,
${r}_{i}$ and
${e}_{i}$ are stored in the structure
qp as
 ${a}_{i}=\mathbf{qp}\mathbf{\to}\mathbf{sub\_int\_beg\_pts}\left[i1\right]$,
 ${b}_{i}=\mathbf{qp}\mathbf{\to}\mathbf{sub\_int\_end\_pts}\left[i1\right]$,
 ${r}_{i}=\mathbf{qp}\mathbf{\to}\mathbf{sub\_int\_result}\left[i1\right]$ and
 ${e}_{i}=\mathbf{qp}\mathbf{\to}\mathbf{sub\_int\_error}\left[i1\right]$.
10 Example
10.1 Program Text
Program Text (d01slce.c)
10.2 Program Data
None.
10.3 Program Results
Program Results (d01slce.r)