Extended block diagonal matrix in Matlab

后端 未结 2 768
无人共我
无人共我 2021-01-06 04:47

I know that to generate a block-diagonal matrix in Matlab the command blkdiag generates such a matrix:

2条回答
  •  醉梦人生
    2021-01-06 05:10

    There is a submission on the File Exchange that can do this: (Block) tri-diagonal matrices.

    You provide the function with three 3D-arrays, each layer of the 3D array represents a block of the main, sub- or superdiagonal. (Which means that the blocks will have to be of the same size.) The result will be a sparse matrix, so it should be rather efficient in terms of memory.

    An example usage would be:

    As = bsxfun(@times,ones(3),permute(1:3,[3,1,2]));
    Bs = bsxfun(@times,ones(3),permute(10:11,[3,1,2]));
    M = blktridiag(As, zeros(size(Bs)), Bs);
    

    where full(M) gives you:

     1     1     1    10    10    10     0     0     0
     1     1     1    10    10    10     0     0     0
     1     1     1    10    10    10     0     0     0
     0     0     0     2     2     2    11    11    11
     0     0     0     2     2     2    11    11    11
     0     0     0     2     2     2    11    11    11
     0     0     0     0     0     0     3     3     3
     0     0     0     0     0     0     3     3     3
     0     0     0     0     0     0     3     3     3
    

提交回复
热议问题