MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Re: Multiple Sums in Mathematica

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

Clear[f];

f[x__] := Module[{xl=Flatten[{x}]},
      Times@@(Tr /@ 
            ({#,Range[Length[xl]]*#,#!,Table[C[k],{k,Length[xl]}]^#}&[xl]))];

f[i1,i2,i3]

(i1 + i2 + i3)*(i1 + 2*i2 + 3*i3)*(C[1]^i1 + C[2]^i2 + 
   C[3]^i3)*(i1! + i2! + i3!)

It also works when the argument is a list instead of a sequence

f[{i1,i2,i3,i4}]

(i1 + i2 + i3 + i4)*(i1 + 2*i2 + 3*i3 + 4*i4)*
  (C[1]^i1 + C[2]^i2 + C[3]^i3 + C[4]^i4)*
  (i1! + i2! + i3! + i4!)


Bob Hanlon

> 
> From: Sebastian Brandt <sbrandt at physics.wustl.edu>
To: mathgroup at smc.vnet.net
> Date: 2005/01/24 Mon PM 09:19:09 EST
> To: hanlonr at cox.net
> Subject: [mg53733] Re: [mg53696] Multiple Sums in Mathematica
> 
> Dear Bob Hanlon,
> 
> Thank you very much for your help! Your code works fine, but now I have 
the (for you probably trivial) problem of how to define f as a function of an 
arbitrary number of arguments.
> 
> For example, f is supposed to be something like this:
> 
> f[i1_, i2_, i3_, ..., iM_] = 
> 
>    (i1 + i2 + .... + iM) 
> *  (1*i1 + 2*i2 + ... + M*iM) 
> *  (i1! + i2! + i3! + ... + iM!)
> *  (C[1]^i1 * C[2]^i2 * ... * C[M]^iM)
> 
> In the last part, the C[1], C[2], ..., C[M] are some constants.
> 
> Sorry for bothering you with this question, but I would really appreciate it if 
you could help me once more.
> 
> Regards,
> 
> Sebastian
> 
> -------------------------------------------------
> Sebastian Brandt                        
> -------------------------------------------------
> Physics Department, CB 1105
> Washington University
> 1 Brookings Drive
> St. Louis, MO 63130-4899, USA
> -------------------------------------------------
> +1-314-935-7507 (phone)
> +1-314-935-6219 (fax)
> sbrandt at physics.wustl.edu
> -------------------------------------------------
> 
> ----- Original Message -----
> From: Bob Hanlon <hanlonr at cox.net>
To: mathgroup at smc.vnet.net
> Date: Sunday, January 23, 2005 8:20 am
> Subject: [mg53733] Re: [mg53696] Multiple Sums in Mathematica
> 
> > 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: [mg53733] [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: NDSolve/InterpolatingFunction and vectors
  • Next by Date: Re: Superellisoid
  • Previous by thread: Re: Multiple Sums in Mathematica
  • Next by thread: Re: Multiple Sums in Mathematica