5

I want to stack columns of a matrix in Maxima.

Example

b3: matrix(
 [1,0,0], 
 [-a21,1,0], 
 [-a31,-a32,1]
);

I wonder how to stack the columns of this matrix. Thanks in advance for your help and time.

MYaseen208
  • 22,666
  • 37
  • 165
  • 309

2 Answers2

4

Here is an naive way of doing it:

c : transpose( b3 );
transpose( append( c[0], c[1], c[2] ) );

and here is a more general way:

apply(append, map(lambda([r], transpose(b3)[r]), makelist(i,i,3)));
soegaard
  • 30,661
  • 4
  • 57
  • 106
  • Thank @soegaard for your answer. I think you mean `c : transpose( b3 ); transpose( append( c[1], c[2], c[3] ) );`. It becomes very tedious if there are many columns. I'd prefer any automated way. Anyway thanks for your answer (+1). – MYaseen208 May 17 '12 at 21:37
  • @MYaseen208 A more general way, which might be what you are looking for: apply(append, map(lambda([r], transpose(b3)[r]), makelist(i,i,3))); – soegaard May 18 '12 at 13:28
  • Thanks for your help and showing interest in this problem. Your new code `apply(append, map(lambda([r], transpose(b3)[r]), makelist(i,i,3)));` produces this output `[1,-a21,-a31,0,1,-a32,0,0,1]` which is not the required output. Thanks – MYaseen208 May 18 '12 at 15:31
  • 1
    @MYaseen208 Just transpose: transpose(apply(append, map(lambda([r], transpose(b3)[r]), makelist(i,i,3)))); – soegaard May 18 '12 at 15:47
2

Or even just:

transpose(apply(append,args(transpose(b3))));