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 have a question regarding multiple sums. And my second index depends on the first index. Here it is:

$$ \sum_{d=1}^{P}e^{-d}\sum_{\substack{1\leq k_{1}\leq Q \\ 1\leq k_{2}\leq Q \\... \\...\\1\leq k_{d}\leq Q}}e^{-(k_{1}+...+k_{d})} $$

I could not write this sum in mathematica. The problem is that my second sum is a multiple sum and I do not know how to sum $d$ times. How can I do it?

share|improve this question
1  
See answers to this question : mathematica.stackexchange.com/questions/134/… –  Artes May 3 '12 at 14:20
add comment

2 Answers 2

Let's concentrate on the inner multiple sum. First note that we know d because it is given from the outer sum. If we want to write the expression $$-\exp\left[k_1+k_2+\ldots+k_d\right]$$ in Mathematica we could do this very easy. First we create the list {k[1],k[2],...,k[d]} and remember, that this is internally nothing more than List[k[1],k[2],...,k[d]]. If we would now replace the List head with Plus, then it is exactly what we want. For this we can use Apply which is written @@ in infix notation. That leaves how to create the {k[1],k[2],...,k[d]} list. Here we can use Table or Array or we think of it as _mapping the function k over the list {1,2,...,d}. This can be written as

k /@ Range[d]

for a known d. All together this gives

Exp[-Plus @@ k /@ Range[d]] 

Now we need to build a multiple Sum, summing over d different k. Again, this can be done in several ways. One way is to create a function which gets as arguments the indices for a Sum

f = Function[Sum[1, ##]]

I only use 1 in the sum for the sake of simplicity. You may ask now, what this ## is: it's the sequence of all arguments given to f. So lets try it:

In[63]:= {Sum[1, {3}], f[{3}]}

Out[63]= {3, 3}

In[62]:= {Sum[1, {3}, {5}], f[{3}, {5}]}

Out[62]= {15, 15}

Seems to work. The only think which is left now, is to create the ranges {k[i],1,q} where i is always a concrete number. Here we can use again the trick with Range and for a known d this gives a list of ranges:

{k[#], 1, q} & /@ Range[d] 

(* For d = 3 for instance
Out[64]= {{k[1], 1, q}, {k[2], 1, q}, {k[3], 1, q}}
*)

The last thing is to think about, that our Sum function needs a Sequence of arguments and the above is a List. But we already solved the problem of replacing the List with something different by using @@. This gives all together:

Sum[Exp[-Plus @@ k /@ Range[d]], ##] & @@ ({k[#], 1, q} & /@ Range[d])

Don't be afraid of the expression, because now you know every single piece of it and you know what every piece does. You could try it by for instance

With[{d = 4},
 Sum[Exp[-Plus @@ k /@ Range[d]], ##] & @@ ({k[#], 1, q} & /@ Range[d])
 ]

and get $$\frac{e^{-4 q} \left(e^q-1\right)^4}{(e-1)^4}$$ or you use this to plant it directly into your outer sum

mysum[p_Integer] := 
 Sum[Exp[-d]*
     Sum[Exp[-Plus @@ k /@ Range[d]], ##] & @@ ({k[#], 1, q} & /@ 
     Range[d]), {d, 1, p}]

I put it into a function mysum, because p needs to be a number to make all the Ranges work. Now you should check mysum[2]

$$\frac{e^{-2 q-2} \left(e^q-1\right)^2}{(e-1)^2}+\frac{e^{-q-1} \left(e^q-1\right)}{e-1}$$

share|improve this answer
    
How do you get $2(q^5 + q^4)$? I don't get that result with your code. –  rcollyer May 3 '12 at 15:19
    
Me neither. Wherever I copied this from.. it was the wrong place. Thanks for paying attention. –  halirutan May 3 '12 at 15:29
    
I do not understand why mathematica doesnt give the closed expression for mysum. because it seems that mysum[n] gives $x+x^2+x^3+...+x^n$ where $x$ is mysum[1] –  neticin May 3 '12 at 16:15
add comment

I'm not sure there's a way to do this symbolically, but you can do the following:

multipleSum[P_] := 
 Sum[Exp[-d] Sum[
    Exp[-Plus @@ Table[Symbol["k" <> ToString[i]], {i, 1, d}]], 
    Evaluate[
     Sequence @@ 
      Table[{Symbol["k" <> ToString[i]], 1, Q}, {i, 1, d}]]], {d, 1, 
   P}]

For example:

In[87]:= multipleSum[3]

Out[87]= (E^(-1 - Q) (-1 + E^Q))/(-1 + E) + (
 E^(-2 - 2 Q) (-1 + E^Q)^2)/(-1 + E)^2 + (
 E^(-3 - 3 Q) (-1 + E^Q)^3)/(-1 + E)^3

I think this is correct.

share|improve this answer
    
I think you missed a minus-sign in the inside exponential. –  halirutan May 3 '12 at 14:25
    
@halirutan erk, thanks: fixed –  tkott May 3 '12 at 14:26
add comment

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.