Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1998
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*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 smc.vnet.net
  • Subject: [mg13507] Re: [mg13480] Help please: Summing a list
  • From: "Jens-Peer Kuska" <kuska at linmpi.mpg.de>
  • Date: Fri, 31 Jul 1998 04:33:23 -0400
  • Sender: owner-wri-mathgroup at wolfram.com

Hi Rob,


>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}];


a) Mathematica List[]s index starts with 1, Part[any,0] gives the head.
So Your summation
   must be
      Sum[P[[n]],{n,1,i}]

b) What do You want ? A function PP[i_] ? that calculates the sums ?
    Here is a possible solution

   PP[i_]:=PP[i]=Module[{n},Sum[P[[n]],{n,1,i}]]

  or the recursive one

  PP[1]:=P[[1]]
  PP[i_ /; i>1]:=PP[i]=P[[i]]+PP[i-1]

 Notice that this definition does not calculate the sums. But if You say
PP[4] You will
 get the value.

 Or do You want that PP is a list containing the accumulated sums ?

  PPList = Table[Plus @@ Drop[#1,n] &[P],{n,-10,0}]

or using the defined PP[]-Function

PPList=Table[PP[i],{i,1,11}]

Hope that helps
  Jens



  • Prev by Date: Help on Mathematica 2.2 on Intel MMX
  • Next by Date: Re: Install[] and command line args?
  • Previous by thread: Re: Help please: Summing a list
  • Next by thread: Re: Help please: Summing a list