6
$\begingroup$

Let's say, I have a compact area $S$ (for example a circle, a square or some arbitrary polygon) and a function $f: S \rightarrow \mathbb{R}$. I want to numerically calculate the Integral $$ \int_S f(\vec{x})\ \mathrm{d}x \approx \sum_i f(x_i)\Delta x_i $$ of the function over $S$.

My question is, how to choose the sapling points $x_i$ for "complicated" areas such as circles or shapes irregularly shaped borders. Can I simply overlay the aread with a equidistant lattice of sampling points and remove the ones not inside the area?

$\endgroup$
  • 5
    $\begingroup$ Super hard problem. Most general approach is to integrate over a square that contains your domain as a subset and then multiply the integrand by an indicator function. This generally makes your integrand discontinuous so convergence is slow. If you need speed, you have to work out the Gaussian quadratures for your domain; see doi.org/10.1016/S0885-064X(03)00011-6 for details. $\endgroup$ – user14717 Nov 12 '18 at 23:19
  • 4
    $\begingroup$ You could discretize your domain in triangles/tetrahedrals and compute the integral over each domain. $\endgroup$ – nicoguaro Nov 13 '18 at 0:21
  • 2
    $\begingroup$ Do you know anything about your function, $f$? The optimal quadrature is going to depend on that, along which quantites you're most interesting in keeping well behaved (e.g., is it important that you get back the exact solution for a constant function). $\endgroup$ – origimbo Nov 13 '18 at 13:45
6
$\begingroup$

Instead of directly integrating over the area, it is often more convenient to use the divergence theorem to replace the area integral with an integral over the boundary edges.

The divergence theorem in three dimensions for a vector function $F$ can be written

$$ \int_V \nabla \cdot {\bf F} dv = \int_S {\bf F} \cdot ds $$ That is, an integral over the volume of the region can be replaced by an integral over the bounding surface. For a scalar function, $f$, in two dimensions this can be simplified to $$ \int_A \frac{\partial f}{\partial x} dx dy = \int_C f ds $$ relating an integral over the area to a line integral over the curve bounding the area.

In general, you may have many separate edges bounding the area. You integrate over each edge and sum the results. Each edge may have a different geometric form. For simple analytic curves (e.g. a straight line or circular arc), it may be possible to evaluate the integral analytically. For more complicated parametric forms, it is necessary to use numerical integration to evaluate the line integral.

$\endgroup$

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.