For a function I do this (Integrate
over circular range):
NIntegrate[x*y Boole[Sqrt[x^2 + y^2] < 3], {x, 1, 5}, {y, 1, 5}]
Now, I want to do the Sum
of the circular set of elements in a square array.
Thanks for your 1st answers and sorry to not have been clear enough.
Example: from a two-dimensional {n, m}
array mat
, I would like to sum all the elements included in a circle of radius r
and located at {x0, y0}
.
Something like this:
Sum[mat[[n]][[m]] Boole[Sqrt[(n-x0)^2 + (m-y0)^2] < r], {n, x0-r, x0+r}, {m, y0-r, y0+r}]
Would you do it differently?
And next step, I would like to increase r
up to the Sum = mySum
.
I hope I'm clearer.
Total@Flatten@#&
after you extracting the desired elements. $\endgroup$mySum
? Is it some value you choose before-hand, and you want to findr
such that the sum is equal (or at least close) tomySum
? $\endgroup$