MATLAB: Numerical integration gauss legendre

gausslegendre

I want a code which compute double integrals with gauss-legendre method.

Best Answer

There is a function in matlab's Symbolic Toolbox Mupad called "numeric::gldata" described at:
http://www.mathworks.com/help/symbolic/mupad_ref/numeric-gldata.html
as well as a number of entries in the File Exchange which provide for the Gauss-Legendre method for single integrals. I would suppose you already know of these.
If your double integral is to be taken over a rectangular area, you can regard your problem as a single integral with respect to one variable of single integrals with respect to a second variable for some function of these two variables. The weights and abscissae of the Gauss-Legendre nodes in the one direction and those in the other direction would be selected in a grid pattern of points within the rectangular area. There is a pdf article at the site:
which explains this method as applied to double integrals better than I can here in their equation 2.7 on page 9. As explained in this article, your computation would be a sum of sums of products. Each term would the the product of the integrand value at a node multiplied by two weight values, one for each of the two directions. As you are no doubt aware, the Gauss-Legnedre method dictates the spacing of nodes where the integrand function is to be evaluated. This seems to me to be the correct approach to your problem.
Note that the above "sum of sums" can be expressed nicely in matlab by the product of three arrays and a scale factor:
A/4*W1'*F*W2
where W1 and W2 are column vectors of the node weights in the two direction, where F is a matrix of appropriate values of the integrand at the nodes, and where the scalar A is the area of the rectangle.
(Corrected: The division by 4 above is needed because the Gauss-Legendre weights and abscissae are intended for the interval from -1 to +1 and the weights sum to 2, so for a double integral we need to divide the area by 4.)