Previous Up Next

14.2.3  Combining matrices

Making a matrix with a list of matrices.

The blockmatrix command combines several matrices into one larger matrix.

Examples

blockmatrix(2,3,[idn(2),idn(2),idn(2),idn(2),idn(2),idn(2)])
     
⎡
⎢
⎢
⎢
⎣
101010
010101
101010
010101
⎤
⎥
⎥
⎥
⎦
          
blockmatrix(3,2,[idn(2),idn(2),idn(2),idn(2),idn(2),idn(2)])
     
⎡
⎢
⎢
⎢
⎢
⎢
⎢
⎣
1010
0101
1010
0101
1010
0101
⎤
⎥
⎥
⎥
⎥
⎥
⎥
⎦
          
blockmatrix(2,2,[idn(2),newMat(2,3),newMat(3,2),idn(3)])
     
⎡
⎢
⎢
⎢
⎢
⎢
⎣
10000
01000
00100
00010
00001
⎤
⎥
⎥
⎥
⎥
⎥
⎦
          
blockmatrix(3,2,[idn(1),newMat(1,4),newMat(2,3),idn(2),newMat(1,2),[[1,1,1]]])
     
⎡
⎢
⎢
⎢
⎣
10000
00010
00001
00111
⎤
⎥
⎥
⎥
⎦
          
A:=[[1,1],[1,1]];B:=[[1],[1]]:; blockmatrix(2,3,[2*A,3*A,4*A,5*B,newMat(2,4),6*B])
     
⎡
⎢
⎢
⎢
⎣
223344
223344
500006
500006
⎤
⎥
⎥
⎥
⎦
          
Making a matrix by concatenating columns of two matrices.

The semi_augment command concatenates two matrices with the same number of columns.

Examples

semi_augment([[3,4],[2,1],[0,1]],[[1,2],[4,5]])
     
⎡
⎢
⎢
⎢
⎢
⎢
⎣
34
21
01
12
45
⎤
⎥
⎥
⎥
⎥
⎥
⎦
          
semi_augment([[3,4,2]],[[1,2,4]])
     
⎡
⎢
⎣
342
124
⎤
⎥
⎦
          

Note the difference with concat.

concat([[3,4,2]],[[1,2,4]]
     
⎡
⎣
342124
⎤
⎦
          

Indeed, when the two matrices A and B have the same dimension, concat makes a matrix with the same number of rows as A and B by gluing them side by side.

concat([[3,4],[2,1],[0,1]],[[1,2],[4,5]]
     
⎡
⎢
⎢
⎢
⎢
⎢
⎣
34
21
01
12
45
⎤
⎥
⎥
⎥
⎥
⎥
⎦
          

But input:

concat([[3,4],[2,1]],[[1,2],[4,5]]
     
⎡
⎢
⎣
3412
2145
⎤
⎥
⎦
          
Making a matrix by gluing two matrices together.

The augment or concat command glues two matrices, either side by side or one on top of the other.

Note that if A and B have the same dimension, then augment(A,B) will return a matrix with the same number of rows as A and B by horizontal gluing. In that case, if you want to combine them by vertical gluing, you must use semi_augment(A,B).

Examples

augment([[3,4,5],[2,1,0]],[[1,2],[4,5]])
     
⎡
⎢
⎣
34512
21045
⎤
⎥
⎦
          
augment([[3,4],[2,1],[0,1]],[[1,2],[4,5]])
     
⎡
⎢
⎢
⎢
⎢
⎢
⎣
34
21
01
12
45
⎤
⎥
⎥
⎥
⎥
⎥
⎦
          
augment([[3,4,2]],[[1,2,4]]
     
⎡
⎣
342124
⎤
⎦
          
Appending a column to a matrix.

The border command adds a column to a matrix.

Examples

border([[1,2,4],[3,4,5]],[6,7])
     
⎡
⎢
⎣
1246
3457
⎤
⎥
⎦
          
border([[1,2,3,4],[4,5,6,8],[7,8,9,10]],[1,3,5])
     
⎡
⎢
⎢
⎣
12341
45683
789105
⎤
⎥
⎥
⎦
          

Previous Up Next