floatfcn (floatx) (Input) User-supplied function to be integrated.
floata (Input) Lower limit of integration.
floatb (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 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, intrule (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, floaterr_abs (Input) Absolute accuracy desired. Default: err_abs = where ɛ is the machine precision
IMSL_ERR_REL, floaterr_rel (Input) Relative accuracy desired. Default: err_rel = 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, intmax_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, floatfcn(floatx, 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 Passing Data to User-Supplied Functions in the introduction to 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).
On some platforms, imsl_f_int_fcn can evaluate the user-supplied function fcn in parallel. This is done only if the function imsl_omp_options is called to flag user-defined functions as thread-safe. A function is thread-safe if there are no dependencies between calls. Such dependencies are usually the result of writing to global or static variables.
Should imsl_f_int_fcn fail to produce acceptable results, consider one of the more specialized functions documented in this chapter section.
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 <imsl.h>
#include <stdio.h>
#include <math.h>
float fcn(float x);
float q;
float exact;
int main()
{
imsl_omp_options(
IMSL_SET_FUNCTIONS_THREAD_SAFE, 1,
0);
/* 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 <imsl.h>
#include <stdio.h>
#include <math.h>
float fcn(float x);
int main()
{
float q, err_est, err_abs= 0.0001, exact = 0.50406706, error;
Roundoff error has been detected. The requested tolerances, “err_abs” = # and “err_rel” cannot be reached.
IMSL_PRECISION_DEGRADATION
Precision is degraded due to too fine a subdivision relative to the requested tolerance. This may be due to bad integrand behavior in the interval (#,#). Higher precision may alleviate this problem.
Fatal Errors
IMSL_MAX_SUBINTERVALS
The maximum number of subintervals allowed “max_sub” has been reached.
IMSL_STOP_USER_FCN
Request from user supplied function to stop algorithm. User flag = "#".