1
$\begingroup$

I have the following code:

NSum[(-1)^(i + j + i*j)* Exp[(-t*Pi)/2*(i^2 + j^2)],{i,-Infinity, Infinity}, {j, -Infinity, Infinity}, NSumTerms -> 30, Method -> "AlternatingSigns", WorkingPrecision -> 40]

I want to evaluate this at a list of different values of t at once, say

t={1/1000,1/100,1/10,1,2,5/4,3}

How can I achieve this? It will be nice to display the results as table/matrix of two column, too; values of t and its respective evaluation.

$\endgroup$
  • $\begingroup$ You could define a function aymane[t_?NumericQ] := NSum[(* stuff *)]... $\endgroup$ – J. M. will be back soon Apr 6 '17 at 12:34
  • $\begingroup$ Thank you, I already did that. now how I evaluate in a set of values, can you give me some hints because I am beginner user. how I achieve the table look? $\endgroup$ – Aymane Fihadi Apr 6 '17 at 12:38
  • $\begingroup$ Look up Table[] and Grid[], then. $\endgroup$ – J. M. will be back soon Apr 6 '17 at 12:40
  • $\begingroup$ Thank you. I come up with this Grid[{{1/1000, 1/100, 1/10, 1, 2, 5/4, 3}, Table[aymane[i], {i, {1/1000, 1/100, 1/10, 1, 2, 5/4, 3}}]}] But I remarked that Grid round the numerical values. $\endgroup$ – Aymane Fihadi Apr 6 '17 at 13:08
  • $\begingroup$ @J.M. Can you help me with this problem, because I want all the decimals without any rounding. $\endgroup$ – Aymane Fihadi Apr 6 '17 at 13:19
2
$\begingroup$

For a start:

Clear@sum
sum[t_?NumericQ] := {t, 
  NSum[(-1)^(i + j + i*j)*Exp[(-t*Pi)/2*(i^2 + j^2)], {i, -Infinity, 
    Infinity}, {j, -Infinity, Infinity}, NSumTerms -> 30, 
   Method -> "AlternatingSigns", WorkingPrecision -> 40]}

out = sum /@ {1/1000, 1/100, 1/10, 1, 2, 5/4, 3};

Grid[{{"t", "sum"}}~Join~Chop[out], Frame -> All, Alignment -> "."]

enter image description here

$\endgroup$

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.