Question: Flattening a Matrix

I'm looking for a flatten procedure for matrices (without first having to convert the matrix to a list, flatten it, and finally convert it back).
In this example, I am trying to generalize the matrix R to higher dimensions (here a 3 by 3 matrix, denoted as A, is used). I'm using a function, denoted as g, to construct a matrix. Obviously, the function applies to each cell and therefore, each cell contains a matrix in the resulting matrix. A flatten command would solve the problem. As a work-around I reconstruct the matrix In this example, but that is hard to generalize to more dimensions (or not?)

restart; kernelopts(version); interface(version); with(LinearAlgebra); with(combinat); interface(rtablesize = 16)

`Maple 2024.2, X86 64 WINDOWS, Oct 29 2024, Build ID 1872373`

 

`Standard Worksheet Interface, Maple 2024.2, Windows 11, October 29 2024 Build ID 1872373`

 

[10, 10]

(1)

Antidiagonal := proc (n) local Q, r, c; Q := Matrix(n, n); seq(seq(`if`(r+c = RowDimension(Q)+1, assign('Q[r, c]', 1), assign('Q[r, c]', 0)), r = 1 .. RowDimension(Q)), c = 1 .. ColumnDimension(Q)); return Q end proc

A := Matrix(3, 3, symbol = a)

R := `<,>`(`<|>`(Adjoint(A([2, 3], [2, 3])), -Adjoint(A([1, 3], [2, 3])), Adjoint(A([1, 2], [2, 3]))), `<|>`(-Adjoint(A([2, 3], [1, 3])), Adjoint(A([1, 3], [1, 3])), -Adjoint(A([1, 2], [1, 3]))), `<|>`(Adjoint(A([2, 3], [1, 2])), -Adjoint(A([1, 3], [1, 2])), Adjoint(A([1, 2], [1, 2]))))

Matrix(%id = 36893490582445267772)

(2)

U := choose(3, 2)

[[1, 2], [1, 3], [2, 3]]

(3)

g := proc (r, c) options operator, arrow; Adjoint((eval*A^%T)(U[c], U[r])) end proc

proc (r, c) options operator, arrow; LinearAlgebra:-Adjoint((eval(A^%T))(U[c], U[r])) end proc

(4)

Q := Matrix(3, g)

Matrix(%id = 36893490582395297788)

(5)

Q := Antidiagonal(3).Q.Antidiagonal(3)

Matrix(%id = 36893490582401641396)

(6)

U := `<,>`(`<|>`(Q[1, 1], Q[1, 2], Q[1, 3]), `<|>`(Q[2, 1], Q[2, 2], Q[2, 3]), `<|>`(Q[3, 1], Q[3, 2], Q[3, 3]))

Matrix(%id = 36893490582412939004)

(7)

R-Matrix(6, 6, [[1, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0], [0, 0, -1, 0, 0, 0], [0, 0, 0, -1, 0, 0], [0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 1]]).U^%T.Matrix(6, 6, [[1, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0], [0, 0, -1, 0, 0, 0], [0, 0, 0, -1, 0, 0], [0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 1]])

Matrix(%id = 36893490582417081876)

(8)


Download Flatten_a_matrix.mw

Please Wait...