Re: Help please: Summing a list
- To: mathgroup at smc.vnet.net
- Subject: [mg13499] Re: [mg13480] Help please: Summing a list
- From: Hugh Walker <hwalker at gvtc.com>
- Date: Fri, 31 Jul 1998 04:33:17 -0400
- Sender: owner-wri-mathgroup at wolfram.com
Rob Peterson at robpetersonSPAMME 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. 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? > Hello Rob: Here is another way to set up the sum function that should work OK. P=Table[ Random [],{x , 1, 110}] ; PP[i_] := Apply [ Plus,Take[ P, i ] ] Cheers! Hugh Walker Professsor Emeritus University of Houston Gnarly Oaks