Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2004

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

Search the Archive

Re: multiple outputs from a function

  • To: mathgroup at
  • Subject: [mg52785] Re: [mg52753] multiple outputs from a function
  • From: yehuda ben-shimol <benshimo at>
  • Date: Mon, 13 Dec 2004 04:22:40 -0500 (EST)
  • References: <>
  • Sender: owner-wri-mathgroup at

A function can return only one expression.
In order to use an expression that holds several results it should be a 
List (not necessarily, but a common practice)
So, for a function f operating on a list of data elements use something 
similar to
f[mydata_List]:={Mean[mydata], Var[mydata], Sqrt/@mydata, ...... (*as 
many as you wish*) }


Ben Barrowes wrote:

>I feel I must be missing something fundamental...
>How do you write a function (or ?) in Mathematica which produces more 
>than one output?
>Let's say I have some data and I want a single function to calculate the 
>mean, variance, std, etc, more than one thing and return those? I know 
>that there are builtin functions for those parameters, but the point is 
>I want to define functions with more than one output.
>The only examples I can find are along the lines of:
>which have only a single result.
>Is there a different structure altogether, such as a Subroutine, which 
>allows multiple results from a single subunit?
>One thought I had was that because Mathematica treats everything as 
>global unless defined specifically local (e.g. in a module), that 
>variables used in a procedure would be accessible and would thus be a 
>"result", but it seems scoping problems would arise if this was used too 
>often. For example:
>Is this the accepted method for extracting multiple results from one 
>function definition?
>Ben Barrowes

  • Prev by Date: Re: Using LevenbergMarquardt Method with a complicated function
  • Next by Date: Re: multiple outputs from a function
  • Previous by thread: Re: multiple outputs from a function
  • Next by thread: Re: multiple outputs from a function