NAG CPP Interface
nagcpp::quad::md_gauss (d01fb)
1
Purpose
md_gauss computes an estimate of a multidimensional integral (from to dimensions), given the analytic form of the integrand and suitable Gaussian weights and abscissae.
2
Specification
#include "d01/nagcpp_d01fb.hpp"
template <typename NPTVEC, typename WEIGHT, typename ABSCIS, typename F>
double md_gauss(const NPTVEC &nptvec, const WEIGHT &weight, const ABSCIS &abscis, F &&f, OptionalD01FB opt)
template <typename NPTVEC, typename WEIGHT, typename ABSCIS, typename F>
double md_gauss(const NPTVEC &nptvec, const WEIGHT &weight, const ABSCIS &abscis, F &&f)
3
Description
md_gauss approximates a multidimensional integral by evaluating the summation
given the weights
and abscissae
for a multidimensional product integration rule (see
Davis and Rabinowitz (1975)). The number of dimensions may be anything from
to
.
The weights and abscissae for each dimension must have been placed in successive segments of the arrays
weight and
abscis; for example, by calling
dim1_gauss_wres and
d01tcf (no CPP interface)
once for each dimension using a quadrature formula and number of abscissae appropriate to the range of each
and to the functional dependence of
on
.
If normal weights are used, the summation will approximate the integral
where
is the weight function associated with the quadrature formula chosen for the
th dimension; while if adjusted weights are used, the summation will approximate the integral
You must supply a function to evaluate
at any values of
within the range of integration.
4
References
Davis P J and Rabinowitz P (1975) Methods of Numerical Integration Academic Press
5
Arguments
-
1:
– types::f77_integer array
Input
-
On entry: must specify the number of points in the th dimension of the summation, for .
-
2:
– double array
Input
-
On entry: must contain in succession the weights for the various dimensions, i.e.,
contains the
th weight for the
th dimension, with
-
3:
– double array
Input
-
On entry: must contain in succession the abscissae for the various dimensions, i.e.,
contains the
th abscissa for the
th dimension, with
-
4:
– double
Function
-
f must return the value of the integrand at a given point.
double f(const utility::array1D<double,data_handling::ArgIntent::IntentIN> &x)
-
1:
– double array
Input
-
On entry: the coordinates of the point at which the integrand must be evaluated.
-
2:
– types::f77_integer
Input
-
On entry: , the number of dimensions of the integral.
Note: f should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by
md_gauss. If your code inadvertently
does return any NaNs or infinities,
md_gauss is likely to produce unexpected results.
-
5:
– OptionalD01FB
Input/Output
-
Optional parameter container, derived from
Optional.
5.1Additional Quantities
- 1:
- , the number of dimensions of the integral.
- 2:
- The dimension of the arrays weight and abscis.
6
Exceptions and Warnings
Errors or warnings detected by the function:
All errors and warnings have an associated numeric error code field,
errorid, stored either as a member of the thrown exception object (see
errorid), or as a member of
opt.
ifail, depending on how errors
and warnings are being handled (see
Error Handling for more details).
- Raises: ErrorException
-
- On entry, is too small.
.
Minimum possible dimension: .
- On entry, .
Constraint: .
- On entry, .
Constraint: .
- On entry, argument must be a vector of size array.
Supplied argument has dimensions.
- On entry, argument must be a vector of size array.
Supplied argument was a vector of size .
- On entry, argument must be a vector of size array.
The size for the supplied array could not be ascertained.
- On entry, the raw data component of is null.
- On entry, unable to ascertain a value for .
- An unexpected error has been triggered by this routine.
- Your licence key may have expired or may not have been installed correctly.
- Dynamic memory allocation failed.
- Raises: CallbackException
-
- An exception was thrown in a callback.
- The memory address for an array in a callback has changed.
7
Accuracy
The accuracy of the computed multidimensional sum depends on the weights and the integrand values at the abscissae. If these numbers vary significantly in size and sign then considerable accuracy could be lost. If these numbers are all positive, then little accuracy will be lost in computing the sum.
8
Parallelism and Performance
Please see the description for the underlying computational routine in this section of the
FL Interface documentation.
The total time taken by
md_gauss will be proportional to
where
is the time taken for one evaluation of
f.
10
Example
This example evaluates the integral
using adjusted weights. The quadrature formulae chosen are:
- : Gauss–Legendre, , ,
- : Gauss–Laguerre, , ,
- : Gauss–Hermite, , ,
- : rational Gauss, , .
Four points are sufficient in each dimension, as this integral is in fact a product of four one-dimensional integrals, for each of which the chosen four-point formula is exact.
10.1
Example Program