Settings help

CPP Name Style:

## 1Purpose

md_gauss computes an estimate of a multidimensional integral (from $1$ to $20$ dimensions), given the analytic form of the integrand and suitable Gaussian weights and abscissae.

## 2Specification

```#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)```

## 3Description

md_gauss approximates a multidimensional integral by evaluating the summation
 $∑i1=1l1 w 1,i1 ∑i2=1l2 w2,i2 ⋯ ∑in=1ln wn,in f ( x 1 , i1 , x 2 , i2 ,…, x n , in )$
given the weights ${w}_{j,{i}_{j}}$ and abscissae ${x}_{j,{i}_{j}}$ for a multidimensional product integration rule (see Davis and Rabinowitz (1975)). The number of dimensions may be anything from $1$ to $20$.
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 ${x}_{j}$ and to the functional dependence of $f$ on ${x}_{j}$.
If normal weights are used, the summation will approximate the integral
 $∫w1(x1)∫w2(x2)⋯∫wn(xn)f (x1,x2,…,xn) dxn⋯dx2dx1$
where ${w}_{j}\left(x\right)$ is the weight function associated with the quadrature formula chosen for the $j$th dimension; while if adjusted weights are used, the summation will approximate the integral
 $∫∫⋯∫f(x1,x2,…,xn)dxn⋯dx2dx1.$
You must supply a function to evaluate
 $f(x1,x2,…,xn)$
at any values of ${x}_{1},{x}_{2},\dots ,{x}_{n}$ within the range of integration.
Davis P J and Rabinowitz P (1975) Methods of Numerical Integration Academic Press

## 5Arguments

1: $\mathbf{nptvec}\left({\mathbf{ndim}}\right)$types::f77_integer array Input
On entry: ${\mathbf{nptvec}}\left(\mathit{j}-1\right)$ must specify the number of points in the $\mathit{j}$th dimension of the summation, for $\mathit{j}=1,2,\dots ,n$.
2: $\mathbf{weight}\left({\mathbf{lwa}}\right)$double array Input
On entry: must contain in succession the weights for the various dimensions, i.e., ${\mathbf{weight}}\left(k-1\right)$ contains the $i$th weight for the $j$th dimension, with
 $k=nptvec(0)+nptvec(1)+⋯+nptvec(j-2)+i.$
3: $\mathbf{abscis}\left({\mathbf{lwa}}\right)$double array Input
On entry: must contain in succession the abscissae for the various dimensions, i.e., ${\mathbf{abscis}}\left(k-1\right)$ contains the $i$th abscissa for the $j$th dimension, with
 $k=nptvec(0)+nptvec(1)+⋯+nptvec(j-2)+i.$
4: $\mathbf{f}$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: $\mathbf{x}\left({\mathbf{ndim}}\right)$double array Input
On entry: the coordinates of the point at which the integrand $f$ must be evaluated.
2: $\mathbf{ndim}$types::f77_integer Input
On entry: $n$, 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: $\mathbf{opt}$OptionalD01FB Input/Output
Optional parameter container, derived from Optional.

1: $\mathbf{ndim}$
$n$, the number of dimensions of the integral.
2: $\mathbf{lwa}$
The dimension of the arrays weight and abscis.

## 6Exceptions 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
$\mathbf{errorid}=1$
On entry, ${\mathbf{lwa}}$ is too small.
${\mathbf{lwa}}=⟨\mathit{value}⟩$.
Minimum possible dimension: $⟨\mathit{\text{value}}⟩$.
$\mathbf{errorid}=1$
On entry, ${\mathbf{ndim}}=⟨\mathit{value}⟩$.
Constraint: ${\mathbf{ndim}}\le 20$.
$\mathbf{errorid}=1$
On entry, ${\mathbf{ndim}}=⟨\mathit{value}⟩$.
Constraint: ${\mathbf{ndim}}\ge 1$.
$\mathbf{errorid}=10601$
On entry, argument $⟨\mathit{\text{value}}⟩$ must be a vector of size $⟨\mathit{\text{value}}⟩$ array.
Supplied argument has $⟨\mathit{\text{value}}⟩$ dimensions.
$\mathbf{errorid}=10601$
On entry, argument $⟨\mathit{\text{value}}⟩$ must be a vector of size $⟨\mathit{\text{value}}⟩$ array.
Supplied argument was a vector of size $⟨\mathit{\text{value}}⟩$.
$\mathbf{errorid}=10601$
On entry, argument $⟨\mathit{\text{value}}⟩$ must be a vector of size $⟨\mathit{\text{value}}⟩$ array.
The size for the supplied array could not be ascertained.
$\mathbf{errorid}=10602$
On entry, the raw data component of $⟨\mathit{\text{value}}⟩$ is null.
$\mathbf{errorid}=10603$
On entry, unable to ascertain a value for $⟨\mathit{\text{value}}⟩$.
$\mathbf{errorid}=-99$
An unexpected error has been triggered by this routine.
$\mathbf{errorid}=-399$
Your licence key may have expired or may not have been installed correctly.
$\mathbf{errorid}=-999$
Dynamic memory allocation failed.
Raises: CallbackException
$\mathbf{errorid}=10701$
An exception was thrown in a callback.
$\mathbf{errorid}=10702$
The memory address for an array in a callback has changed.

## 7Accuracy

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.

## 8Parallelism 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
 $T×nptvec(0)×nptvec(1)×⋯×nptvec(ndim-1),$
where $T$ is the time taken for one evaluation of f.

## 10Example

This example evaluates the integral
 $∫12∫0∞∫-∞∞∫1∞ (x1x2x3) 6 (x4+2) 8e-2x2e-0.5x32dx4dx3dx2dx1$
• ${x}_{1}$: Gauss–Legendre, $a=1.0$, $b=2.0$,
• ${x}_{2}$: Gauss–Laguerre, $a=0.0$, $b=2.0$,
• ${x}_{3}$: Gauss–Hermite, $a=0.0$, $b=0.5$,
• ${x}_{4}$: rational Gauss, $a=1.0$, $b=2.0$.