d01 Chapter Contents
d01 Chapter Introduction
NAG C Library Manual

# NAG Library Function Documentnag_1d_quad_inf_wt_trig (d01asc)

## 1  Purpose

nag_1d_quad_inf_wt_trig (d01asc) calculates an approximation to the sine or the cosine transform of a function $g$ over $\left[a,\infty \right)$:
 $I = ∫ a ∞ g x sinωx dx or I = ∫ a ∞ g x cosωx dx$
(for a user-specified value of $\omega$).

## 2  Specification

 #include #include
 double (*g)(double x),
double a, double omega, Nag_TrigTransform wt_func, Integer maxintervals, Integer max_num_subint, double epsabs, double *result, double *abserr, Nag_QuadSubProgress *qpsub, NagError *fail)

## 3  Description

nag_1d_quad_inf_wt_trig (d01asc) is based upon the QUADPACK routine QAWFE (Piessens et al. (1983)). It is an adaptive function, designed to integrate a function of the form $g\left(x\right)w\left(x\right)$ over a semi-infinite interval, where $w\left(x\right)$ is either $\mathrm{sin}\left(\omega x\right)$ or $\mathrm{cos}\left(\omega x\right)$. Over successive intervals
 $C k = a + k-1 × c , a + k × c , k = 1 , 2 , … , qpsub→intervals$
integration is performed by the same algorithm as is used by nag_1d_quad_wt_trig (d01anc). The intervals ${C}_{k}$ are of constant length
 $c = 2 ω + 1 π / ω , ω ≠ 0 ,$
where $\left[\left|\omega \right|\right]$ represents the largest integer less than or equal to $\left|\omega \right|$. Since $c$ equals an odd number of half periods, the integral contributions over succeeding intervals will alternate in sign when the function $g$ is positive and monotonically decreasing over $\left[a,\infty \right)$. The algorithm, described by Piessens et al. (1983), incorporates a global acceptance criterion (as defined by Malcolm and Simpson (1976)) together with the $\epsilon$-algorithm (Wynn (1956)) to perform extrapolation. The local error estimation is described by Piessens et al. (1983).
If $\omega =0$ and ${\mathbf{wt_func}}=\mathrm{Nag_Cosine}$, the function uses the same algorithm as nag_1d_quad_inf (d01amc) (with ${\mathbf{epsrel}}=0.0$).
In contrast to most other functions in Chapter d01, nag_1d_quad_inf_wt_trig (d01asc) works only with a user-specified absolute error tolerance (epsabs). Over the interval ${C}_{k}$ it attempts to satisfy the absolute accuracy requirement
 $EPSA k = U k × epsabs ,$
where ${U}_{\mathit{k}}=\left(1-p\right){p}^{\mathit{k}-1}$, for $\mathit{k}=1,2,\dots$ and $p=0.9$.
However, when difficulties occur during the integration over the $k$th interval ${C}_{k}$ such that the error flag $\mathbf{qpsub}\mathbf{\to }\mathbf{interval_flag}\left[k-1\right]$ is nonzero, the accuracy requirement over subsequent intervals is relaxed. See Piessens et al. (1983) for more details.

## 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
Wynn P (1956) On a device for computing the ${e}_{m}\left({\mathrm{S}}_{n}\right)$ transformation Math. Tables Aids Comput. 10 91–96

## 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$.
On entry: the argument $\omega$ in the weight function of the transform.
4:     wt_funcNag_TrigTransformInput
On entry: indicates which integral is to be computed:
• if ${\mathbf{wt_func}}=\mathrm{Nag_Cosine}$, $w\left(x\right)=\mathrm{cos}\left(\omega x\right)$;
• if ${\mathbf{wt_func}}=\mathrm{Nag_Sine}$, $w\left(x\right)=\mathrm{sin}\left(\omega x\right)$.
Constraint: ${\mathbf{wt_func}}=\mathrm{Nag_Cosine}$ or $\mathrm{Nag_Sine}$.
5:     maxintervalsIntegerInput
On entry: an upper bound on the number of intervals ${C}_{k}$ needed for the integration.
Suggested value: ${\mathbf{maxintervals}}=50$ is adequate for most problems.
Constraint: ${\mathbf{maxintervals}}\ge 3$.
6:     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 1$.
7:     epsabsdoubleInput
On entry: the absolute accuracy required. If epsabs is negative, the absolute value is used. See Section 7.
8:     resultdouble *Output
On exit: the approximation to the integral $I$.
9:     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_QuadSubProgress with the following members:
intervalsIntegerOutput
On exit: the number of intervals ${C}_{k}$ actually used for the integration.
fun_countIntegerOutput
On exit: the number of function evaluations performed by nag_1d_quad_inf_wt_trig (d01asc).
subints_per_intervalIntegerOutput
On exit: the maximum number of sub-intervals actually used for integrating over any of the intervals ${C}_{k}$.
interval_errordouble *Output
On exit: the error estimate corresponding to the integral contribution over the interval ${C}_{k}$, for $\mathit{k}=1,2,\dots ,\mathbf{intervals}$.
interval_resultdouble *Output
On exit: the corresponding integral contribution over the interval ${C}_{\mathit{k}}$, for $\mathit{k}=1,2,\dots ,\mathbf{intervals}$.
interval_flagInteger *Output
On exit: the error flag corresponding to $\mathbf{interval_result}$, for $k=1,2,\dots ,\mathbf{intervals}$. See also Section 6.
When the information available in the arrays $\mathbf{interval_error}$, $\mathbf{interval_result}$ and $\mathbf{interval_flag}$ is no longer useful, or before a subsequent call to nag_1d_quad_inf_wt_trig (d01asc) with the same argument qpsub is made, you should free the storage contained in this pointer using the NAG macro NAG_FREE. Note that these arrays do not need to be freed if one of the error exits NE_INT_ARG_LT, NE_BAD_PARAM or NE_ALLOC_FAIL occurred.
11:   failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

## 6  Error Indicators and Warnings

In the cases where ${\mathbf{fail}}\mathbf{.}\mathbf{code}={\mathbf{NE_QUAD_BAD_SUBDIV_INT}}\text{, ​}{\mathbf{NE_QUAD_MAX_INT}}\text{​ or ​}{\mathbf{NE_QUAD_EXTRAPL_INT}}$, additional information about the cause of the error can be obtained from the array $\mathbf{qpsub}\mathbf{\to }\mathbf{interval_flag}$, as follows:
• $\mathbf{qpsub}\mathbf{\to }\mathbf{interval_flag}\left[k-1\right]=1$
• The maximum number of subdivisions $\left(={\mathbf{max_num_subint}}\right)$ has been achieved on the $k$th interval.
• $\mathbf{qpsub}\mathbf{\to }\mathbf{interval_flag}\left[k-1\right]=2$
• Occurrence of round-off error is detected and prevents the tolerance imposed on the $k$th interval from being achieved.
• $\mathbf{qpsub}\mathbf{\to }\mathbf{interval_flag}\left[k-1\right]=3$
• Extremely bad integrand behaviour occurs at some points of the $k$th interval.
• $\mathbf{qpsub}\mathbf{\to }\mathbf{interval_flag}\left[k-1\right]=4$
• The integration procedure over the $k$th interval does not converge (to within the required accuracy) due to round-off in the extrapolation procedure invoked on this interval. It is assumed that the result on this interval is the best which can be obtained.
• $\mathbf{qpsub}\mathbf{\to }\mathbf{interval_flag}\left[k-1\right]=5$
• The integral over the $k$th interval is probably divergent or slowly convergent. It must be noted that divergence can occur with any other value of $\mathbf{qpsub}\mathbf{\to }\mathbf{interval_flag}\left[k-1\right]$.
If users declare and initialize fail and set ${\mathbf{fail}}\mathbf{.}\mathbf{print}=\mathrm{Nag_TRUE}$ as recommended then
may be produced supplemented by messages indicating more precisely where problems were encountered by the function. However, if the default error handling, NAGERR_DEFAULT, is used then one of the following errors may occur. Please note the program will terminate when the first of such errors is detected.
NE_ALLOC_FAIL
Dynamic memory allocation failed.
On entry, argument wt_func had an illegal value.
NE_INT_ARG_LT
On entry, ${\mathbf{maxintervals}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{maxintervals}}\ge 3$.
On entry, max_num_subint must not be less than 1: ${\mathbf{max_num_subint}}=〈\mathit{\text{value}}〉$.
Bad integrand behaviour occurs at some points of the $〈\mathit{\text{value}}〉$ interval.
$\mathbf{qpsub}\mathbf{\to }\mathbf{interval_flag}\left[〈\mathit{\text{value}}〉\right]=〈\mathit{\text{value}}〉$ over sub-interval $\left(〈\mathit{\text{value}}〉,〈\mathit{\text{value}}〉\right)$.
Extremely bad integrand behaviour occurs around the sub-interval $\left(〈\mathit{\text{value}}〉,〈\mathit{\text{value}}〉\right)$.
Bad integration behaviour has occurred within one or more intervals.
The integral is probably divergent on the $〈\mathit{\text{value}}〉$ interval.
$\mathbf{qpsub}\mathbf{\to }\mathbf{interval_flag}\left[〈\mathit{\text{value}}〉\right]=〈\mathit{\text{value}}〉$ over sub-interval $\left(〈\mathit{\text{value}}〉,〈\mathit{\text{value}}〉\right)$.
The extrapolation table constructed for convergence acceleration of the series formed by the integral contribution over the integral does not converge.
Maximum number of intervals allowed has been achieved. Increase the value of maxintervals.
The maximum number of subdivisions has been reached: ${\mathbf{max_num_subint}}=〈\mathit{\text{value}}〉$.
The maximum number of subdivisions within an interval 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 this function on the infinite subrange and an appropriate integrator on the finite subrange. Alternatively, consider relaxing the accuracy requirements specified by epsabs or increasing the value of max_num_subint.
The maximum number of subdivisions has been reached,
${\mathbf{max_num_subint}}=〈\mathit{\text{value}}〉$ on the $〈\mathit{\text{value}}〉$ interval.
$\mathbf{qpsub}\mathbf{\to }\mathbf{interval_flag}\left[〈\mathit{\text{value}}〉\right]=〈\mathit{\text{value}}〉$ over sub-interval $\left(〈\mathit{\text{value}}〉,〈\mathit{\text{value}}〉\right)$.
The integral is probably divergent or slowly convergent.
Please note that divergence can also occur with any error exit other than NE_INT_ARG_LT, NE_BAD_PARAM or NE_ALLOC_FAIL.
The integral has failed to converge on the $〈\mathit{\text{value}}〉$ interval.
$\mathbf{qpsub}\mathbf{\to }\mathbf{interval_flag}\left[〈\mathit{\text{value}}〉\right]=〈\mathit{\text{value}}〉$ over sub-interval $\left(〈\mathit{\text{value}}〉,〈\mathit{\text{value}}〉\right)$.
Round-off error prevents the requested tolerance from being achieved: ${\mathbf{epsabs}}=〈\mathit{\text{value}}〉$.
The error may be underestimated. Consider relaxing the accuracy requirements specified by epsabs.
Round-off 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.
Round-off error prevents the requested tolerance from being achieved on the $〈\mathit{\text{value}}〉$ interval.
$\mathbf{qpsub}\mathbf{\to }\mathbf{interval_flag}\left[〈\mathit{\text{value}}〉\right]=〈\mathit{\text{value}}〉$ over sub-interval $\left(〈\mathit{\text{value}}〉,〈\mathit{\text{value}}〉\right)$.

## 7  Accuracy

nag_1d_quad_inf_wt_trig (d01asc) cannot guarantee, but in practice usually achieves, the following accuracy:
 $I - result ≤ epsabs$
where epsabs is the user-specified absolute error tolerance. Moreover it returns the quantity abserr which, in normal circumstances, satisfies
 $I - result ≤ abserr ≤ epsabs .$

The time taken by nag_1d_quad_inf_wt_trig (d01asc) depends on the integrand and on the accuracy required.

## 9  Example

This example computes
 $∫ 0 ∞ 1 x cos π x / 2 dx .$

### 9.1  Program Text

Program Text (d01asce.c)

None.

### 9.3  Program Results

Program Results (d01asce.r)