I am trying to plot the following double sum expression with mathematica.

$$f(x,y)=\sum_{r=-\infty}^\infty \sum_{s=-\infty}^\infty \frac{1}{(k^2\tau^2+(x+2\pi r)^2+(y+2\pi s)^2)^{3/2}}$$

where $(k\tau)^2=\frac{1}{10}$.

But I keep getting an error, here is the code:

Sum[((2πs+x)^2+(2πr+y)^2+(1/10)^2)^(-3/2)), {s,-Infinity,Infinity},
{r,-Infinity, Infinity}] //Evaluate,

and the error is:

NSum::nsnum: Summand (or its derivative) -((6. 3.14159 (-4.99929+2. 3.14159s))/
      (0.01 +(-4.99929+<<1>>)^2+(-4.99929+<<18>> s)^2)^(5/2)) is not numerical at point r = 0.
NSum::nsnum: Summand (or its derivative) -((6. 3.14159 (-4.99929+2. 3.14159 s))/
    (0.01 +(-4.99929+<<1>>)^2+(-4.99929+<<18>> s)^2)^(5/2)) is not numerical at point r = 0.
Plot3D::exclul: {Im[(2 \[Pi] s+x)^2+(2 \[Pi] r+y)^2]-0} must be a 
       list or equalities or real-valued functions.
Cloud::timelimit: This computation has exceeded the time limit for your plan.

I would be grateful if someone can explain what is the problem.

  • 2
    $\begingroup$ Please edit your post and include your code, properly formatted in code blocks with proper Mathematica syntax, rather than screenshots. $\endgroup$ – march Jan 5 '17 at 19:06
  • $\begingroup$ Are you sure the sum converges? Why not break the problems into steps? Try the double sums first, then evaluate that at some random (x,y) point and see. Whenever you have larger problem, always break it down to smaller problems. $\endgroup$ – Nasser Jan 5 '17 at 19:34
  • $\begingroup$ This doesn't sum to infinity, but might let you get started i=8; n=5; Plot3D[ Sum[1/(1/10+(x+2 Pi r)^2 + (y+2 Pi s)^2)^(3/2), {s,-i,i}, {r,-i,i}], {x,-n,n}, {y,-n,n}] and let you slowly increase the value of i $\endgroup$ – Bill Jan 5 '17 at 19:39
  • $\begingroup$ Thank you for the answers. @Nasser The double sum is not tractable with Mathematica, that's why I am trying to plot it to see how it behaves. Mathematica just returns the double sum when I try to do the evaluation. $\endgroup$ – Mounia Hamidouche Jan 5 '17 at 20:01
  • 2
    $\begingroup$ Note that your sum is periodic in x and y with period 2*Pi. Exploiting this periodicity (e.g. by fitting a function over one cycle) should make numerical exploration of this function more efficient. $\endgroup$ – mikado Jan 5 '17 at 21:15

Mathematica can't find symbolic Sum solution,only numerically.

By good advice @Bill. You may increase n value.

f[x_?NumericQ, y_?NumericQ] :=
With[{n = 10}, NSum[((2 Pi s + x)^2 + (2 Pi r + y)^2 + (1/10)^2)^(-3/2), 
{s, -n, n}, {r, -n, n}, Method -> "AlternatingSigns"]]

Plot3D[f[x, y], {x, -5, 5}, {y, -5, 5}]

enter image description here


Using compile I speedup calculation.It is 90 times faster.

n = 30;
func = Compile[{{x, _Real}, {y, _Real}, {n, _Integer}}, 
With[{r = Range[-n, n]}, 
Tr[((2 Pi s + x)^2 + (2 Pi r + y)^2 + (1/10)^2)^(-3/2)]], {s, 
Range[-n, n]}], RuntimeAttributes -> {Listable}, 
Parallelization -> True, RuntimeOptions -> "Speed"];
Plot3D[func[x, y, n], {x, -5, 5}, {y, -5, 5}]
| improve this answer | |
  • $\begingroup$ It takes a lot of time. Maple produces that with n = 30 in a moment $\endgroup$ – user64494 Jan 5 '17 at 20:55
  • $\begingroup$ What does Method -> "AlternatingSigns" means ? $\endgroup$ – Mounia Hamidouche Jan 5 '17 at 21:07
  • $\begingroup$ This method speedup calculation twice than Automatic.I.m don't know why Mathematica takes a lot of time to calculation. $\endgroup$ – Mariusz Iwaniuk Jan 5 '17 at 21:12
  • $\begingroup$ @user64494. I'm updated code,it fast as Maple. $\endgroup$ – Mariusz Iwaniuk Jan 5 '17 at 23:39
  • $\begingroup$ The compiled version of your code is faster than Maple one. $\endgroup$ – user64494 Jan 6 '17 at 17:12

Your Answer

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

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