Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2004
*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 2004

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

Search the Archive

Re: multiple outputs from a function

  • To: mathgroup at smc.vnet.net
  • Subject: [mg52802] Re: [mg52753] multiple outputs from a function
  • From: "David Annetts" <davidannetts at ihug.com.au>
  • Date: Mon, 13 Dec 2004 04:23:23 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

Hi Ben,

> 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:
> 
> f[x_,y_]:=x^2+y^2;
> 
> which have only a single result.
> 
> Is there a different structure altogether, such as a 
> Subroutine, which allows multiple results from a single subunit?

Why not define your function

Needs["Statistics`"] (* to be safe ...*)
stats[x_List] := Module[
{local variables},

(* function body *)

Return[{mean, variance, std}];
];

Ie. A function that accepts a list and returns another list.  The return
list has three elements, mean variance & std deviation of the original list.
Rephrasing this

mean = First[stats[yourList]];
var = stats[yourList][[2]];
std = Last[stats[yourList]];

Regards,

Dave.

-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.296 / Virus Database: 265.5.0 - Release Date: 9/12/2004
 


  • Prev by Date: Re: Sorting question
  • Next by Date: Solve Feature?
  • Previous by thread: Re: multiple outputs from a function
  • Next by thread: Re: Re: multiple outputs from a function