Previous: Expressions Involving Diagonal Matrices, Up: Linear Algebra with Diagonal/Permutation Matrices [Contents][Index]
If P is a permutation matrix and M a matrix, the expression
P*M will permute the rows of M. Similarly,
yield a column permutation.
M/P can be used to do inverse
The previously described syntax for creating permutation matrices can actually
help an user to understand the connection between a permutation matrix and
a permuting vector. Namely, the following holds, where
I = eye (n)
is an identity matrix:
I(p,:) * M = (I*M) (p,:) = M(p,:)
M * I(:,p) = (M*I) (:,p) = M(:,p)
I(:,p) are permutation matrices.
A permutation matrix can be transposed (or conjugate-transposed, which is the
same, because a permutation matrix is never complex), inverting the
permutation, or equivalently, turning a row-permutation matrix into a
column-permutation one. For permutation matrices, transpose is equivalent to
P\M is equivalent to
P'*M. Transpose of a
permutation matrix (or inverse) is a constant-time operation, flipping only a
flag internally, and thus the choice between the two above equivalent
expressions for inverse permuting is completely up to the user’s taste.
Multiplication and division by permutation matrices works efficiently also when
combined with sparse matrices, i.e.,
P*S, where P is a permutation
matrix and S is a sparse matrix permutes the rows of the sparse matrix
and returns a sparse matrix. The expressions
S/P work analogically.
Two permutation matrices can be multiplied or divided (if their sizes match), performing a composition of permutations. Also a permutation matrix can be indexed by a permutation vector (or two vectors), giving again a permutation matrix. Any other operations do not generally yield a permutation matrix and will thus trigger the implicit conversion.