Karim Belabas on Mon, 13 Feb 2012 20:02:08 +0100


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: matconcat


* Andreas Enge [2012-02-13 19:28]:
> A user can easily provide building blocks of the required dimensions using
> matdiagonal, for instance, or c*matid(d), or matrix(m,n) for simple
> building blocks of the right dimension.

Simple test-case : 

? A = 1; B = [1,2;3,4]; C = [1,2,3;4,5,6;7,8,9]
? matconcat(matdiagonal([A,B,C]))   \\ current implementation
%2 = 
[1 0 0 0 0 0]

[0 1 2 0 0 0]

[0 3 4 0 0 0]

[0 0 0 1 2 3]

[0 0 0 4 5 6]

[0 0 0 7 8 9]

Please provide "easy" building blocks of the required dimensions. :-)
The "best" I can come up with is

{
  matconcat([A,          vector(2),   vector(3);
             vectorv(2), B,           matrix(2,3);
             vectorv(3), matrix(3,2), C]);
}

I believe this demonstrates the usefulness of "extendable 0-blocks", at least.

I kind of like to interpret a scalar as c*Id_{proper dimension}, but this is
maybe less useful.


It would be nice to be able to write 

  M = matrix(6,6);
  M[1,1]        = A;
  M[2..3, 2..3] = B;
  M[4..,  4..]  = C;

But this currently does not work.

Cheers,

    K.B.

P.S: Granted, this would be better solved in matdiagonal() itself, which could
interpret properly "block" diagonal elements (square matrices instead of the
expected scalar).


P.S2;
I found old GP scripts of mine with nasty examples:

  vconcat(a,b) = concat(a~, b~)~

  rebuild(H, B, dep) =
  { my(top, bot, l,h);

    top = concat(vconcat(dep, H), B);
    h = matsize(B)[2];
    l = matsize(H)[1];
    bot = concat(matrix(h,l), matid(h));
    vconcat(top, bot);
  }

This becomes  \\ current implementation

   matconcat([matconcat([dep,H]~), B; 0, matid(#B)])

Marginally nicer, with '1' = 1 * Id_{proper dimension}

   matconcat([matconcat([dep,H]~), B; 0, 1])

-- 
Karim Belabas, IMB (UMR 5251)  Tel: (+33) (0)5 40 00 26 17
Universite Bordeaux 1          Fax: (+33) (0)5 40 00 69 50
351, cours de la Liberation    http://www.math.u-bordeaux1.fr/~belabas/
F-33405 Talence (France)       http://pari.math.u-bordeaux1.fr/  [PARI/GP]
`