The type double function is imsl_d_int_fcn_smooth.
Required Arguments
floatfcn (float x) (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, NaN is returned.
Synopsis with Optional Arguments
#include<imsl.h>
float imsl_f_int_fcn_smooth (float fcn(), float a, float b,
IMSL_ERR_ABS, float err_abs,
IMSL_ERR_REL, float err_rel,
IMSL_ERR_EST, float *err_est,
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, floaterr_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_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_smooth is designed to integrate smooth functions. It implements a nonadaptive quadrature procedure based on nested Paterson rules of order 10, 21, 43, and 87. These rules are positive quadrature rules with degree of accuracy 19, 31, 64, and 130, respectively. The function imsl_f_int_fcn_smooth applies these rules successively, estimating the error, until either the error estimate satisfies the user-supplied constraints or the last rule is applied.
This function is not very robust, but for certain smooth functions it can be efficient. If imsl_f_int_fcn_smooth should not perform well, we recommend the use of the function imsl_f_int_fcn_sing.
On some platforms, imsl_f_int_fcn_smooth 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.
The function imsl_f_int_fcn_smooth is based on the subroutine QNG by Piessens et al. (1983).
Examples
Example 1
The value of
is computed.
#include <imsl.h>
#include <stdio.h>
#include <math.h>
float fcn(float x);
int main()
{
float q, exact;
imsl_omp_options(
IMSL_SET_FUNCTIONS_THREAD_SAFE, 1,
0);
/* Evaluate the integral */
q = imsl_f_int_fcn_smooth (fcn, 0., 2.,
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)
{
return x * exp(x);
}
Output
integral = 8.389
exact = 8.389
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 is the case in this example.
#include <imsl.h>
#include <stdio.h>
#include <math.h>
float fcn(float x);
int main()
{
float q, exact, err_est, exact_err;
imsl_omp_options(
IMSL_SET_FUNCTIONS_THREAD_SAFE, 1,
0);
/* Evaluate the integral */
q = imsl_f_int_fcn_smooth (fcn, 0.0, 2.0,
IMSL_ERR_EST, &err_est,
0);
/* Print the result and the */
/* exact answer */
exact = exp(2.0) + 1.0;
exact_err = fabs(exact - q);
printf("integral = %10.3f\nexact = %10.3f\n", q, exact);