       Re: How to define a routine to return multiple values

• To: mathgroup at smc.vnet.net
• Subject: [mg49971] Re: [mg49939] How to define a routine to return multiple values
• From: "David Park" <djmp at earthlink.net>
• Date: Sun, 8 Aug 2004 05:37:59 -0400 (EDT)
• Sender: owner-wri-mathgroup at wolfram.com

```Xun,

Easy, just return a list or array. Here is a simple example that
premultiplies an input matrix by a constant built-in matrix and returns a
matrix.

matmultiply[mat_?MatrixQ] /; Dimensions[mat] == {3, 3} :=
With[{constantmatrix = {{1, 0, 0}, {0, 0, 1}, {0, 1, 0}}},
constantmatrix.mat]

testmat = {{a, b, c}, {d, e, f}, {g, h, i}};
matmultiply[testmat]
{{a, b, c}, {g, h, i}, {d, e, f}}

You really don't have to do anything special. You can calculate and return
any kind of Mathematica expression.

David Park

From: Xiaoxun [mailto:dbjunxiao at hotmail.com]
To: mathgroup at smc.vnet.net

Dear Group,

In Mathematica, how to generate a function to return
multiple values simutaneously, for example, to return
a 3 by 3 tensor. Just as subroutine in Fortran..