d01 Chapter Contents
d01 Chapter Introduction
NAG C Library Manual

# NAG Library Function Documentnag_1d_quad_wt_alglog (d01apc)

## 1  Purpose

nag_1d_quad_wt_alglog (d01apc) is an adaptive integrator which calculates an approximation to the integral of a function $g\left(x\right)w\left(x\right)$ over a finite interval $\left[a,b\right]$:
 $I = ∫ a b g x w x dx$
where the weight function $w$ has end-point singularities of algebraico-logarithmic type.

## 2  Specification

 #include #include
 double (*g)(double x),
double a, double b, double alfa, double beta, Nag_QuadWeight wt_func, double epsabs, double epsrel, Integer max_num_subint, double *result, double *abserr, Nag_QuadProgress *qp, NagError *fail)

## 3  Description

nag_1d_quad_wt_alglog (d01apc) is based upon the QUADPACK routine QAWSE (Piessens et al. (1983)) and integrates a function of the form $g\left(x\right)w\left(x\right)$, where the weight function $w\left(x\right)$ may have algebraico-logarithmic singularities at the end-points $a$ and/or $b$. The strategy is a modification of that in nag_1d_quad_osc (d01akc). We start by bisecting the original interval and applying modified Clenshaw–Curtis integration of orders 12 and 24 to both halves. Clenshaw–Curtis integration is then used on all sub-intervals which have $a$ or $b$ as one of their end-points (Piessens et al. (1974)). On the other sub-intervals Gauss–Kronrod (7–15 point) integration is carried out.
A ‘global’ acceptance criterion (as defined by Malcolm and Simpson (1976)) is used. The local error estimation control is described by Piessens et al. (1983).

## 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, de Doncker–Kapenga E, Überhuber C and Kahaner D (1983) QUADPACK, A Subroutine Package for Automatic Integration Springer–Verlag
Piessens R, Mertens I and Branders M (1974) Integration of functions having end-point singularities Angew. Inf. 16 65–68

## 5  Arguments

1:     gfunction, supplied by the userExternal Function
g must return the value of the function $g$ at a given point.
The specification of g is:
 double g (double x)
1:     xdoubleInput
On entry: the point at which the function $g$ must be evaluated.
On entry: the lower limit of integration, $a$.
3:     bdoubleInput
On entry: the upper limit of integration, $b$.
Constraint: ${\mathbf{b}}>{\mathbf{a}}$.
On entry: the argument $\alpha$ in the weight function.
Constraint: ${\mathbf{alfa}}>-1.0$.
On entry: the argument $\beta$ in the weight function.
Constraint: ${\mathbf{beta}}>-1.0$.
On entry: indicates which weight function is to be used:
• if ${\mathbf{wt_func}}=\mathrm{Nag_Alg}$, $w\left(x\right)={\left(x-a\right)}^{\alpha }{\left(b-x\right)}^{\beta }$;
• if ${\mathbf{wt_func}}=\mathrm{Nag_Alg_loga}$, $w\left(x\right)={\left(x-a\right)}^{\alpha }{\left(b-x\right)}^{\beta }ln\left(x-a\right)$;
• if ${\mathbf{wt_func}}=\mathrm{Nag_Alg_logb}$, $w\left(x\right)={\left(x-a\right)}^{\alpha }{\left(b-x\right)}^{\beta }ln\left(b-x\right)$;
• if ${\mathbf{wt_func}}=\mathrm{Nag_Alg_loga_logb}$, $w\left(x\right)={\left(x-a\right)}^{\alpha }{\left(b-x\right)}^{\beta }ln\left(x-a\right)ln\left(b-x\right)$.
Constraint: ${\mathbf{wt_func}}=\mathrm{Nag_Alg}$, $\mathrm{Nag_Alg_loga}$, $\mathrm{Nag_Alg_logb}$ or $\mathrm{Nag_Alg_loga_logb}$.
7:     epsabsdoubleInput
On entry: the absolute accuracy required. If epsabs is negative, the absolute value is used. See Section 7.
8:     epsreldoubleInput
On entry: the relative accuracy required. If epsrel is negative, the absolute value is used. See Section 7.
9:     max_num_subintIntegerInput
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: ${\mathbf{max_num_subint}}\ge 2$.
10:   resultdouble *Output
On exit: the approximation to the integral $I$.
11:   abserrdouble *Output
On exit: an estimate of the modulus of the absolute error, which should be an upper bound for $\left|I-{\mathbf{result}}\right|$.
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 nag_1d_quad_wt_alglog (d01apc).
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, NE_BAD_PARAM, NE_REAL_ARG_LE, NE_2_REAL_ARG_LE or NE_ALLOC_FAIL occurs, these arrays will contain information which may be useful. For details, see Section 8.
Before a subsequent call to nag_1d_quad_wt_alglog (d01apc) 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.
13:   failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

## 6  Error Indicators and Warnings

NE_2_REAL_ARG_LE
On entry, ${\mathbf{b}}=〈\mathit{\text{value}}〉$ while ${\mathbf{a}}=〈\mathit{\text{value}}〉$. These arguments must satisfy ${\mathbf{b}}>{\mathbf{a}}$.
NE_ALLOC_FAIL
Dynamic memory allocation failed.
On entry, argument wt_func had an illegal value.
NE_INT_ARG_LT
On entry, max_num_subint must not be less than 2: ${\mathbf{max_num_subint}}=〈\mathit{\text{value}}〉$.
Extremely bad integrand behaviour occurs around the sub-interval $\left(〈\mathit{\text{value}}〉,〈\mathit{\text{value}}〉\right)$.
The maximum number of subdivisions has been reached: ${\mathbf{max_num_subint}}=〈\mathit{\text{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 discontinuity or a singularity of algebraico-logarithmic type within the interval can be determined, the interval must be split up at this point and the integrator called 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.
Round-off error prevents the requested tolerance from being achieved: ${\mathbf{epsabs}}=〈\mathit{\text{value}}〉$, ${\mathbf{epsrel}}=〈\mathit{\text{value}}〉$.
The error may be underestimated. Consider relaxing the accuracy requirements specified by epsabs and epsrel.
NE_REAL_ARG_LE
On entry, ${\mathbf{alfa}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{alfa}}\le -1.0$.
On entry, ${\mathbf{beta}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{beta}}\le -1.0$.

## 7  Accuracy

nag_1d_quad_wt_alglog (d01apc) 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 .$

The time taken by nag_1d_quad_wt_alglog (d01apc) depends on the integrand and the accuracy required.
If the function fails with an error exit other than NE_INT_ARG_LT, NE_BAD_PARAM, NE_REAL_ARG_LE, NE_2_REAL_ARG_LE 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 nag_1d_quad_wt_alglog (d01apc) along with the integral contributions and error estimates over these sub-intervals.
Specifically, for $i=1,2,\dots ,n$, let ${r}_{i}$ denote the approximation to the value of the integral over the sub-interval $\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}}g\left(x\right)w\left(x\right)dx\simeq {r}_{i}$ and ${\mathbf{result}}={\sum }_{i=1}^{n}{r}_{i}$. 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[i-1\right]$,
• ${b}_{i}=\mathbf{qp}\mathbf{\to }\mathbf{sub_int_end_pts}\left[i-1\right]$,
• ${r}_{i}=\mathbf{qp}\mathbf{\to }\mathbf{sub_int_result}\left[i-1\right]$ and
• ${e}_{i}=\mathbf{qp}\mathbf{\to }\mathbf{sub_int_error}\left[i-1\right]$.

## 9  Example

This example computes
 $∫ 0 1 ln⁡x cos10πx dx$
and
 $∫ 0 1 sin10x x 1-x dx .$

### 9.1  Program Text

Program Text (d01apce.c)

None.

### 9.3  Program Results

Program Results (d01apce.r)