On Sat, Oct 27, 2007 at 09:02:00AM +0000, Wolfgang Lindner wrote:
> A somewhat general wish is to insert a matrix ('row') at a special
> position. . .
In the more general case you'll need a function like this:
insertrows(A, B, i) := block([n],
head(A, n) :=
if n > 0
then head(submatrix(length(A), A), n - 1)
else A,
tail(A, n) :=
if n > 0
then tail(submatrix(1, A), n - 1)
else A,
n: length(A),
addrow(head(A, n - i), B, tail(A, i)));
For instance:
(%i2) A: matrix([1,2],[3,4],[5,6])$
(%i3) B: matrix([a,b],[c,d])$
(%i4) insertrows(A, B, 2);
(%o4)
[ 1 2 ]
[ ]
[ 3 4 ]
[ ]
[ a b ]
[ ]
[ c d ]
[ ]
[ 5 6 ]