Wolfram Research

BlockDiagonalMatrix

Contributed by: Bob Sandheinrich

Source Notebook

Create a block-diagonal matrix from submatrices

ResourceFunction["BlockDiagonalMatrix"][m1,m2,]

constructs a matrix with submatrices mi on the diagonal.

Details and Options

The submatrices miare included in the specified order.
The submatrices need not be square.
{} and {{}} are treated as 0x0 submatrices.

Examples

Basic Examples

Create a block-diagonal matrix from three matrices:

In[1]:=
ResourceFunction[
  "BlockDiagonalMatrix"][{{1, 2}, {3, 4}}, {{5}}, {{6}}] // MatrixForm
Out[1]=

Use non-square matrices:

In[2]:=
ResourceFunction[
  "BlockDiagonalMatrix"][{{1, 2}}, {{3}, {4}}] // MatrixForm
Out[2]=

Scope

Empty lists are treated a zero-dimensional matrices:

In[3]:=
ResourceFunction["BlockDiagonalMatrix"][{}, DiagonalMatrix[{1, 2, 3}]] // MatrixForm
Out[3]=

Properties and Relations

The dimensions of the result are the sum of the dimensions of the submatrices:

In[4]:=
m1 = {{1, 2, 3}, {4, 5, 6}};
m2 = DiagonalMatrix[{a, b, c}]; block = ResourceFunction["BlockDiagonalMatrix"][m1, m2]
Out[5]=
In[6]:=
Dimensions[block]
Out[6]=
In[7]:=
Plus @@ Dimensions /@ {m1, m2}
Out[7]=

Resource History