I'm relatively inexperienced with mathematica, so I apologize if this is a trivial question. I want to take a double sum over a function $f(i,j)$ of two indices, of the form $$ \sum_{i = -\infty}^\infty \sum_{j = 0\atop j\not = i}^m f(i,j). $$ That is, in the inner sum I want to sum over only those indices $j$ in my range of summation that satisfy the assumption $j \not = i$. How can I input such a sum to Mathematica?
Answer
You can use Boole
as follows:
Sum[f[i, j] Boole[i != j], {j, 0, m}, {i, -Infinity, Infinity}]
Here's an example where f[i, j] = Sin[i] Cos[j]
Sum[Sin[i] Cos[j] Boole[i != j], {j, 0, 3}, {i, 0, 3}]
Which gives
Sin[1] + Cos[2] Sin[1] + Cos[3] Sin[1] + Sin[2] + Cos[1] Sin[2] +
Cos[3] Sin[2] + Sin[3] + Cos[1] Sin[3] + Cos[2] Sin[3]
Comments
Post a Comment