MathGroup Archive 2004

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

Search the Archive

List arguments to functions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg45537] List arguments to functions
  • From: Chris Rozell <crozell at rice.edu>
  • Date: Tue, 13 Jan 2004 04:03:52 -0500 (EST)
  • Organization: Rice University, Houston, TX
  • Sender: owner-wri-mathgroup at wolfram.com

I have basic experience with Mathematica, but this problem has stumped 
me for the last day or so.  Any help would be appreciated.

I have a function that needs to take two lists as arguments, perform 
operations on them, and then sum the resulting list.  However, by 
including the Plus function, it operates on each list item separately 
(which is exactly the opposite of what I need.  For a simple example,

 >myfunc[x_, y_] = Apply[Plus, x + y];
 >myfunc[{1, 2, 3}, {4, 5, 6}]
 >
 >{5, 7, 9}

When what I would really like is the number 21 (i.e., 5+7+9, perform the 
list addition first, then sum the components).  In this simple example I 
could perform the summation after the function returns, but in my real 
problem this would not be possible.

When reading the documentation, it appears that the Plus function 
behaves this way because it has the attribute "Flat".  But even after 
removing that attribute it still behaves in the same way, so I may be 
misunderstanding the description of "flat".  Can anyone suggest a way to 
either modify the Plus function behavior, or do this another way?  Thank 
you in advance!


  • Prev by Date: FW: Re: Wishart Distribution
  • Next by Date: Re: composing functions
  • Previous by thread: Re: Re: hyperlink to pdf files
  • Next by thread: Re: List arguments to functions