1
$\begingroup$

I want to efficiently compute weighted average of the whole cartesian plane with weight $\overline{r}(x,y)$

The definition of $\overline{r}(x,y)$ is the average radius of the closed region $\mathcal{C}$ from any point.

Suppose we have curve $\mathcal{C}$ and a ray, from point $\mathbf{p}$ rotating full circle at $\Delta \theta$ increments, while intersecting $\mathcal{C}$ at zero or more points. ( We will denote the intersections as $\left\{\mathbf{q}_i\right\}_{i=1}^{n}$ for $n$ intersections). If one or more intersections exist, $r_i = \sum\limits_{i=1}^{n} \|{\mathbf{q}_i}\mathbf - \mathbf p\|$, otherwise $r_i=0$.

Then as $\Delta \theta\to0$, the average radius function is $\overline{r}(\mathbf{p})=\left(\sum\limits_{i=1}^{n}r_i\right)/{n}$

For star shaped curves, with $\mathbf{p}$ inside the region, one can use an alternate and simpler definition

$$\overline{r}(\mathbf{p})=\frac1{2\pi}\oint_{\mathbf {q}_1\in\mathcal C}\|\mathbf {q}_1-\mathbf p\|\,\mathrm d\theta.$$

Thanks to @Rahul, I have a code that can implement $\overline{r}(x,y)$. For example, if $\mathcal{C}$ is defined by $x^2+y^2+\sin(4x)+\sin(4y)=4$

curve = DiscretizeRegion[
      ImplicitRegion[
       x^2+y^2+Sin[4*x]+Sin[4*y] == 4, {{x, -3, 3}, {y, -4, 4}}], {{-3, 3},
    {-4, 4}}, AccuracyGoal -> 8]
    q = MeshCoordinates[curve];
    edges = First /@ MeshCells[curve, 1];
    signedAngle[a_, b_] := Arg[(Complex @@ a)/(Complex @@ b)]
    avgRadius[p_] := 
     1/(2 \[Pi]) Abs[Sum[Module[{q1, q2, r, d\[Theta]}, q1 = q[[First@e]];
         q2 = q[[Last@e]];
         r = EuclideanDistance[p, (q1 + q2)/2];(*midpoint approximation*)
         d\[Theta] = signedAngle[q1 - p, q2 - p];
         r d\[Theta]], {e, edges}]]
   avgRadius[{x, y}]

We can plot the contour of $\overline{r}(x,y)$ on $\mathcal{C}$.

f = ContourPlot[avgRadius[{x, y}], {x, -3, 3}, {y, -3, 3}, 
  Exclusions -> None, Contours -> 100, PlotLegends -> Automatic]

Center

Hence the weighted average over the entire cartesian plane is

$$\begin{array}{cc} {x_w=\frac{\int_{-\infty}^{\infty}\int_{-\infty}^{\infty}x\overline{r}(x,y) \ dx \ dy }{\int_{-\infty}^{\infty}\int_{-\infty}^{\infty}\overline{r}(x,y) \ dx \ dy}} & { y_w=\frac{\int_{-\infty}^{\infty}\int_{-\infty}^{\infty}y\overline{r}(x,y) \ dx \ dy}{\int_{-\infty}^{\infty}\int_{-\infty}^{\infty}\overline{r}(x,y) \ dx \ dy} }\end{array}$$

I know the integral converges, since as $\mathbf{p}$ moves further away from $\mathcal{C}$, the average radius approaches zero.

Unfortunately, I'm unable to accurately approximate the integral to $4$ decimal places using NIntegrate under 35 minutes.

x_w=(NIntegrate[x*avgRadius[{x,y}],{x,-10,10},
{y,-10,10}])/(NIntegrate[avgRadius[{x,y}],{x,-10,10},{y,-10,10}])

y_w=(NIntegrate[y*avgRadius[{x,y}],{x,-10,10},{y,-10,10}])/(NIntegrate[avgRadius[{x,y}],{x,-10,10},{y,-10,10}])

How do I do accurately and efficiently approximate the weighted average of the $x$ and $y$-coordinates over the entire cartesian plane with weights $\overline{r}(x,y)$?

"Accurately" means the error should be less than .00001. "Efficently" means computing the integral under $15$ minutes? I am unable to do so using NIntegrate

$\endgroup$
8
  • 1
    $\begingroup$ FYI your code does not work as typed e.g. because in Mathematica its Sin[x] not sin(x). Also requesting avgRadius[{x, y}] takes forever and is useless? $\endgroup$
    – chris
    Jan 13, 2018 at 7:08
  • $\begingroup$ @chris I fixed the code. $\endgroup$
    – Arbuja
    Jan 13, 2018 at 12:06
  • $\begingroup$ @chris So how do we integrate $\overline{r}(x,y)$? Do we use sums? $\endgroup$
    – Arbuja
    Jan 13, 2018 at 12:07
  • 2
    $\begingroup$ I'm voting to close this question as off-topic because because this question is ill-posed. $\endgroup$ Jan 13, 2018 at 14:37
  • 3
    $\begingroup$ I'm voting to close this question as off-topic because the issue it raises is not a Mathematica issue but a mathematics issue. That it is formulated in terms of Mathematica is not sufficient to make it an appropriate question for Mathematica.SE. $\endgroup$
    – m_goldberg
    Jan 13, 2018 at 16:39

1 Answer 1

2
$\begingroup$

The short answer is probably

xw[reg]:=∞
yw[reg]:=∞

at least for regions with nonempty interior.

With the unit circle

curve = DiscretizeRegion[ImplicitRegion[x^2 + y^2 == 1, {{x, -3, 3}, {y, -4, 4}}], {{-3, 3}, {-4, 4}}, AccuracyGoal -> 8]

I obtain as counter example:

xlist = 10. Range[10, 200, 10];
a = {#, avgRadius[{#, 0}]} & /@ xlist;
b = {#, 0.5/#} & /@ xlist;
ListLinePlot[Transpose[{xlist, a[[All, 2]] - b[[All, 2]]}]]

enter image description here

So, $\bar r(x,y) = \frac{1}{2 \sqrt{x^2 + y^2}}$ and this function is not integrable over the plane.

$\endgroup$
5
  • $\begingroup$ What if we took the weighted average of all points inside $\mathcal{C}$. Would $x_w$ and $y_w$ converge? $\endgroup$
    – Arbuja
    Jan 13, 2018 at 14:43
  • $\begingroup$ Check it out for yourself. $\endgroup$ Jan 13, 2018 at 14:44
  • $\begingroup$ I'm editing my question. It will make your answer no longer relevant. Should I create a new question instead? $\endgroup$
    – Arbuja
    Jan 13, 2018 at 14:54
  • $\begingroup$ @Arbuja In general, asking a new question is preferable. $\endgroup$
    – bbgodfrey
    Jan 13, 2018 at 15:37
  • $\begingroup$ @bbgodfrey I posted a new question. $\endgroup$
    – Arbuja
    Jan 13, 2018 at 16:53

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