Previous Up Next

2.42.21Make a matrix with a list of matrix : blockmatrix

blockmatrix takes as arguments two integers n,m and a list of size n*m of matrices of the same dimension p q (or more generally such that the m first matrices have the same number of rows and c columns, the m next rows have the same number of rows and c columns, and so on ...). In both cases, we have n blocks of c columns.
blockmatrix returns a matrix having c columns by putting these n blocks one under another (vertical gluing). If the matrix arguments have the same dimension p q, the answer is a matrix of dimension p*n q*m.
Input :

blockmatrix(2,3,[idn(2),idn(2),idn(2), idn(2),idn(2),idn(2)])

Output :

[[1,0,1,0,1,0],[0,1,0,1,0,1], [1,0,1,0,1,0],[0,1,0,1,0,1]]

Input :

blockmatrix(3,2,[idn(2),idn(2), idn(2),idn(2),idn(2),idn(2)])

Output :

[[1,0,1,0],[0,1,0,1], [1,0,1,0],[0,1,0,1],[1,0,1,0],[0,1,0,1]]

Input :

blockmatrix(2,2,[idn(2),newMat(2,3), newMat(3,2),idn(3)])

Output :

[[1,0,0,0,0],[0,1,0,0,0],[0,0,1,0,0], [0,0,0,1,0],[0,0,0,0,1]]

Input :

blockmatrix(3,2,[idn(1),newMat(1,4), newMat(2,3),idn(2),newMat(1,2),[[1,1,1]]])

Output :

[[1,0,0,0,0],[0,0,0,1,0],[0,0,0,0,1],[0,0,1,1,1]]

Input :

A:=[[1,1],[1,1]];B:=[[1],[1]]

then :

blockmatrix(2,3,[2*A,3*A,4*A,5*B,newMat(2,4),6*B])

Output :

[[2,2,3,3,4,4],[2,2,3,3,4,4], [5,0,0,0,0,6],[5,0,0,0,0,6]]

Previous Up Next