[GAP Forum] block matrix
Sven Reichard
sven.reichard at freenet.de
Wed Jun 8 19:16:18 BST 2005
Luca Giuzzi wrote:
> On Tue, Jun 07, 2005 at 11:39:53PM -0400, Vahid Dabbaghian-Abdoly wrote:
>
>>Dear GAP Forum,
>>
>>I am want to construct a diagonal block matrix such that the
>>diagonal entries have different dimensions.
>>Is there any function or method for such a matrix in GAP?
>>
>>Best regards, Vahid
>>
>>
>
> There is no such function I am aware of in GAP ...
> (I actually got this snippet from somebody on the mailing list some time
> ago)
> However, I have been using the following:
<snip>
> lg
Vahid,
if you have more than two blocks, the following code might help:
DiagonalBlockMatrix := function(matrices)
# matrices is a list of square matrices over a field.
# note: both matrices and matrices[1] are assumed to be non-empty
local dimension, partialSum, totalLength, result, m, i, range;
dimension := List(matrices, Length);
partialSum := List([0..Length(matrices)], x ->
Sum(dimension{[1..x]}));
range := List([1..Length(matrices)], x ->
[partialSum[x]+1..partialSum[x+1]]);
totalLength := Sum(dimension);
result := NullMat(totalLength, totalLength, Field(matrices[1][1][1]));
for m in [1..Length(matrices)] do
for i in [1..dimension[m]] do
result[range[m][i]]{range[m]} := matrices[m][i];
od;
od;
return result;
end;
Regards,
Sven.
More information about the Forum
mailing list