Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1998

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

Search the Archive

Re: Help please: Summing a list

  • To: mathgroup at
  • Subject: [mg13501] Re: Help please: Summing a list
  • From: Paul Abbott <paul at>
  • Date: Fri, 31 Jul 1998 04:33:18 -0400
  • Organization: University of Western Australia
  • References: <6pebm8$>
  • Sender: owner-wri-mathgroup at

robpeterson at 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}

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  AUSTRALIA                   

            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