# Is there a more natural way to create matrix from consituitve blocks?

I have a matrix that I'd like to augment with identity:

b = {{1, 1, 1, 1}, {1, -1, 1, -1}}.DiagonalMatrix[{1, -1, -1, -1}];
i = DiagonalMatrix[{1, 1}];
b // MatrixForm
i // MatrixForm


i.e.:

I was able to combine these compatible block matrixes with the following mess:

xx = Flatten[{b, i} // Transpose , 2];
yy = {xx[[1 ;; 6]], xx[[7 ;; 12]]} ;
yy // MatrixForm


This seems very perverse. I found ArrayFlatten mentioned in https://mathematica.stackexchange.com/a/164897/10, which looked promising, but had trouble adapting it to my simple case.

How would construction of a matrix from blocks such as these be done in a less horrific fashion?

Join[b, i, 2]

ArrayFlatten[{{b, i}}]



all give

 {{1, -1, -1, -1, 1, 0}, {1, 1, -1, 1, 0, 1}}

 TeXForm @ MatrixForm @ %


$$\left( \begin{array}{cccccc} 1 & -1 & -1 & -1 & 1 & 0 \\ 1 & 1 & -1 & 1 & 0 & 1 \\ \end{array} \right)$$

Note: You can use IdentityMatrix[2] for i:

i == IdentityMatrix[2]

 True

• Thanks. I needed an extra set of braces in my ArrayFlatten attempt! Nov 11, 2020 at 0:47