vec operator in LinearAlgebra

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

(m,n) := 5,7:
A := LinearAlgebra[RandomMatrix](m,n);

convert(A,Vector[column]);

or,

Vector([seq(A[1..-1,i],i=1..LinearAlgebra[ColumnDimension](A))]); 

or,

B := Vector(m*n):
ArrayTools[Copy](m*n,A,0,1,B,0,1):
B;

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?  

alec's picture

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.

alec's picture

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

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
}