IMSL C Math Library
int_fcn_2d
Computes a two-dimensional iterated integral.
Synopsis
#include <imsl.h>
float imsl_f_int_fcn_2d (float fcn(), float a, float b, float gcn (float x), float hcn (float x), , 0)
The type double function is imsl_d_int_fcn_2d.
Required Arguments
float fcn (float x, float y) (Input)
User-supplied function to be integrated.
float a (Input)
Lower limit of outer integral.
float b (Input)
Upper limit of outer integral.
float gcn (float x) (Input)
User-supplied function to evaluate the lower limit of the inner integral.
float hcn (float x) (Input)
User-supplied function to evaluate the upper limit of the inner integral.
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_2d (float fcn(), float a, float b, float gcn (), float hcn (),
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,
IMSL_GCN_W_DATA, float gcn(), void *data,
IMSL_HCN_W_DATA, float hcn(), 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, float y, 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.
IMSL_GCN_W_DATA, float gcn (float x, void *data), void *data (Input)
User supplied function to evaluate the lower limit of the inner integral, which also accepts a pointer to data that is supplied by the user. See Passing Data to User-Supplied Functions in the introduction to this manual for more details.
IMSL_HCN_W_DATA, float hcn (float x, void *data), void *data (Input)
User supplied function to evaluate the upper limit of the inner integral, 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_2d approximates the two-dimensional iterated integral
An estimate of the error is returned in err_est. The lower-numbered rules are used for less smooth integrands while the higher-order rules are more efficient for smooth (oscillatory) integrands.
Examples
Example 1
In this example, compute the value of the integral
 
#include <imsl.h>
#include <stdio.h>
#include <math.h>
 
float fcn(float x, float y), gcn(float x), hcn(float x);
 
int main()
{
float q, exact;
 
/* Evaluate the integral */
q = imsl_f_int_fcn_2d (fcn, 0.0, 1.0, gcn, hcn, 0);
/* print the result and the exact answer */
exact = 0.5*(cos(9.0)+cos(2.0)-cos(10.0)-cos(1.0));
printf("integral = %10.3f\nexact = %10.3f\n", q, exact);
}
 
float fcn(float x, float y)
{
return y * cos(x+y*y);
}
 
float gcn(float x)
{
return 1.0;
}
 
float hcn(float x)
{
return 3.0;
}
Output
 
integral = -0.514
exact = -0.514
 
Example 2
In this example, compute the value of the integral
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. The number of function evaluations also is printed.
 
#include <imsl.h>
#include <stdio.h>
#include <math.h>
 
float fcn(float x, float y), gcn(float x), hcn(float x);
 
int main()
{
int n_evals;
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_2d (fcn, 0., 1., gcn, hcn,
IMSL_ERR_EST, &err_est,
IMSL_N_EVALS, &n_evals,
0);
/* Print the result and the */
/* exact answer */
exact = 0.5*(cos(9.0)+cos(2.0)-cos(10.0)-cos(1.0));
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, float y)
{
return y * cos(x+y*y);
}
 
float gcn(float x)
{
return 1.0;
}
 
float hcn(float x)
{
return 3.0;
}
Output
 
integral = -0.514
exact = -0.514
error estimate = 3.065193e-06
exact error = 1.192093e-07
The number of function evaluations = 441
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.
IMSL_STOP_USER_FCN
Request from user supplied function to stop algorithm. User flag = "#".