generate matrix from submatrices.



Moch Ramis <mocramis at gmail.com> writes:

> Hello
>
> I'm probably asking something really basic, but I've not been able to have
> it working: I'm trying to create a 9x9 matrix from 1x3 matrix:
> something like:
>                 [  A    0   0 ]
>                 [  0    A   0 ]
>                 [  0    0   A ]
>                 [ B   0    0  ]
> M=           [  0   B   0  ]
>                 [  0    0   B ]
>                 [ C   0    0  ]
>                 [  0   C   0  ]
>                 [  0    0   C ]
>
> where A,B,C ar some 1x3 matrices.
>

How about the following?

make_row(lst) := block([ret: []],
  for x in lst do ret: append(ret, x), ret)$

make_diag_block(triple) :=
  matrix(
    make_row([triple, [0,0,0], [0,0,0]]),
    make_row([[0,0,0], triple, [0,0,0]]),
    make_row([[0,0,0], [0,0,0], triple]))$

make_stripes(A,B,C) :=
  addrow(make_diag_block(A), make_diag_block(B), make_diag_block(C))$


giving:

(%i27) make_stripes([1,2,3], [2,3,4], [3,4,5]);
                         [ 1  2  3  0  0  0  0  0  0 ]
                         [                           ]
                         [ 0  0  0  1  2  3  0  0  0 ]
                         [                           ]
                         [ 0  0  0  0  0  0  1  2  3 ]
                         [                           ]
                         [ 2  3  4  0  0  0  0  0  0 ]
                         [                           ]
(%o27)                   [ 0  0  0  2  3  4  0  0  0 ]
                         [                           ]
                         [ 0  0  0  0  0  0  2  3  4 ]
                         [                           ]
                         [ 3  4  5  0  0  0  0  0  0 ]
                         [                           ]
                         [ 0  0  0  3  4  5  0  0  0 ]
                         [                           ]
                         [ 0  0  0  0  0  0  3  4  5 ]
(%i28) 

There might be an easier/more efficient way to do it, but I'm not sure
how.

Rupert
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 315 bytes
Desc: not available
URL: <http://www.math.utexas.edu/pipermail/maxima/attachments/20101214/20554816/attachment.pgp>;