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: [mg13492] Re: Help please: Summing a list
  • From: "Allan Hayes" <hay at haystack.demon.cc.uk>
  • Date: Fri, 31 Jul 1998 04:33:13 -0400
  • References: <6pebm8$i6j@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

robpetersonSPAMME at iname.com wrote in message <6pebm8$i6j at smc.vnet.net>...
>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.  I try
>
>PP[[i]]:=Sum[P[[n]],{n,0,i}];
>
>At the definition, I get the following error: Part::"pspec":
>    "Part specification \!\(n\) is neither an integer nor a list of
>integers."
>
>I don't know how to make n an integer.  In the definition of Sum[], it
>seems n is an integer unless you add a forth parameter "di" in the
>specification list such as
>Sum[f, {i, imin, imax, di}]
>
>Can anyone help me to generate this second list?
>
>Thanks, Rob
>

Rob:

lst = {a,b,c,d,e};

FoldList[Plus, 0, lst]
{0,a,a+b,a+b+c,a+b+c+d,a+b+c+d+e}

Rest[%]
{a,a+b,a+b+c,a+b+c+d,a+b+c+d+e}

Please note that in order to use a definition like
PP[[i]]:=Sum[P[[n]],{n,0,i}]

PP must have already been define in the fashion PP = ... (notPP:=..) as
having the appropriate number of elements.

Allan

------------------------------------------------------------- Allan
Hayes
Training and Consulting
Leicester UK
http://www.haystack.demon.co.uk
hay at haystack.demon.co.uk
voice: +44 (0)116 271 4198
fax: +44(0)116 271 8642






  • Prev by Date: displaying animation grahps in one place
  • Next by Date: Re:Help please: Summing a list
  • Previous by thread: Re: Help please: Summing a list
  • Next by thread: Re:Help please: Summing a list