NAG Library Function Document

nag_1d_quad_inf_wt_trig_1 (d01ssc)


    1  Purpose
    7  Accuracy


nag_1d_quad_inf_wt_trig_1 (d01ssc) calculates an approximation to the sine or the cosine transform of a function g  over a, :
I = a g x sinωx dx   or   I = a g x cosωx dx  
(for a user-specified value of ω ).


#include <nag.h>
#include <nagd01.h>
void  nag_1d_quad_inf_wt_trig_1 (
double (*g)(double x, Nag_User *comm),
double a, double omega, Nag_TrigTransform wt_func, Integer maxintervals, Integer max_num_subint, double epsabs, double *result, double *abserr, Nag_QuadSubProgress *qpsub, Nag_User *comm, NagError *fail)


nag_1d_quad_inf_wt_trig_1 (d01ssc) 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 x w x  over a semi-infinite interval, where w x  is either sinωx  or cosωx . Over successive intervals
C k = a + k-1 × c , a + k × c ,   k = 1 , 2 , , qpsubintervals  
integration is performed by the same algorithm as is used by nag_1d_quad_wt_trig_1 (d01snc). The intervals C k  are of constant length
c = 2 ω + 1 π / ω ,   ω 0 ,  
where ω  represents the largest integer less than or equal to ω . 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 a, . The algorithm, described by Piessens et al. (1983), incorporates a global acceptance criterion (as defined by Malcolm and Simpson (1976)) together with the ε -algorithm (Wynn (1956)) to perform extrapolation. The local error estimation is described by Piessens et al. (1983).
If ω=0  and wt_func=Nag_Cosine, the function uses the same algorithm as nag_1d_quad_inf_1 (d01smc) (with epsrel=0.0 ).
In contrast to most other functions in Chapter d01, nag_1d_quad_inf_wt_trig_1 (d01ssc) 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 k = 1-p p k-1 , for k = 1 , 2 ,  and p=0.9 .
However, when difficulties occur during the integration over the k th interval C k  such that the error flag qpsubinterval_flag[k-1]  is nonzero, the accuracy requirement over subsequent intervals is relaxed. See Piessens et al. (1983) for more details.


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 emSn transformation Math. Tables Aids Comput. 10 91–96


1:     g function, 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, Nag_User *comm)
1:     x doubleInput
On entry: the point at which the function g  must be evaluated.
2:     comm Nag_User *
Pointer to a structure of type Nag_User with the following member:
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: g should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by nag_1d_quad_inf_wt_trig_1 (d01ssc). If your code inadvertently does return any NaNs or infinities, nag_1d_quad_inf_wt_trig_1 (d01ssc) is likely to produce unexpected results.
2:     a doubleInput
On entry: the lower limit of integration, a .
3:     omega doubleInput
On entry: the argument ω  in the weight function of the transform.
4:     wt_func Nag_TrigTransformInput
On entry: indicates which integral is to be computed:
  • if wt_func=Nag_Cosine, w x = cosωx ;
  • if wt_func=Nag_Sine, w x = sinωx .
Constraint: wt_func=Nag_Cosine or Nag_Sine.
5:     maxintervals IntegerInput
On entry: an upper bound on the number of intervals C k  needed for the integration.
Suggested value: maxintervals=50  is adequate for most problems.
Constraint: maxintervals3 .
6:     max_num_subint IntegerInput
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:     epsabs doubleInput
On entry: the absolute accuracy required. If epsabs is negative, the absolute value is used. See Section 7.
8:     result double *Output
On exit: the approximation to the integral I .
9:     abserr double *Output
On exit: an estimate of the modulus of the absolute error, which should be an upper bound for I - result .
10:   qpsub Nag_QuadSubProgress *
Pointer to structure of type Nag_QuadSubProgress with the following members:
On exit: the number of intervals C k  actually used for the integration.
On exit: the number of function evaluations performed by nag_1d_quad_inf_wt_trig_1 (d01ssc).
subints_per_intervalInteger *Output
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 k = 1 , 2 , , intervals.
interval_resultdouble *Output
On exit: the corresponding integral contribution over the interval C k , for k=1,2,,intervals.
interval_flagInteger *Output
On exit: the error flag corresponding to interval_result, for k = 1 , 2 , , intervals. See also Section 6.
When the information available in the arrays interval_error, interval_result and interval_flag is no longer useful, or before a subsequent call to nag_1d_quad_inf_wt_trig_1 (d01ssc) 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:   comm Nag_User *
Pointer to a structure of type Nag_User with the following member:
On entry/exit: the pointer commp, of type Pointer, allows you to communicate information to and from g(). 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 *.
12:   fail NagError *Input/Output
The NAG error argument (see Section 3.7 in How to Use the NAG Library and its Documentation).

Error Indicators and Warnings

In the cases where fail.code=NE_QUAD_BAD_SUBDIV_INT , NE_QUAD_MAX_INT or NE_QUAD_EXTRAPL_INT, additional information about the cause of the error can be obtained from the array qpsubinterval_flag, as follows:
If you declare and initialize fail and set fail.print = Nag_TRUE as recommended then NE_QUAD_NO_CONV 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 NE_QUAD_MAX_SUBDIV_SPEC_INT, NE_QUAD_ROUNDOFF_TOL_SPEC_INT, NE_QUAD_BAD_SPEC_INT, NE_QUAD_NO_CONV_SPEC_INT and NE_QUAD_DIVERGENCE_SPEC_INT may occur. Please note the program will terminate when the first of such errors is detected.
Dynamic memory allocation failed.
On entry, argument wt_func had an illegal value.
On entry, maxintervals=value.
Constraint: maxintervals3.
On entry, max_num_subint must not be less than 1: max_num_subint=value .
Bad integrand behaviour occurs at some points of the value interval.
qpsubinterval_flag[value] = value over sub-interval value,value .
Extremely bad integrand behaviour occurs around the sub-interval value,value .
The same advice applies as in the case of NE_QUAD_MAX_SUBDIV.
Bad integration behaviour has occurred within one or more intervals.
The integral is probably divergent on the value interval.
qpsubinterval_flag[value] = value over sub-interval value,value .
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: max_num_subint=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,
max_num_subint=value  on the value interval.
qpsubinterval_flag[value] = value over sub-interval value,value .
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 value interval.
qpsubinterval_flag[value] = value over sub-interval value,value .
Round-off error prevents the requested tolerance from being achieved: epsabs=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.
The same advice applies as in the case of NE_QUAD_MAX_SUBDIV.
Round-off error prevents the requested tolerance from being achieved on the value interval.
qpsubinterval_flag[value] = value over sub-interval value,value .


nag_1d_quad_inf_wt_trig_1 (d01ssc) 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 .  

Parallelism and Performance

nag_1d_quad_inf_wt_trig_1 (d01ssc) is not threaded in any implementation.

Further Comments

The time taken by nag_1d_quad_inf_wt_trig_1 (d01ssc) depends on the integrand and on the accuracy required.


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

Program Text

Program Text (d01ssce.c)

Program Data


Program Results

Program Results (d01ssce.r)

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