We have developed the file NCBlockPartition.m to do matrix
partitioning.
The easiest way to explain how it works is
through an example.
If one has a 3
3 matrix
A is the 1
1 matrix containing the entry 3
B is the 1
2 matrix containing the entries 6 and 9
C is the 2
1 matrix containing the entries 1 and 5
D is the 2
2 matrix containing the entries 2, 4, 9, and 1.
PartitionMatrix[{{3,6,9}, {1,2,4}, {5,9,1}}, 1, 1]
(Note: the second parameter is the number of rows of the upper
left hand and the third parameter is the number of columns of
the upper left hand block. That is, A is a 1and the output would have the form
{{$1,$2},{$3,$4}}
and would have the consequence of typing ?ValueQ and ?BlockQ
ValueOf[$1] = {{3}}
ValueOf[$2] = {{6,9}}
ValueOf[$3] = {{1},{5}}
ValueOf[$4] = {{2,4},{9,1}}
BlockQ[$1] = True
BlockQ[$2] = True
BlockQ[$3] = True
BlockQ[$4] = True
One can reconstruct the original matrix by executing
FormMatrix[{{$1,$2},{$3,$4}}]
If one does not want a `$', then one can use a different `prefix" by adding a fourth parameter to the call to PartitionMatrix. The numbers following the prefix are generated by the `Unique" command. We hope that their uglyness is not offensive.
We use the ValueOf function to associate the value of the block
to the block without actually assigning it. If it were assigned
immediately, then the assigned value would be dragged around instead
of the variable representing the entry. If one is
partitioning a 100
100 matrix into a 2
2 block matrix,
then delaying the assignment makes following the calculation
much simpler.
The BlockQ command tells the user if the variable represents a block matrix and is assigned within PartitionMatrix via the SetBlock command. At this time, BlockQ is never used. The intention is to provide it at this point for future expansion.
Lastly, note that
FormMatrix[PartitionMatrix[x, m, n]]will give back x (as long as m and n are less than the dimensions of the matrix x, of course).