Re: Re: multiple outputs from a function
- To: mathgroup at smc.vnet.net
- Subject: [mg52842] Re: [mg52802] Re: [mg52753] multiple outputs from a function
- From: DrBob <drbob at bigfoot.com>
- Date: Tue, 14 Dec 2004 05:59:55 -0500 (EST)
- References: <200412130923.EAA23502@smc.vnet.net>
- Reply-to: drbob at bigfoot.com
- Sender: owner-wri-mathgroup at wolfram.com
Return is almost never needed, certainly not in this kind of function:
stats[x_List] := Module[{local variables},
(* function body *);
{mean, variance, std}
];
Bobby
On Mon, 13 Dec 2004 04:23:23 -0500 (EST), David Annetts <davidannetts at ihug.com.au> wrote:
>
>
> 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.
>
--
DrBob at bigfoot.com
www.eclecticdreams.net
- References:
- Re: multiple outputs from a function
- From: "David Annetts" <davidannetts@ihug.com.au>
- Re: multiple outputs from a function