Function Repository Resource:

MatrixFormDivided

Source Notebook

Add row and column dividing lines to MatrixForm

Contributed by: Gustavo Delfino

ResourceFunction["MatrixFormDivided"][m,step]

returns a MatrixForm of matrix m with divider lines every step columns and rows.

ResourceFunction["MatrixFormDivided"][m,{xstep,ystep}]

use different step specifications for colums and rows.

ResourceFunction["MatrixFormDivided"][m,{{s1,s2,,sn}}]

uses divider lines with specified sizes s where each si represents a number of columns and rows.

ResourceFunction["MatrixFormDivided"][m,{{sx1,sx2,,sxn},{sy1,sy2,,syn}}]

uses diferent divider lines specific spacings for rows and columns.

ResourceFunction["MatrixFormDivided"][spec]

represents an operator form of ResourceFunction["MatrixFormDivided"] that can be applied to a matrix.

Details and Options

ResourceFunction["MatrixFormDivided"] takes the option "DividersOffset", which specifies the offset used for the dividers. This can be an integer or a list of two integers representing different row and column offsets.

Examples

Basic Examples (3) 

Place divider lines at every second column and row:

In[1]:=
ResourceFunction["MatrixFormDivided"][IdentityMatrix[8], 2]
Out[1]=

Place divider lines at every third column and row:

In[2]:=
ResourceFunction["MatrixFormDivided"][IdentityMatrix[9], 3]
Out[2]=

Use the operator form on a rectangular matrix:

In[3]:=
IdentityMatrix[{3, 6}] // ResourceFunction["MatrixFormDivided"][3]
Out[3]=
In[4]:=
Transpose[Riffle[IdentityMatrix[4], IdentityMatrix[4]]] // ResourceFunction["MatrixFormDivided"][{2, 1}]
Out[4]=

Using copy/paste or evaluate in place, it is possible to use MatrixFormDivided as part of input. This cannot be done with a Grid:

In[5]:=
VerificationTest[\!\(\*
TagBox[
SqrtBox[
RowBox[{"(", GridBox[{
{"4", "0", "0", "0"},
{"0", "4", "0", "0"}
},
GridBoxDividers->{"Columns" -> {False, False, {True, False}, False}, "Rows" -> {False, False, {True, False}, False}}], ")"}]],
DisplayForm]\), ( {
   {2, 0, 0, 0},
   {0, 2, 0, 0}
  } )]
Out[5]=

Scope (3) 

The structure of composed matrices can be highlighted by using divider lines:

In[6]:=
m = ConstantArray[1, {2, 2}];
ArrayFlatten[{{m, m, m}, {0, m, m}, {0, 0, m}}] // ResourceFunction["MatrixFormDivided"][2]
Out[7]=
In[8]:=
RotationMatrix[\[Theta], {0, 0, 1}] // ResourceFunction["MatrixFormDivided"][2]
Out[8]=

Use dividers at specific locations:

In[9]:=
AdjacencyMatrix[CompleteGraph[{2, 3, 4}]] // ResourceFunction["MatrixFormDivided"][{{2, 3, 4}}]
Out[9]=

Use dividers at specific locations differently for rows and columns:

In[10]:=
With[{m = AdjacencyMatrix[CompleteGraph[{2, 3, 4}]]},
  ArrayFlatten[{{m, Reverse[m]}}]] //
 ResourceFunction["MatrixFormDivided"][{{2, 3, 4, 2, 3, 4}, {2, 5}}]
Out[10]=

Options (3) 

DividersOffset (3) 

Place dividers for every two rows or columns, with an offset of one:

In[11]:=
ResourceFunction["MatrixFormDivided"][IdentityMatrix[7], 3, "DividersOffset" -> 1]
Out[11]=

Use an offset of one only on the rows:

In[12]:=
ResourceFunction["MatrixFormDivided"][IdentityMatrix[7], 3, "DividersOffset" -> {1, 0}]
Out[12]=

Use an offset of one only on the columns:

In[13]:=
ResourceFunction["MatrixFormDivided"][IdentityMatrix[7], 3, "DividersOffset" -> {0, 1}]
Out[13]=

Properties and Relations (1) 

MatrixFormDivided is an extended version of MatrixForm:

In[14]:=
ResourceFunction["MatrixFormDivided"][IdentityMatrix[4], 2]
Out[14]=
In[15]:=
MatrixForm[IdentityMatrix[4], 2]
Out[15]=

Possible Issues (2) 

The output of MatrixFormDivided is not directly computable:

In[16]:=
1 + ResourceFunction["MatrixFormDivided"][IdentityMatrix[4], 2]
Out[16]=

By evaluating it in place, it becomes computable:

In[17]:=
1 + {{1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}}
Out[17]=

The "DividersOffset" option has no effect when using specific spacings:

In[18]:=
ResourceFunction["MatrixFormDivided"][IdentityMatrix[6], {{1, 2, 3}}, "DividersOffset" -> 1]
Out[18]=

Publisher

GustavoDelfino

Version History

  • 1.0.0 – 11 July 2022

License Information