{{indexmenu_n>999}}
====== Flatten ======
Matrix.Flatten($M$) takes an object $M$, which must be a matrix with matrix-valued entries, and returns the flattened version, which is a matrix with numbers as entries. This allows for working with block matrices, e.g. defining a matrix of the form
\begin{equation}
M=
\left(
\begin{matrix}
A & B \\
C & D\\
\end{matrix}
\right)
\end{equation}
where $A,B,C,D$ are all matrices.
If an entry of the input matrix $M$ is $0$ instead of a matrix, Quanty will interpret this as a zero-matrix of appropriate size, which makes creating sparse block-matrices especially easy in conjunction with //[[documentation:language_reference:objects:matrix:functions:zero|Matrix.Zero()]]//. A complete line or column of zeros will be deleted.
===== Example =====
==== Input ====
A = {{1,1},{1,1}}
B = {{2,2,2},{2,2,2}}
C = {{3,3},{3,3},{3,3},{3,3}}
D = {{4,4,4},{4,4,4},{4,4,4},{4,4,4}}
print("Matrix.Flatten({{A,B},{C,D}})" )
print( Matrix.Flatten({{A,B},{C,D}}) )
print("\n\n\n")
M = Matrix.Zero(3,{{"userdata",false}})
M[1][1] = A
M[1][2] = B
M[2][2] = D
M[3][3] = C
print( "Matrix.Flatten(M)" )
print( Matrix.Flatten(M) )
==== Result ====
Matrix.Flatten({{A,B},{C,D}})
{ { 1 , 1 , 2 , 2 , 2 } ,
{ 1 , 1 , 2 , 2 , 2 } ,
{ 3 , 3 , 4 , 4 , 4 } ,
{ 3 , 3 , 4 , 4 , 4 } ,
{ 3 , 3 , 4 , 4 , 4 } ,
{ 3 , 3 , 4 , 4 , 4 } }
Matrix.Flatten(M)
{ { 1 , 1 , 2 , 2 , 2 , 0 , 0 } ,
{ 1 , 1 , 2 , 2 , 2 , 0 , 0 } ,
{ 0 , 0 , 4 , 4 , 4 , 0 , 0 } ,
{ 0 , 0 , 4 , 4 , 4 , 0 , 0 } ,
{ 0 , 0 , 4 , 4 , 4 , 0 , 0 } ,
{ 0 , 0 , 4 , 4 , 4 , 0 , 0 } ,
{ 0 , 0 , 0 , 0 , 0 , 3 , 3 } ,
{ 0 , 0 , 0 , 0 , 0 , 3 , 3 } ,
{ 0 , 0 , 0 , 0 , 0 , 3 , 3 } ,
{ 0 , 0 , 0 , 0 , 0 , 3 , 3 } }
===== Table of contents =====
{{indexmenu>..:#2|tsort}}