Re: Matrix construction

• To: mathgroup at smc.vnet.net
• Subject: [mg101117] Re: Matrix construction
• From: Bill Rowe <readnews at sbcglobal.net>
• Date: Wed, 24 Jun 2009 06:34:33 -0400 (EDT)

```On 6/23/09 at 7:03 AM, yshdfeng at gmail.com (Haibo Min) wrote:

>Hi, everyone. I know that matrix can be constructed via Table or
>Array, but I want to construct a matrix from other matrices, how to
>do it? For example, suppose I would like to construct a matrix M
>which is composed of four matrices, A,B,C,D.  The element
>corresponding to the first row and the first column is A, the first
>row and second column is B... I used the M={{A,B},{C,D}} and
>M={A,B,C,D}, but both of them didn't  work. How? Thanks for advance.

=46or version 6 and later the most direct way to do this would be
to use ArrayFlatten. For example,

In[1]:= a = RandomInteger[1, {2, 2}];
b = RandomInteger[2, {2, 2}];
c = RandomInteger[3, {2, 2}];
d = RandomInteger[4, {2, 2}];

In[5]:= ArrayFlatten@{{a, b}, {c, d}}

Out[5]= {{1, 0, 0, 1}, {0, 1, 2, 0}, {2, 2, 4, 3},
{3, 3, 3, 2}}

With earlier versions of Mathematica the same result can be
obtained using Flatten as follows:

In[6]:= Flatten[{{a, b}, {c, d}}, {{1, 3}, {2, 4}}]

Out[6]= {{1, 0, 0, 1}, {0, 1, 2, 0}, {2, 2, 4, 3},
{3, 3, 3, 2}}

```

• Prev by Date: Re: For loops with mathematica....
• Next by Date: Re: Re: Putting an If in my function
• Previous by thread: Re: Matrix construction
• Next by thread: For loops with mathematica....