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

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

Search the Archive

Re: I'm looking for an algorithm: Cartesian Product

  • To: mathgroup at christensen.cybernetics.net
  • Subject: [mg1672] Re: I'm looking for an algorithm: Cartesian Product
  • From: rubin at msu.edu (Paul A. Rubin)
  • Date: Tue, 11 Jul 1995 05:27:18 -0400
  • Organization: Michigan State University

In article <3ti27l$klt at news0.cybernetics.net>,
   Hala.Skaf at loria.fr (Hala Skaf) wrote:
->
->Hello,
->
->     I'm looking for an algorithm that can compute 
-> Cartesian Product for several sets. For example:
->
-> How can I compute the Cartesian Product of:
->
->	E1={a1 a2} E2={b1 b2 b3} E3={z1 z2}
->
->        Cartesian Product is:
->
->	E1 x E2 x E3 = 
->	     {
->		<a1 b1 z1>, <a1 b1 z2>,
->		<a1 b2 z1>, <a1 b2 z2>,	
->        	<a1 b3 z1>, <a1 b3 z2>,
->		<a2 b1 z1>, <a2 b1 z2>,
->		<a2 b2 z1>, <a2 b2 z2>,	
->        	<a2 b3 z1>, <a2 b3 z2>
->	     }
->
->   Thank's in advance for your Quickly Help.
->
->
->   Hala :-),
->

You can do it with Outer[].

In[]:=  E1={a1, a2}; E2={b1, b2, b3}; E3={z1, z2};
In[]:=  Outer[ List, E1, E2, E3 ] // TableForm
Out[]=  
	a1 b1 z1   a1 b2 z1   a1 b3 z1
        a1 b1 z2   a1 b2 z2   a1 b3 z2

Paul


a2 b1 z1   a2 b2 z1   a2 b3 z1
a2 b1 z2   a2 b2 z2   a2 b3 z2

**************************************************************************
* Paul A. Rubin                                  Phone: (517) 432-3509   *
* Department of Management                       Fax:   (517) 432-1111   *
* Eli Broad Graduate School of Management        Net:   RUBIN at MSU.EDU    *
* Michigan State University                                              *
* East Lansing, MI  48824-1122  (USA)                                    *
**************************************************************************
Mathematicians are like Frenchmen:  whenever you say something to them,
they translate it into their own language, and at once it is something
entirely different.                                    J. W. v. GOETHE


  • Prev by Date: Re: Problems with NIntegrate
  • Next by Date: Re: Printing Problem
  • Previous by thread: Re: I'm looking for an algorithm: Cartesian Product
  • Next by thread: Re: I'm looking for an algorithm: Cartesian Product