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: [mg52783] Re: multiple outputs from a function
  • From: Bill Rowe <readnewsciv at earthlink.net>
  • Date: Mon, 13 Dec 2004 04:22:37 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

On 12/11/04 at 5:22 AM, barrowes at alum.mit.edu (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:

>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?

The way I would do this is to return the results in a list.

>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:

>In[67]:= t1[x_,y_]:=(a1=x^2+y;a2=x+y^2;x+y)

Instead try

t1[x_,y_]:={x^2+y, x+y^2, x+y}
{a1,a2,t2}=t1[5,6];

t2
11

a1
31

a2
41
--
To reply via email subtract one hundred and four


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