Reputation: 115
I already have a code for generating the weights and abscissas for the Gaussian-Legendre quadrature rule for integration but I am having difficulty in using it for double integrals.
To generate the weights and abscissas I use the following notation [w,x]=leg(x1,x2,n) where w are the weights, x are the abscissas, x1 is the lower limit of the integral, x2 is the upper limit, and n is the number of quadrature points.
I'll just give a simple example so that it can help me understand the idea. Suppose I have the following integral $\int_0^1 \int_0^1 x^2 y^2 dx dy$ How do I implement this?
Thanks in advance.
Upvotes: 0
Views: 1561
Reputation: 58721
Double integrals are integrals over a rectangular domain. They can either be treated with dedicated rectangular schemes or – what you attempt to do – with product schemes from one-dimensional quadrature. You could even mix and match two different schemes here.
The points of the product schemes are the 1D points in a Cartesian product, i.e., for every x_i
from scheme 1 and y_j
from scheme 2, (x_i, y_j)
is a point in the product scheme. The weights are the product of the two corresponding weights.
If you want to make it easy on you, you could use quadpy (a project of mine):
import numpy
import quadpy
quadpy.quadrilateral.integrate(
lambda x: numpy.exp(x[0]),
[[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]],
quadpy.quadrilateral.Product(quadpy.line_segment.GaussLegendre(4))
)
Upvotes: 0