MathGroup Archive 2004

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

Search the Archive

RE: Using "Sum" (i = 1 ... N) in a function definition

  • To: mathgroup at
  • Subject: [mg49692] RE: [mg49666] Using "Sum" (i = 1 ... N) in a function definition
  • From: "Ellis, George" <George.Ellis at Cognos.COM>
  • Date: Thu, 29 Jul 2004 07:42:56 -0400 (EDT)
  • Sender: owner-wri-mathgroup at


I do not know why you would want to do this; so my response below may be
off target.  Nonetheless, what about this?  (The function "Total" in
version 5.0, in this case, provides the equivalent functionality -- as
would "Apply[Plus,data]" in earlier versions).

In[10]:=  (8:59:39 on 7/27/04)

Out[11]=  (8:59:39 on 7/27/04)

In[9]:=  (8:59:21 on 7/27/04)

Out[9]=  (8:59:21 on 7/27/04)


-----Original Message-----
From: Rainer [mailto:wilhelm.rainer at] 
To: mathgroup at
Subject: [mg49692] [mg49666] Using "Sum" (i = 1 ... N) in a function definition

I was trying to define a function using the Sum command in the following
way (simplified example):

 MyData = {3,2,4,5,6};
 MyFunc[i_] = Sum[MyData[[j]],{j,1,i}];

As you can see, the idea is to use the length of the list (i) as a
variable in the function definition, such that

 MyFunc[1] = 3
 MyFunc[2] = 3 + 2 = 5
 MyFunc[3] = 3 + 2 + 4 = 9

etc. Mathematica does not like the abobe statements, and prints the
following error message:

"Part specification K$394 is neither an integer nor a list of integers."

Does anybody know how to define (correctly) such a function. Should be
possible ...?
       This message may contain privileged and/or confidential information.  If you have received this e-mail in error or are not the intended recipient, you may not use, copy, disseminate or distribute it; do not open any attachments, delete it immediately from your system and notify the sender promptly by e-mail that you have done so.  Thank you. 

  • Prev by Date: RE: Q: extract all k-tuple from a list of n elements
  • Next by Date: Re: Fibonacci[1,000,000,000] contains 208,987,640 decimal digits
  • Previous by thread: Re: Using "Sum" (i = 1 ... N) in a function definition
  • Next by thread: Re: extract all k-tuple from a list of n elements