Re: Multiple Sums in Mathematica

• To: mathgroup at smc.vnet.net
• Subject: [mg53704] Re: [mg53696] Multiple Sums in Mathematica
• From: Bob Hanlon <hanlonr at cox.net>
• Date: Mon, 24 Jan 2005 03:37:25 -0500 (EST)
• Sender: owner-wri-mathgroup at wolfram.com

```Presumably, you intend f to be a function of the indices.

multiSum[f_, n_Integer, maxIndex_:M, index_String:"i"]  :=
Module[{var,k},
var=ToExpression[Table[index<>ToString[k],{k,n}]];
Fold[Sum[#1,{#2,1,maxIndex}]&,
f[Sequence@@var],Reverse[var]]];

multiSum[f,3]

Sum[f[i1, i2, i3], {i1, 1, M}, {i2, 1, M}, {i3, 1, M}]

multiSum[f,3,r]

Sum[f[i1, i2, i3], {i1, 1, r}, {i2, 1, r}, {i3, 1, r}]

multiSum[f,3,M,"k"]

Sum[f[k1, k2, k3], {k1, 1, M}, {k2, 1, M}, {k3, 1, M}]

Bob Hanlon

>
> From: sbrandt at physics.wustl.edu (Sebastian Brandt)
To: mathgroup at smc.vnet.net
> Date: 2005/01/23 Sun AM 02:02:26 EST
> To: mathgroup at smc.vnet.net
> Subject: [mg53704] [mg53696] Multiple Sums in Mathematica
>
> Hello,
>
> I want to perform a nested sum, where the number of summations is not
> specified. I.e., I am looking for a way to implement the sum
>
> sum[ f, {i1, 1, M}, {i2, 1, M}, ..., {in, 1, M} ]
>
> Does anbody know how to do this for arbitrary n?
>
> Regards,
>
> Sebastian Brandt
>
>

```

• Prev by Date: Re: Problems with ExtendGraphics/Delaunay Triangulation
• Next by Date: Re: Numbers and their reversals
• Previous by thread: Re: Multiple Sums in Mathematica
• Next by thread: Re: Multiple Sums in Mathematica