1

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.:

blocks

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

augmented

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?

Peeter Joot
  • 6,398
  • 4
  • 36
  • 55

1 Answers1

3
Join[b, i, 2]

ArrayFlatten[{{b, i}}]

ArrayPad[b, {{0}, {0, 2}}, i]

MapThread[Join, {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
kglr
  • 394,356
  • 18
  • 477
  • 896