I am struggling with the new LinearAlgebra package and I want a procedure for the vec operator (just stacking the colums of matrix r by c into a (r*c) by 1 columnvector. For only extracting two columns the following commands work well: A := Matrix(5, 5, symbol = a); Matrix([[Column(A, [1])], [Column(A, [1])]]); but there must be a simple procedure for doing this for a converting a large matrix into a column vector. Any help would be appreciated. kind regards, Harry Garst
Matrix-Vector conversion
or,
or,
Dave Linder
Team Lead, Mathematical Software, Maplesoft, Inc.
Kronecker product, vec, and vech operators
Has someone written Kronecker product, vec, and vech operators for Maple?
Kronecker product, vec, and vech
KroneckerProduct is in LinearAlgebra package, and also you could search this site for it.
Various forms of vec are presented in Dave Linder's post above.
For vech, one can use something like <seq(seq(A[i,j], i=1..j),j=1..n)> where n is the number of columns of A (assuming that A is square).
Alec
ArrayTools[Reshape]
It looks like ArrayTools[Reshape] and ArrayTools[Alias] can also convert Matrices to Vectors (and back) with (and without) copying.
Reshape and Alias
As far as I understand, Alias - without copying, Reshape - with copying (or, more precisely, creating a new Array.)
The only problem with Alias is that it works not for all Matrices, but only for those with a rectangular storage, so in other cases an additional operation is needed, converting a Matrix to a Matrix with a rectangular storage.
Reshape produces an Array with a rectangular storage, and works for Arrays not necessarily with a rectangular storage, converting them first to Arrays with rectangular storage, if necessary.
Alec