0

I would like to numerically evaluate an integral of the form:

$$ int_D f(x,y) dx dy $$

where $D$ is a region in $R^2$ and $f(x,y)$ is a map from $R^2$ to $R$.

I have a grid covering a subset of $R^2$. From this grid, for my particular application, I select a particular region $D$ (not necessarily rectangular, but simply-connected) according to the value of $f(x,y)$ (for example, I select all points for which $f(x,y) < 5$).

I would then like to integrate the function over this selected region. Many functions exist for 2D integrals over rectangular regions and some have been implemented for integration over simplicies. It appears to me none exist for integration over more general regions. It does not seem too complicated to implement a version of Riemann Sums, but have not seen it anywhere.

Does anyone know?

1 Answers1

0

You can use the integral function for bivariate.

Assume you have a function f(x, y) = xy/2 and you want to integrate the function with 0<x<10 and 0<y<x we have:

integrate(Vectorize(function(x,y)integrate(function(y)0.5*x*y, 0, x)[[1]]), 0, 10)
625 with absolute error < 6.9e-12

This is exactly the value you obtain by hand

Onyambu
  • 67,392
  • 3
  • 24
  • 53
  • Thank you for your answer, unfortunately this will not work in my context as I do not know the way to specify the region. I simply have coordinates of grid points at which to evaluate the integral at. – Marco Froelich Apr 28 '22 at 23:50
  • @MarcoFroelich can you give an example – Onyambu Apr 29 '22 at 00:11