I might have completely missed something in my search. I want to discretely sum over a function, $f(x_i,y_j)$ multiplied by some other function $g$ over a general region $S$.

$$\sum_{(x,y)\in S}f(x,y)g\Delta x \Delta y$$

where the region S is given, for example, by a polygon $P$.

  1. For the polygon case, I know Mathematica can do this for an Integral as seen in the following example:

    pol = Polygon[CirclePoints[4 \[Pi]/3, 6]]; Integrate[1, {x, y} \[Element] pol]

But this wont work if I try to do the same with Sum[].

I think one solution is to calculate the boundary of the polygon by hand, and then plug it into the Sum[] function. But there must be a better solution, given the complexity of the Polygon[] function?

  1. What if it's a general region, for example by an inequality $f(x_i,y_j)<0$. Is there an easy way to do the sum over this region?

Thanks in advance! Any thoughts would be appreicated!


Henrik suggested DiscretizeRegion, it looks like it does discretize the region into triangles. But still, it won't work inside the Sum[] function.

  • $\begingroup$ If the region consists of a continuoum of points, your sum does not make sense at all. $\endgroup$ – Henrik Schumacher Aug 5 at 19:17
  • $\begingroup$ Yes I was hoping there is way to discretize the region nicely... $\endgroup$ – Histoscienology Aug 5 at 19:19
  • $\begingroup$ Try DiscretizeRegion. But every meaningful sum would actually be only the discretization of an integral. And NIntegrate does the discretization automatically if needed. $\endgroup$ – Henrik Schumacher Aug 5 at 19:21
  • $\begingroup$ Okay thanks, it looks like it does discretize the region geometrically but not computationally?... Am I missing something? $\endgroup$ – Histoscienology Aug 5 at 19:26
  • 1
    $\begingroup$ What is "it"? Yes, DiscretizeRegion will only discretize geometrically in to a MeshRegion. NIntgrate approximates the integral by doing the geometric discretization under the hood. $\endgroup$ – Henrik Schumacher Aug 5 at 19:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.