Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Symmetrically reorder the rows and columns of a square matrix
ResourceFunction["SymmetricSort"][matrix,from,to] symmetrically reorders the elements of matrix from ordering from to ordering to. | |
ResourceFunction["SymmetricSort"][matrix,index] symmetrically reorders the elements of matrix by the ordering represented by index. |
Generate a covariance matrix from example data:
In[1]:= |
Out[1]= |
The covariance matrix is symmetric and positive semidefinite:
In[2]:= |
Out[2]= |
A SymmetricSort using the variable names to change the order of the variables:
In[3]:= |
Out[3]= |
Symmetric and positive semidefinite properties are preserved:
In[4]:= |
Out[4]= |
SymmetricSort can also take an ordering of position indices:
In[5]:= |
Out[5]= |
SymmetricSort preserves the diagonal and the relative positions of the upper and lower off-diagonals:
In[6]:= |
Out[6]= |
Diagonal elements in the original matrix remain on the diagonal in the reordered matrix, and off-diagonal relative positions are comparable. For example, m34 is still mirrored with m43:
In[7]:= |
Out[7]= |
SymmetricSort accepts permutations expressed in cycle format:
In[8]:= |
Out[8]= |
Properties of Graph, like WeightedAdjacencyMatrix, are given in the order of VertexList:
In[9]:= |
Out[9]= |
SymmetricSort property elements in canonical order:
In[10]:= |
Out[10]= |
SymmetricSort the HadamardMatrix:
In[11]:= |
Out[11]= |
The permuted matrix is involutory, just like the original Hadamard matrix:
In[12]:= |
Out[12]= |
The eigenvalues of a symmetric matrix are invariant under SymmetricSort:
In[13]:= |
Out[13]= |
In[14]:= |
Out[14]= |
In[15]:= |
Out[15]= |
An upper bidiagonal matrix:
In[16]:= |
Out[16]= |
Generate a symmetric block matrix with bidiagonal blocks:
In[17]:= |
Out[17]= |
Use the resource function OutShuffle with SymmetricSort to transform the matrix into a tridiagonal matrix:
In[18]:= |
Out[18]= |
Compute the singular values of a numerical upper bidiagonal matrix:
In[19]:= |
Out[19]= |
These are equivalent to the positive eigenvalues of the permuted block matrix:
In[20]:= |
Out[20]= |
This work is licensed under a Creative Commons Attribution 4.0 International License