MathGroup Archive 1998

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

Search the Archive

Re: Help please: Summing a list

  • To: mathgroup at smc.vnet.net
  • Subject: [mg13501] Re: Help please: Summing a list
  • From: Paul Abbott <paul at physics.uwa.edu.au>
  • Date: Fri, 31 Jul 1998 04:33:18 -0400
  • Organization: University of Western Australia
  • References: <6pebm8$i6j@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

robpeterson at iname.com wrote:
 
> I make a list of numbers, eg:
> 
> P=Table[6,{x,0,110}]; (I have a more interesting list to use later if I
> get this working)
> 
> Now I want to make another list PP in which each entry PP[[i]] is the
> sum of P's first i entries. 

For the list (it is safer to use lower-case variables),

In[1]:= p = Table[6, {x, 0, 10}]; 

FoldList is probably the easiest (and fastest) operator for producing
the list of cumulative sums:

In[2]:= FoldList[Plus, First[P], Rest[P]];

Out[2]= {6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66}

Cheers,
	Paul 
 
____________________________________________________________________ 
Paul Abbott                                   Phone: +61-8-9380-2734
Department of Physics                           Fax: +61-8-9380-1014
The University of Western Australia            Nedlands WA  6907       
mailto:paul at physics.uwa.edu.au  AUSTRALIA                            
http://www.pd.uwa.edu.au/~paul

            God IS a weakly left-handed dice player
____________________________________________________________________


  • Prev by Date: Does Mathematica speed up with multiple processors under NT?
  • Next by Date: Re: abcd-matrix for lens-systems
  • Previous by thread: Re: Help please: Summing a list
  • Next by thread: Re: Help please: Summing a list