Chapter 4: Quadrature

.p>.CMCH4.DOC!INT_FCN;int_fcn

Integrates a function using a globally adaptive scheme based on Gauss-Kronrod rules.

Synopsis

#include <imsl.h>

float imsl_f_int_fcn (float fcn(), float a, float b, ¼, 0)

The type double function is imsl_d_int_fcn.

Required Arguments

float fcn (float x)   (Input)
User-supplied function to be integrated.

float a   (Input)
Lower limit of integration.

float b   (Input)
Upper limit of integration.

Return Value

The value of

is returned. If no value can be computed, then NaN is returned.

Synopsis with Optional Arguments

#include <imsl.h>

float imsl_f_int_fcn (float fcn(float x), float a, float b,
IMSL_RULE, int rule,
IMSL_ERR_ABS, float err_abs,
IMSL_ERR_REL, float err_rel,
IMSL_ERR_EST, float *err_est,
IMSL_MAX_SUBINTER, int max_subinter,
IMSL_N_SUBINTER, int *n_subinter,
IMSL_N_EVALS, int *n_evals,
IMSL_FCN_W_DATA, float fcn(), void *data,
0)

Optional Arguments

IMSL_RULE, int rule   (Input)
Choice of quadrature rule.

rule

Gauss-Kronrod Rule

1

  7-15 points

2

10-21 points

3

15-31 points

4

20-41 points

5

25-51 points

6

30-61 points

Default: rule = 1

IMSL_ERR_ABS, float err_abs   (Input)
Absolute accuracy desired.
Default:

where ɛ is the machine precision

IMSL_ERR_REL, float err_rel   (Input)
Relative accuracy desired.
Default:

where ɛ is the machine precision

IMSL_ERR_EST, float *err_est   (Output)
Address to store an estimate of the absolute value of the error.

IMSL_MAX_SUBINTER, int max_subinter   (Input)
Number of subintervals allowed.
Default: max_subinter = 500

IMSL_N_SUBINTER, int *n_subinter   (Output)
Address to store the number of subintervals generated.

IMSL_N_EVALS, int *n_evals   (Output)
Address to store the number of evaluations of fcn.

IMSL_FCN_W_DATA, float fcn (float x, void *data), void *data (Input)
User supplied function to be integrated, which also accepts a pointer to data that is supplied by the user.  data is a pointer to the data to be passed to the user-supplied function.  See the Introduction, Passing Data to User-Supplied Functions at the beginning of this manual for more details.

Description

The function imsl_f_int_fcn is a general-purpose integrator that uses a globally adaptive scheme to reduce the absolute error. It subdivides the interval [a, b] and uses a (2k + 1)-point Gauss-Kronrod rule to estimate the integral over each subinterval. The error for each subinterval is estimated by comparison with the k-point Gauss quadrature rule. The subinterval with the largest estimated error is then bisected, and the same procedure is applied to both halves. The bisection process is continued until either the error criterion is satisfied, roundoff error is detected, the subintervals become too small, or the maximum number of subintervals allowed is reached. The function imsl_f_int_fcn is based on the subroutine QAG by Piessens et al. (1983).

Should imsl_f_int_fcn fail to produce acceptable results, consider one of the more specialized functions documented in this chaptersection.

Examples

Example 1

The value of

is computed. Since the integrand is not oscillatory, all of the default values are used. The values of the actual and estimated error are machine dependent.

#include <math.h>
#include <imsl.h>

float           fcn(float x);
float           q;
float           exact;

 main()
{
                    /* evaluate the integral */
    q = imsl_f_int_fcn (fcn, 0.0, 2.0, 0);
                    /* print the result and the exact answer */
    exact = exp(2.0) + 1.0;
    printf("integral  = %10.3f\nexact     = %10.3f\n", q, exact);
}

float fcn(float x)
{  
    float y;
    y =  x *  (exp(x));
    return y;
}

Output

integral  =      8.389
exact     =      8.389

Example 2

The value of

is computed. Since the integrand is oscillatory, rule = 6 is used. The exact value is 0.50406706. The values of the actual and estimated error are machine dependent.

#include <math.h>
#include <imsl.h>

float           fcn(float x);

main()
{
float           q, err_est, err_abs= 0.0001, exact = 0.50406706, error;

                    /* intergrate fcn(x) from 0 to 1 */
    q = imsl_f_int_fcn (fcn, 0.0, 1.0,
                        IMSL_ERR_ABS,    err_abs,/* set abs error value*/
                        IMSL_RULE,       6,
                        IMSL_ERR_EST,    &err_est, /* pass in address */
                        0);
    error = q - exact;
                    /* print the result and the exact answer */
    printf(" integral = %10.3f\n    exact = %10.3f\n    error = %10.3f\n ",
            q, exact , error);   
    printf("   err_est = %g\n", err_est);                 
}

float fcn(float x)
{
                    /* compute sin(1/x), avoiding division by zero */
    return      ((x)>1.0e-5) ? sin(1.0/(x)) : 0.0;
}

Output

integral =      0.504
   exact =      0.504
   error =      0.000
   err_est = 0.000170593

Warning Errors

IMSL_ROUNDOFF_CONTAMINATION         Roundoff error, preventing the requested tolerance from being achieved, has been detected.

IMSL_PRECISION_DEGRADATION           A degradation in precision has been detected.

Fatal Errors

IMSL_MAX_SUBINTERVALS                       The maximum number of subintervals allowed has been reached.


Visual Numerics, Inc.
Visual Numerics - Developers of IMSL and PV-WAVE
http://www.vni.com/
PHONE: 713.784.3131
FAX:713.781.9260