MathGroup Archive 2004

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

Search the Archive

Re: Re: Sum of list elements

  • To: mathgroup at smc.vnet.net
  • Subject: [mg49396] Re: [mg49365] Re: Sum of list elements
  • From: DrBob <drbob at bigfoot.com>
  • Date: Sat, 17 Jul 2004 06:39:20 -0400 (EDT)
  • References: <200407130923.FAA10334@smc.vnet.net> <cd35pk$qc8$1@smc.vnet.net> <cd5o9d$av7$1@smc.vnet.net> <200407161006.GAA24883@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

What's an "erraneous version"? We'd need to know what you WANT Total to do, in order to troubleshoot the behavior you're seeing. The simplest thing is something like:

Clear[total]
total[list_] := Plus @@ Flatten@list

But Total has a lot more possibilities.

Bobby

On Fri, 16 Jul 2004 06:06:48 -0400 (EDT), Per Rønne <spam at husumtoften.invalid> wrote:

> Per Rønne <spam at husumtoften.invalid> wrote:
>
>> > Total@A
>> > Total[A]
>> >
>> > Total is new in version 5.
>>
>> Yes - isn't part of Teacher's Edition. Which uses 4.1 [Classic MacOS +
>> Windows] and 4.2 [MacOS X].
>
> But now, I've put the following in my init.m file:
>
> Total[l_]:= Apply[Plus,l_]
>
> In[1]:=
> Total[{2,3}]
> Out[1]=
> 5
>
> And an erraneous version with two parameters:
>
> In[56]:= l={1,{1,2},{3,4}}
> Out[56]= {1,{1,2},{3,4}}
>
> In[65]:= Total[l_,n_]:=
>   Module[{li=l},
>     For[i=n,i>=1,i=i-1,li=Apply[Plus,li];Print[li]];
>     Return[li]]
> In[58]:= l
> Out[58]= {1,{1,2},{3,4}}
>
> In[66]:= Total[l,2]
> From In[66]:= {5,7}
> From In[66]:= 12
> Out[66]= 12
>
>



-- 
DrBob at bigfoot.com
www.eclecticdreams.net


  • Prev by Date: Re: DeleteCases : several at once, conditions
  • Next by Date: new package for custom ticks
  • Previous by thread: Re: Sum of list elements
  • Next by thread: Re: Sum of list elements