2
$\begingroup$

I need to do summation of this function with Mathematica.

For[t=0,t<500,t++;Sum[-Q*Log[Q],{k,-Infinity,Infinity},{n,-Infinity,Infinity}]]

Q= Q1+Q2+Q3

where

Q1= 1/(Sqrt[(0.2+ 0.2 k)^2] Sqrt[
  k^2]) ((0.0220725+ 0.0220725 k) Sqrt[k^2]
     Erf[Sqrt[(0.2+ 0.2 k)^2]] - 
   0.110363 Sqrt[(0.2+ 0.2 k)^2]
     k Erf[0.2 Sqrt[k^2]]) (0.886227 Erf[0.8 E^(-0.0004 t) - 0.2 n] + 
   0.886227 Erf[0.2- 0.8 E^(-0.0004 t) + 0.2 n])

Q2=1/(Sqrt[(0.2+ 0.2 k)^2] Sqrt[
  k^2]) ((0.0220725+ 0.0220725 k) Sqrt[k^2]
     Erf[Sqrt[(0.2+ 0.2 k)^2]] - 
   0.110363 Sqrt[(0.2+ 0.2 k)^2]
     k Erf[0.2 Sqrt[k^2]]) (-0.886227 Erf[
     0.8 E^(-0.0004 t) + 0.2 n] + 
   0.886227 Erf[0.2+ 0.8 E^(-0.0004 t) + 0.2 n])

Q3=(Erf[0.2+ 0.2 n] - 
   1. Erf[0.2 n]) (0.0271938 Erf[(0.2+ 
        0. I) - (0.\[VeryThinSpace]+ 0.8 I) Sqrt[
       E^(-0.0004 t)] + (0.2+ 0. I) k] + 
   0.0271938 Erf[(0.2+ 
        0. I) + (0.+ 0.8 I) Sqrt[
       E^(-0.0004 t)] + (0.2+ 
         0. I) k] - (0.+ 0.0271938 I) Erfi[
     0.8 Sqrt[
       E^(-0.0004 t)] - (0.+ 
         0.2 I) k] + (0.+ 0.0271938 I) Erfi[
     0.8 Sqrt[E^(-0.0004 t)] + (0.+ 0.2 I) k])

The problem is because Q cannot be defined at certain k,Sum cannot be done. (For example, when I try to sum Sum[-Q*Log[Q],{n,-55,55},{k,-55,55}] at t=0, the error message is "Power::infy: "Infinite expression 1/Sqrt[0] encountered", "indet: Indeterminate expression 0.ComplexInfinity encountered."

Is there a way that i can sum except the points where -Q*Log[Q] cannot be defined?

Thanks.

$\endgroup$

1 Answer 1

1
$\begingroup$

Since the sum is from -Infinity to +Infinity it will have to be computed algebraically, so you cannot intercept the errors like so :-

Sum[If[NumberQ[#], #, 0] &@Chop[-Q*Log[Q]],
  {k, -Infinity, Infinity}, {n, -Infinity, Infinity}];

One source of error is, for instance, in Q1, when k = 1 ...

1/(Sqrt[(0.2 + 0.2 k)^2] Sqrt[k^2])

the denominator is zero.

You can avoid this problem by summing without k = 1 :-

a1 = Sum[-Q*Log[Q], {k, -3, 0}, {n, -3, 3}];
a2 = Sum[-Q*Log[Q], {k, 2, 3}, {n, -3, 3}];
ans = a1 + a2

However, k = 1 is not the only problematic input. You may be able to identify the others and exclude them from the summation.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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