NAG Library Function Document

nag_1d_quad_wt_trig_1 (d01snc)


    1  Purpose
    7  Accuracy


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


#include <nag.h>
#include <nagd01.h>
void  nag_1d_quad_wt_trig_1 (
double (*g)(double x, Nag_User *comm),
double a, double b, double omega, Nag_TrigTransform wt_func, double epsabs, double epsrel, Integer max_num_subint, double *result, double *abserr, Nag_QuadProgress *qp, Nag_User *comm, NagError *fail)


nag_1d_quad_wt_trig_1 (d01snc) is based upon the QUADPACK routine QFOUR (Piessens et al. (1983)). It is an adaptive function, designed to integrate a function of the form g x w x , where w x  is either sinωx  or cosωx . If a sub-interval has length
L = b-a 2 -l  
then the integration over this sub-interval is performed by means of a modified Clenshaw–Curtis procedure (Piessens and Branders (1975)) if L ω > 4  and l20 . In this case a Chebyshev series approximation of degree 24 is used to approximate g x , while an error estimate is computed from this approximation together with that obtained using Chebyshev series of degree 12. If the above conditions do not hold then Gauss 7-point and Kronrod 15-point rules are used. The algorithm, described in Piessens et al. (1983), incorporates a global acceptance criterion (as defined in Malcolm and Simpson (1976)) together with the ε -algorithm (Wynn (1956)) to perform extrapolation. The local error estimation is described in Piessens et al. (1983).


Malcolm M A and Simpson R B (1976) Local versus global strategies for adaptive quadrature ACM Trans. Math. Software 1 129–146
Piessens R and Branders M (1975) Algorithm 002: computation of oscillating integrals J. Comput. Appl. Math. 1 153–164
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_wt_trig_1 (d01snc). If your code inadvertently does return any NaNs or infinities, nag_1d_quad_wt_trig_1 (d01snc) is likely to produce unexpected results.
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:     omega doubleInput
On entry: the argument ω  in the weight function of the transform.
5:     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.
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 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 .
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 I - result .
11:   qp Nag_QuadProgress *
Pointer to structure of type Nag_QuadProgress with the following members:
On exit: the actual number of sub-intervals used.
On exit: the number of function evaluations performed by nag_1d_quad_wt_trig_1 (d01snc).
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 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_wt_trig_1 (d01snc) 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:
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 *.
13:   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

Dynamic memory allocation failed.
On entry, argument wt_func had an illegal value.
On entry, max_num_subint must not be less than 1: max_num_subint=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.
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.
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.
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: epsabs=value , epsrel=value .
The error may be underestimated. Consider relaxing the accuracy requirements specified by epsabs and epsrel.


nag_1d_quad_wt_trig_1 (d01snc) cannot guarantee, but in practice usually achieves, the following accuracy:
I - result tol  
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 .  

Parallelism and Performance

nag_1d_quad_wt_trig_1 (d01snc) is not threaded in any implementation.

Further Comments

The time taken by tnag_1d_quad_wt_trig_1 (d01snc) 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 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_trig_1 (d01snc) along with the integral contributions and error estimates over the 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 g x w x dx r i  and result = 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 qpnum_subint, and the values a i , b i , r i  and e i  are stored in the structure qp as


This example computes
0 1 lnx sin10πx dx .  

Program Text

Program Text (d01snce.c)

Program Data


Program Results

Program Results (d01snce.r)

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