The following example converts the one-line notation of a transposition into a matrix representation.
i1 : M = permutationMatrix toString 213 o1 = | 0 1 0 | | 1 0 0 | | 0 0 1 | 3 3 o1 : Matrix ZZ <--- ZZ |
The following example converts the cyclic notation of the same transposition into a matrix representation. Without n the function assumes n is the largest integer that appears in your array or list of arrays.
i2 : M = permutationMatrix(3,[1,2]) o2 = | 0 1 0 | | 1 0 0 | | 0 0 1 | 3 3 o2 : Matrix ZZ <--- ZZ |
i3 : M = permutationMatrix [1,2] o3 = | 0 1 | | 1 0 | 2 2 o3 : Matrix ZZ <--- ZZ |
The following example converts the cyclic notation of a permutation of 4 into a matrix representation.
i4 : M = permutationMatrix(4,{[1,2],[3,4]}) o4 = | 0 1 0 0 | | 1 0 0 0 | | 0 0 0 1 | | 0 0 1 0 | 4 4 o4 : Matrix ZZ <--- ZZ |
i5 : M = permutationMatrix {[1,2],[3,4]} o5 = | 0 1 0 0 | | 1 0 0 0 | | 0 0 0 1 | | 0 0 1 0 | 4 4 o5 : Matrix ZZ <--- ZZ |
The object permutationMatrix is a method function.