Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2006
*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 2006

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

Search the Archive

Re: Merge of Matrices

  • To: mathgroup at smc.vnet.net
  • Subject: [mg71130] Re: [mg71098] Merge of Matrices
  • From: János <janos.lobb at yale.edu>
  • Date: Thu, 9 Nov 2006 03:37:37 -0500 (EST)
  • References: <200611081115.GAA22422@smc.vnet.net>

On Nov 8, 2006, at 6:15 AM, Robert Berger wrote:

> Hello!
>
> I like to create from the four matrices A (N1 rows and N1 columns),
> B (N1 rows and N2 columns), C (N2 rows and N1 columns),
> D (N2 rows and N2 columns) a new matrix X of the form
>
>       A  B
> X =
>       C  D
>
>
> Once A & B and C & D have been merged, the first (A & B) and the
> second row (C& D) can be merged in that way by applying Join, which is
> not a problem but how can I merge A & B (and of course C & D) in
> that way?
>
> Kindly regards,
> Roman.

Here is a newbie approach:

In[1]:=
n1 = 3; n2 = 5;

In[2]:=
mA = Table[a[i, j],
    {i, 1, n1}, {j, 1, n1}]
Out[2]=
{{a[1, 1], a[1, 2], a[1, 3]},
   {a[2, 1], a[2, 2],
    a[2, 3]}, {a[3, 1],
    a[3, 2], a[3, 3]}}

In[3]:=
mB = Table[b[i, j],
    {i, 1, n1}, {j, 1, n2}]
Out[3]=
{{b[1, 1], b[1, 2], b[1, 3],
    b[1, 4], b[1, 5]},
   {b[2, 1], b[2, 2], b[2, 3],
    b[2, 4], b[2, 5]},
   {b[3, 1], b[3, 2], b[3, 3],
    b[3, 4], b[3, 5]}}

In[4]:=
mC = Table[c[i, j],
    {i, 1, n2}, {j, 1, n1}]
Out[4]=
{{c[1, 1], c[1, 2], c[1, 3]},
   {c[2, 1], c[2, 2],
    c[2, 3]}, {c[3, 1],
    c[3, 2], c[3, 3]},
   {c[4, 1], c[4, 2],
    c[4, 3]}, {c[5, 1],
    c[5, 2], c[5, 3]}}

In[5]:=
mD = Table[d[i, j],
    {i, 1, n2}, {j, 1, n2}]
Out[5]=
{{d[1, 1], d[1, 2], d[1, 3],
    d[1, 4], d[1, 5]},
   {d[2, 1], d[2, 2], d[2, 3],
    d[2, 4], d[2, 5]},
   {d[3, 1], d[3, 2], d[3, 3],
    d[3, 4], d[3, 5]},
   {d[4, 1], d[4, 2], d[4, 3],
    d[4, 4], d[4, 5]},
   {d[5, 1], d[5, 2], d[5, 3],
    d[5, 4], d[5, 5]}}

In[6]:=
mAB = Table[Join[mA[[i]],
     mB[[i]]], {i, Length[mA]}]
Out[6]=
{{a[1, 1], a[1, 2], a[1, 3],
    b[1, 1], b[1, 2], b[1, 3],
    b[1, 4], b[1, 5]},
   {a[2, 1], a[2, 2], a[2, 3],
    b[2, 1], b[2, 2], b[2, 3],
    b[2, 4], b[2, 5]},
   {a[3, 1], a[3, 2], a[3, 3],
    b[3, 1], b[3, 2], b[3, 3],
    b[3, 4], b[3, 5]}}

In[7]:=
mCD = Table[Join[mC[[i]],
     mD[[i]]], {i, Length[mC]}]
Out[7]=
{{c[1, 1], c[1, 2], c[1, 3],
    d[1, 1], d[1, 2], d[1, 3],
    d[1, 4], d[1, 5]},
   {c[2, 1], c[2, 2], c[2, 3],
    d[2, 1], d[2, 2], d[2, 3],
    d[2, 4], d[2, 5]},
   {c[3, 1], c[3, 2], c[3, 3],
    d[3, 1], d[3, 2], d[3, 3],
    d[3, 4], d[3, 5]},
   {c[4, 1], c[4, 2], c[4, 3],
    d[4, 1], d[4, 2], d[4, 3],
    d[4, 4], d[4, 5]},
   {c[5, 1], c[5, 2], c[5, 3],
    d[5, 1], d[5, 2], d[5, 3],
    d[5, 4], d[5, 5]}}

In[8]:=
mABCD = Transpose[
    Table[Join[mAB[[All,i]],
      mCD[[All,i]]],
     {i, Length[mAB[[1]]]}]]
Out[8]=
{{a[1, 1], a[1, 2], a[1, 3],
    b[1, 1], b[1, 2], b[1, 3],
    b[1, 4], b[1, 5]},
   {a[2, 1], a[2, 2], a[2, 3],
    b[2, 1], b[2, 2], b[2, 3],
    b[2, 4], b[2, 5]},
   {a[3, 1], a[3, 2], a[3, 3],
    b[3, 1], b[3, 2], b[3, 3],
    b[3, 4], b[3, 5]},
   {c[1, 1], c[1, 2], c[1, 3],
    d[1, 1], d[1, 2], d[1, 3],
    d[1, 4], d[1, 5]},
   {c[2, 1], c[2, 2], c[2, 3],
    d[2, 1], d[2, 2], d[2, 3],
    d[2, 4], d[2, 5]},
   {c[3, 1], c[3, 2], c[3, 3],
    d[3, 1], d[3, 2], d[3, 3],
    d[3, 4], d[3, 5]},
   {c[4, 1], c[4, 2], c[4, 3],
    d[4, 1], d[4, 2], d[4, 3],
    d[4, 4], d[4, 5]},
   {c[5, 1], c[5, 2], c[5, 3],
    d[5, 1], d[5, 2], d[5, 3],
    d[5, 4], d[5, 5]}}

János


----------------------------------------------
Trying to argue with a politician is like lifting up the head of a  
corpse.
(S. Lem: His Master Voice)


  • Prev by Date: Re: Evaluating integral with varying upper limit?
  • Next by Date: Re: Factor.....
  • Previous by thread: Re: Merge of Matrices
  • Next by thread: Merge of Matrices