hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_quad_md_gauss (d01fb)

Purpose

nag_quad_md_gauss (d01fb) computes an estimate of a multidimensional integral (from 11 to 2020 dimensions), given the analytic form of the integrand and suitable Gaussian weights and abscissae.

Syntax

[result, ifail] = d01fb(nptvec, weight, abscis, fun, 'ndim', ndim, 'lwa', lwa)
[result, ifail] = nag_quad_md_gauss(nptvec, weight, abscis, fun, 'ndim', ndim, 'lwa', lwa)

Description

nag_quad_md_gauss (d01fb) approximates a multidimensional integral by evaluating the summation
l1 l2 ln
w1,i1w2,i2wn,inf(x 1 , i1 ,x 2 , i2 ,,x n , in)
i1 = 1 i2 = 1 in = 1
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 wj,ijwj,ij and abscissae xj,ijxj,ij for a multidimensional product integration rule (see Davis and Rabinowitz (1975)). The number of dimensions may be anything from 11 to 2020.
The weights and abscissae for each dimension must have been placed in successive segments of the arrays weight and abscis; for example, by calling nag_quad_1d_gauss_wgen (d01bc) or nag_quad_1d_gauss_wres (d01tb) once for each dimension using a quadrature formula and number of abscissae appropriate to the range of each xjxj and to the functional dependence of ff on xjxj.
If normal weights are used, the summation will approximate the integral
w1(x1)w2(x2)wn(xn)f (x1,x2,,xn) dxndx2dx1
w1(x1)w2(x2)wn(xn)f (x1,x2,,xn) dxndx2dx1
where wj(x)wj(x) is the weight function associated with the quadrature formula chosen for the jjth dimension; while if adjusted weights are used, the summation will approximate the integral
f(x1,x2,,xn)dxndx2dx1.
f(x1,x2,,xn)dxndx2dx1.
You must supply a function to evaluate
f(x1,x2,,xn)
f(x1,x2,,xn)
at any values of x1,x2,,xnx1,x2,,xn within the range of integration.

References

Davis P J and Rabinowitz P (1975) Methods of Numerical Integration Academic Press

Parameters

Compulsory Input Parameters

1:     nptvec(ndim) – int64int32nag_int array
ndim, the dimension of the array, must satisfy the constraint 1ndim201ndim20.
nptvec(j)nptvecj must specify the number of points in the jjth dimension of the summation, for j = 1,2,,nj=1,2,,n.
2:     weight(lwa) – double array
lwa, the dimension of the array, must satisfy the constraint lwanptvec(1) + nptvec(2) + + nptvec(ndim)lwanptvec1+nptvec2++nptvecndim.
Must contain in succession the weights for the various dimensions, i.e., weight(k)weightk contains the iith weight for the jjth dimension, with
k = nptvec(1) + nptvec(2) + + nptvec(j1) + i.
k=nptvec1+nptvec2++nptvecj-1+i.
3:     abscis(lwa) – double array
lwa, the dimension of the array, must satisfy the constraint lwanptvec(1) + nptvec(2) + + nptvec(ndim)lwanptvec1+nptvec2++nptvecndim.
Must contain in succession the abscissae for the various dimensions, i.e., abscis(k)abscisk contains the iith abscissa for the jjth dimension, with
k = nptvec(1) + nptvec(2) + + nptvec(j1) + i.
k=nptvec1+nptvec2++nptvecj-1+i.
4:     fun – function handle or string containing name of m-file
fun must return the value of the integrand ff at a specified point.
[result] = fun(ndim, x)

Input Parameters

1:     ndim – int64int32nag_int scalar
nn, the number of dimensions of the integral.
2:     x(ndim) – double array
The coordinates of the point at which the integrand ff must be evaluated.

Output Parameters

1:     result – double scalar
The result of the function.

Optional Input Parameters

1:     ndim – int64int32nag_int scalar
Default: The dimension of the array nptvec.
nn, the number of dimensions of the integral.
Constraint: 1ndim201ndim20.
2:     lwa – int64int32nag_int scalar
Default: The dimension of the arrays weight, abscis. (An error is raised if these dimensions are not equal.)
The dimension of the arrays weight and abscis as declared in the (sub)program from which nag_quad_md_gauss (d01fb) is called.
Constraint: lwanptvec(1) + nptvec(2) + + nptvec(ndim)lwanptvec1+nptvec2++nptvecndim.

Input Parameters Omitted from the MATLAB Interface

None.

Output Parameters

1:     result – double scalar
The result of the function.
2:     ifail – int64int32nag_int scalar
ifail = 0ifail=0 unless the function detects an error (see [Error Indicators and Warnings]).

Error Indicators and Warnings

Errors or warnings detected by the function:
  ifail = 1ifail=1
On entry,ndim < 1ndim<1,
orndim > 20ndim>20,
orlwa < nptvec(1) + nptvec(2) + + nptvec(ndim)lwa<nptvec1+nptvec2++nptvecndim.

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.

Further Comments

The total time taken by nag_quad_md_gauss (d01fb) will be proportional to
T × nptvec(1) × nptvec(2) × × nptvec(ndim),
T×nptvec1×nptvec2××nptvecndim,
where TT is the time taken for one evaluation of fun.

Example

function nag_quad_md_gauss_example
nptvec = [int64(4);4;4;4];
weight = [0.1739274225687269;
     0.326072577431273;
     0.326072577431273;
     0.1739274225687269;
     0.4163695619189446;
     1.024051219227148;
     1.815573152910759;
     3.243572542203831;
     1.753944171790685;
     1.49901614734385;
     1.49901614734385;
     1.753944171790685;
     0.6025497939505366;
     2.179205635439835;
     8.982199653682851;
     108.2360449169268];
abscis = [1.930568155797026;
     1.669990521792428;
     1.330009478207572;
     1.069431844202974;
     0.1612738448096961;
     0.8728805505791732;
     2.268310148460564;
     4.697535456150566;
     2.334414218338977;
     0.7419637843027259;
     -0.7419637843027259;
     -2.334414218338977;
     1.223836944463802;
     2.477675284083257;
     7.090647990761759;
     41.20783978069118];
[result, ifail] = nag_quad_md_gauss(nptvec, weight, abscis, @fun)

function result = fun(ndim,x)
  result = (x(1)*x(2)*x(3))^6/(x(4)+2.0)^8*exp(-2.0*x(2)-0.5*x(3)*x(3));
 

result =

    0.2506


ifail =

                    0


function d01fb_example
nptvec = [int64(4);4;4;4];
weight = [0.1739274225687269;
     0.326072577431273;
     0.326072577431273;
     0.1739274225687269;
     0.4163695619189446;
     1.024051219227148;
     1.815573152910759;
     3.243572542203831;
     1.753944171790685;
     1.49901614734385;
     1.49901614734385;
     1.753944171790685;
     0.6025497939505366;
     2.179205635439835;
     8.982199653682851;
     108.2360449169268];
abscis = [1.930568155797026;
     1.669990521792428;
     1.330009478207572;
     1.069431844202974;
     0.1612738448096961;
     0.8728805505791732;
     2.268310148460564;
     4.697535456150566;
     2.334414218338977;
     0.7419637843027259;
     -0.7419637843027259;
     -2.334414218338977;
     1.223836944463802;
     2.477675284083257;
     7.090647990761759;
     41.20783978069118];
[result, ifail] = d01fb(nptvec, weight, abscis, @fun)

function result = fun(ndim,x)
  result = (x(1)*x(2)*x(3))^6/(x(4)+2.0)^8*exp(-2.0*x(2)-0.5*x(3)*x(3));
 

result =

    0.2506


ifail =

                    0



PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2013