# double sum with condition

I was trying to compute the following sum:

$$\phi(x,y)=\frac{1}{4\pi^2}\sum_{(n,m)\neq(0,0)}\frac{1}{n^2+m^2}\exp(i(nx+my))$$ where the range of indices is, say, $-10\leq n, \,m\leq 10$.

But I don't know how to "encode" the condition $(n,m)\neq(0,0)$ into Mathematica. I tried this:

phi[x, y] = (1/(4 Pi^2)) Sum[(1/(n^2 + m^2))*Exp[I*(n*x + m*y)], {n, -10, 10},
{m, -10, 10}, n^2+m^2>0]


but it didn't work.

Thanks for any help!

Thanks everyone. I tried to use If statement inside the Sum command, and it worked. Here it is:

phi[x, y] = 1/(4 Pi^2) Sum[ If[0 < n^2 + m^2, 1/(n^2 + m^2) Exp[I*(n*x + m*y)], 0],
{n, -10, 10}, {m, -10, 10}]

• {n, DeleteCases[Range[-10, 10], 0]} ? – Algohi Apr 7 '16 at 20:39
• You could just put an If statement inside your sum: If[n^2 + m^2 == 0, 0, ...]. – wxffles Apr 7 '16 at 20:50

One can reformulate slightly

nmx = 3
1/π^2 Sum[1/(n^2 + m^2) Cos[n x] Cos[m x], {n, 1, nmx}, {m, 1, mmx}]


Interestingly, when x=$\pi$ the sum with infinite limits can be computed

1/π^2 Sum[1/(n^2 + m^2) Cos[n π] Cos[m π], {n, 1, ∞}, {m, 1, ∞}]
(*1/12 1/π^2 (π^2 - π Log[8])*)

• Hi yarchik, what does nmx do here? I think we still have $(n,m)=(0,0)$ here, which is not what I want. – mori39 Apr 8 '16 at 2:32
• @mori, look at the limits of yarchik's sum carefully, and recall the exponential formula for cosine. – J. M. is away Apr 8 '16 at 2:40