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_withdraw_md_gauss (d01fb)

 Contents

    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example

Purpose

nag_quad_md_gauss (d01fb) 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.

Syntax

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

Description

nag_quad_md_gauss (d01fb) 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 wj,ij and abscissae xj,ij 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 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 xj and to the functional dependence of f on xj.
If normal weights are used, the summation will approximate the integral
w1x1w2x2wnxnf x1,x2,,xn dxndx2dx1  
where wjx is the weight function associated with the quadrature formula chosen for the jth dimension; while if adjusted weights are used, the summation will approximate the integral
fx1,x2,,xndxndx2dx1.  
You must supply a function to evaluate
fx1,x2,,xn  
at any values of x1,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:     nptvecndim int64int32nag_int array
nptvecj must specify the number of points in the jth dimension of the summation, for j=1,2,,n.
2:     weightlwa – double array
Must contain in succession the weights for the various dimensions, i.e., weightk contains the ith weight for the jth dimension, with
k=nptvec1+nptvec2++nptvecj-1+i.  
3:     abscislwa – double array
Must contain in succession the abscissae for the various dimensions, i.e., abscisk contains the ith abscissa for the jth dimension, with
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 f at a specified point.
[result] = fun(ndim, x)

Input Parameters

1:     ndim int64int32nag_int scalar
n, the number of dimensions of the integral.
2:     xndim – double array
The coordinates of the point at which the integrand f must be evaluated.

Output Parameters

1:     result – double scalar
The value of fx evaluated at x.

Optional Input Parameters

1:     ndim int64int32nag_int scalar
Default: the dimension of the array nptvec.
n, the number of dimensions of the integral.
Constraint: 1ndim20.
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.
Constraint: lwanptvec1+nptvec2++nptvecndim.

Output Parameters

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

Error Indicators and Warnings

Errors or warnings detected by the function:
   ifail=1
On entry,ndim<1,
orndim>20,
orlwa<nptvec1+nptvec2++nptvecndim.
   ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
   ifail=-399
Your licence key may have expired or may not have been installed correctly.
   ifail=-999
Dynamic memory allocation failed.

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×nptvec1×nptvec2××nptvecndim,  
where T is the time taken for one evaluation of fun.

Example

This example evaluates the integral
120-1 x1x2x3 6 x4+2 8e-2x2e-0.5x32dx4dx3dx2dx1  
using adjusted weights. The quadrature formulae chosen are:
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.
function d01fb_example


fprintf('d01fb example results\n\n');

nptvec = [int64(4), 4, 4, 4];
a      = [1, 0, 0  , 1];
b      = [2, 2, 0.5, 2];
key    = [int64(0), -3, -4, -5];
j      = 1;
for i = 1:4
  [wgt, absc, ifail] = d01tb(key(i), a(i), b(i), nptvec(i));
  weight(j:j+nptvec(i)-1) = wgt;
  abscis(j:j+nptvec(i)-1) = absc;
  j = j + nptvec(i);
end

[result, ifail] = d01fb( ...
			 nptvec, weight, abscis, @fun);

fprintf('Result = %13.5f\n', result);



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

Result =       0.25065

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–2015