ps1 q2 (a)

2 Log[2.0]

(*Table[If[ i^2 + j^2 ≠ 0 && i^2 + j^2 ≤ 2^2, N[Sqrt[i^2 + j^2 ]] +u[i] + v[j], N[Sqrt[i^2 + j^2]] + nn[i] + mm[j]], {i, -3, 3}, {j, -3, 3}]*)

ps1 q2 (b)

Clear[t, tr, ts, aRect, aSphere, i, j, k]
t[i_, j_, k_] = (-1.)^(i + j + k+ 1) / Sqrt[ i^2 + j^2 + k^2];

aRect[m_] := Sum[ 
If[ i^2 + j^2 + k^2≠ 0,
t[i, j, k],
0],
{i, -m, m}, 
{j, -m, m}, 
{k, -m, m} ] 

aSphere[m_] := Sum[ 
If[ i^2 + j^2 + k^2≠ 0 &&i^2+ j^2 + k^2 ≤ m^2,
t[i, j, k],
0],
{i, -m, m}, 
{j, -m, m}, 
{k, -m, m} ] 

Table[ aRect[m], {m, 1, 20}]
Table[ aSphere[m], {m, 1, 20}]

aRect[97]
aSphere[97]

aRect[98]
aSphere[98]

aRect[99]
aSphere[99]

(*Timing[ Block[ {m}, m = 20 ; Sum[ 
If[ i^2 + j^2 ≠ 0, 
(-1.)^(i + j + k+ 1) / Sqrt[ i^2 + j^2 + k^2],
 0],
{i, -m, m}, 
{j, -m, m}, 
{k, -m, m} ] 
]]
Timing[ Block[ {m}, m = 20 ; Sum[ 
If[ i^2 + j^2 ≠ 0, 
(-1)^(i + j + k+ 1) / Sqrt[ i^2 + j^2 + k^2],
 0],
{i, -m, m}, 
{j, -m, m}, 
{k, -m, m} ] // N
]]
t[i_, j_, k_] = (-1.)^(i + j + k+ 1) / Sqrt[ i^2 + j^2 + k^2];
Timing[ Block[ {m}, m = 20 ; Sum[ 
If[ i^2 + j^2 ≠ 0, 
t[i, j, k],
 0],
{i, -m, m}, 
{j, -m, m}, 
{k, -m, m} ] 
]]

Clear[t2]
t2 = Compile[{{i, _Integer}, {j, _Integer}, {k, _Integer}}, (-1.)^(i + j + k+ 1) / Sqrt[ i^2 + j^2 + k^2]]
Timing[ Block[ {m}, m = 20 ; Sum[ 
If[ i^2 + j^2 ≠ 0, 
t2[i, j, k],
 0],
{i, -m, m}, 
{j, -m, m}, 
{k, -m, m} ] 
]]
*)

(*Table[ aRect[m], {m, 97, 99}]
Table[ aSphere[m], {m, 97, 99}]
*)

aRect = Compile[{{m, _Integer}},
Sum[ 
If[ i^2 + j^2 + k^2≠ 0, 
t[i, j, k],
 0],
{i, -m, m}, 
{j, -m, m}, 
{k, -m, m} ] ]

aSphere= Compile[{{m, _Integer}},
Sum[ 
If[ (i^2 + j^2 + k^2≠ 0) && (i^2+ j^2 + k^2 ≤ m^2), 
t[i, j, k],
 0],
{i, -m, m}, 
{j, -m, m}, 
{k, -m, m} ] ]
(*tr= Compile[{{i, _Integer}, {j, _Integer}, {k, _Integer}}, (*If[ i^2 + j^2 + k^2≠ 0, *)
t[i, j, k]
(* ,0]*)];*)
(*ts = Compile[{{i, _Integer}, {j, _Integer}, {k, _Integer}, {m, _Integer}}, If[ (i^2 + j^2 + k^2≠ 0) && (i^2+ j^2 + k^2 ≤ m^2), 
t[i, j, k],
 0]];*)

For the cubic evaluation of the sum at m=97,98,99, we have 1.75349, 1.7417, 1.75337 respectively, whereas for the spherical evaluation of the sum we have 15.4051, -4.51377, 3.57085.  Also above are calculations of the sums for m in the range [1, 20], where for cubic and spherical evaluations we have {2.13352,1.51665,1.9125,1.61927,1.85254,1.65874,1.82454,1.67964,1.80834,1.69258,1.79777,1.70138,1.79033,1.70775,1.78481,1.71257,1.78056,1.71636,1.77717,1.7194}, and {6.,-0.866479,5.82605,-4.50869,5.24582,3.00632,9.32067,0.102809,8.41881,-6.03497,3.29762,-0.303157,1.86501,-0.847907,10.0539,-4.60154,8.14541,0.339301,-1.12987,-3.86737} respectively.  For additional discussion see the non-computed portions of the homework.