Chapter 4: Quadrature

.p>.CMCH4.DOC!INT_FCN_ALG_LOG;int_fcn_alg_log

Integrates a function with algebraic-logarithmic singularities.

Synopsis

#include <imsl.h>

float imsl_f_int_fcn_alg_log (float fcn(), float a, float b, Imsl_quad weight, float alpha, float beta, ¼, 0)

The type double function is imsl_d_int_fcn_alg_log.

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.

Imsl_quad weight, float alpha, float beta   (Input)
These three parameters are used to describe the weight function that may have algebraic or logarithmic singularities at the endpoints. The parameter weight can take on four values as described below. The parameters alpha = α and beta = β specify the strength of the singularities at a or b and hence, must be greater than 1.

Weight

Integration Weight

IMSL_ALG

(x - a)a (b - x)b

IMSL_ALG_LEFT_LOG

(x - a)a (b - x)blog (x - a)

IMSL_ALG_RIGHT_LOG

(x - a)a (b - x)blog (b - x)

IMSL_ALG_LOG

(x - a)a (b - x)blog (x - a) log (b - x)

 

 

Return Value

The value of

is returned where w(x) is one of the four weights above. If no value can be computed, then NaN is returned.

Synopsis with Optional Arguments

#include <imsl.h>

float imsl_f_int_fcn_alg_log (float fcn(float x), float a, float b,
Imsl_quad weight, float alpha, float beta,
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_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_alg_log is a special-purpose integrator that uses a globally adaptive scheme to reduce the absolute error. It computes integrals whose integrands have the special form w(x)f(x) where w(x) is a weight function described above. A combination of modified Clenshaw-Curtis and Gauss-Kronrod formulas is employed. This function is based on the subroutine QAWS, which is fully documented by Piessens et al. (1983).

Examples

Example 1

The value of

is computed.

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

float           fcn(float x);
 
main()
{
    float       q, exact;
                                /* Evaluate the integral */
    q = imsl_f_int_fcn_alg_log (fcn, 0.0, 1.0,
                                IMSL_ALG_LEFT_LOG,  1.0, 0.5,
                                0);
                                /* Print the result and the */
                                /* exact answer */
    exact = (3.*log(2.)-4.)/9.;
    printf("integral  = %10.3f\nexact     = %10.3f\n", q, exact);
}

float fcn(float x)
{  
    return  sqrt(1+x);
}

Output

integral  =     -0.213
exact     =     -0.213

 

Example 2

The value of

is again computed. The values of the actual and estimated error are printed as well. Note that these numbers are machine dependent. Furthermore, the error estimate is usually pessimistic. That is, the actual error is usually smaller than the error estimate,
as in this example. The number of function evaluations also are printed.

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

float           fcn(float x);
 
main()
{
    int         n_evals;
    float       q, exact, err_est, exact_err;
                                /* Evaluate the integral */
    q = imsl_f_int_fcn_alg_log (fcn, 0.0, 1.0,
                                IMSL_ALG_LEFT_LOG, 1.0, 0.5,
                                IMSL_ERR_EST, &err_est,
                                IMSL_N_EVALS, &n_evals,
                                0);
                                /* Print the result and the */
                                /* exact answer */
    exact = (3.*log(2.)-4.)/9.;
    exact_err = fabs(exact - q);
    printf("integral  = %10.3f\nexact     = %10.3f\n", q, exact);
    printf("error estimate   = %e\nexact error      = %e\n", err_est,
             exact_err);
    printf("The number of function evaluations  =  %d\n", n_evals);
}

float fcn(float x)
{  
    return  sqrt(1+x);
}

Output

integral  =     -0.213
exact     =     -0.213
error estimate   = 3.725290e-09
exact error      = 1.490116e-08
The number of function evaluations  =  50

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