Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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