11

I have four matrices

m = {{M11, M12, M13}, {M21, M22, M23}, {M31, M32, M33}};
n = {{N11, N12, N13}, {N21, N22, N23}, {N31, N32, N33}};
p = {{P11, P12, P13}, {P21, P22, P23}, {P31, P32, P33}};
q = {{Q11, Q12, Q13}, {Q21, Q22, Q23}, {Q31, Q32, Q33}};

and i want to construct the following

ArrayFlatten[Table[{{m[[k1, k2]], n[[k1, k2]]}, {p[[k1, k2]], q[[k1, k2]]}}, {k1,1, 3}, {k2, 1, 3}]]

 {{M11, N11, M12, N12, M13, N13},
  {P11, Q11, P12, Q12, P13, Q13},
  {M21, N21, M22, N22, M23, N23},
  {P21, Q21, P22, Q22, P23, Q23},
  {M31, N31, M32, N32, M33, N33},
  {P31, Q31, P32, Q32, P33, Q33}}

There is a more elegant and rapid way to this thing?

Kowalski
  • 437
  • 2
  • 7

2 Answers2

14

I would use Flatten:

m = {{M11, M12, M13}, {M21, M22, M23}, {M31, M32, M33}};
n = {{N11, N12, N13}, {N21, N22, N23}, {N31, N32, N33}};
p = {{P11, P12, P13}, {P21, P22, P23}, {P31, P32, P33}};
q = {{Q11, Q12, Q13}, {Q21, Q22, Q23}, {Q31, Q32, Q33}};

Flatten[{{m, n}, {p, q}}, {{3, 1}, {4, 2}}] //TeXForm

$\begin{pmatrix} \text{M11} & \text{N11} & \text{M12} & \text{N12} & \text{M13} & \text{N13} \\ \text{P11} & \text{Q11} & \text{P12} & \text{Q12} & \text{P13} & \text{Q13} \\ \text{M21} & \text{N21} & \text{M22} & \text{N22} & \text{M23} & \text{N23} \\ \text{P21} & \text{Q21} & \text{P22} & \text{Q22} & \text{P23} & \text{Q23} \\ \text{M31} & \text{N31} & \text{M32} & \text{N32} & \text{M33} & \text{N33} \\ \text{P31} & \text{Q31} & \text{P32} & \text{Q32} & \text{P33} & \text{Q33} \\ \end{pmatrix}$

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
Carl Woll
  • 130,679
  • 6
  • 243
  • 355
3
♮ = ## & @@@ (#) &@(## & @@@ (#) & /@ (#) & /@ {##}) &;

Mathematica graphics

♮[{m, n}, {p, q}] // MatrixForm

Mathematica graphics

kglr
  • 394,356
  • 18
  • 477
  • 896