1 | initial version |
A possible solution illustrating slicing for submatrices of a given matrix is as follows:
A = matrix( ZZ, 4, 4, [ 2,3,1,1, 1,2,3,1, 1,1,2,3, 3,1,1,2 ] )
print "The matrix A is:\n%s" % A
parts = sorted( [ tuple(S) for S in Set( [0,1,2,3] ).subsets() if S ]
, key=lambda S: (len(S), S) )
for S in parts:
for T in parts:
if len(S) != len(T):
continue
print ( "A[ %s , %s ].det() = %s"
% ( S, T, A.matrix_from_rows_and_columns(S, T).det() ) )
The results are:
The matrix A is: [2 3 1 1] [1 2 3 1] [1 1 2 3] [3 1 1 2]
A[ (0,) , (0,) ].det() = 2
A[ (0,) , (1,) ].det() = 3
A[ (0,) , (2,) ].det() = 1
A[ (0,) , (3,) ].det() = 1
A[ (1,) , (0,) ].det() = 1
A[ (1,) , (1,) ].det() = 2
A[ (1,) , (2,) ].det() = 3
A[ (1,) , (3,) ].det() = 1
A[ (2,) , (0,) ].det() = 1
A[ (2,) , (1,) ].det() = 1
A[ (2,) , (2,) ].det() = 2
A[ (2,) , (3,) ].det() = 3
A[ (3,) , (0,) ].det() = 3
A[ (3,) , (1,) ].det() = 1
A[ (3,) , (2,) ].det() = 1
A[ (3,) , (3,) ].det() = 2
A[ (0, 1) , (0, 1) ].det() = 1
A[ (0, 1) , (0, 2) ].det() = 5
A[ (0, 1) , (0, 3) ].det() = 1
A[ (0, 1) , (1, 2) ].det() = 7
A[ (0, 1) , (1, 3) ].det() = 1
A[ (0, 1) , (2, 3) ].det() = -2
A[ (0, 2) , (0, 1) ].det() = -1
A[ (0, 2) , (0, 2) ].det() = 3
A[ (0, 2) , (0, 3) ].det() = 5
A[ (0, 2) , (1, 2) ].det() = 5
A[ (0, 2) , (1, 3) ].det() = 8
A[ (0, 2) , (2, 3) ].det() = 1
A[ (0, 3) , (0, 1) ].det() = -7
A[ (0, 3) , (0, 2) ].det() = -1
A[ (0, 3) , (0, 3) ].det() = 1
A[ (0, 3) , (1, 2) ].det() = 2
A[ (0, 3) , (1, 3) ].det() = 5
A[ (0, 3) , (2, 3) ].det() = 1
A[ (1, 2) , (0, 1) ].det() = -1
A[ (1, 2) , (0, 2) ].det() = -1
A[ (1, 2) , (0, 3) ].det() = 2
A[ (1, 2) , (1, 2) ].det() = 1
A[ (1, 2) , (1, 3) ].det() = 5
A[ (1, 2) , (2, 3) ].det() = 7
A[ (1, 3) , (0, 1) ].det() = -5
A[ (1, 3) , (0, 2) ].det() = -8
A[ (1, 3) , (0, 3) ].det() = -1
A[ (1, 3) , (1, 2) ].det() = -1
A[ (1, 3) , (1, 3) ].det() = 3
A[ (1, 3) , (2, 3) ].det() = 5
A[ (2, 3) , (0, 1) ].det() = -2
A[ (2, 3) , (0, 2) ].det() = -5
A[ (2, 3) , (0, 3) ].det() = -7
A[ (2, 3) , (1, 2) ].det() = -1
A[ (2, 3) , (1, 3) ].det() = -1
A[ (2, 3) , (2, 3) ].det() = 1
A[ (0, 1, 2) , (0, 1, 2) ].det() = 4
A[ (0, 1, 2) , (0, 1, 3) ].det() = 3
A[ (0, 1, 2) , (0, 2, 3) ].det() = 11
A[ (0, 1, 2) , (1, 2, 3) ].det() = 17
A[ (0, 1, 3) , (0, 1, 2) ].det() = 17
A[ (0, 1, 3) , (0, 1, 3) ].det() = 4
A[ (0, 1, 3) , (0, 2, 3) ].det() = 3
A[ (0, 1, 3) , (1, 2, 3) ].det() = 11
A[ (0, 2, 3) , (0, 1, 2) ].det() = 11
A[ (0, 2, 3) , (0, 1, 3) ].det() = 17
A[ (0, 2, 3) , (0, 2, 3) ].det() = 4
A[ (0, 2, 3) , (1, 2, 3) ].det() = 3
A[ (1, 2, 3) , (0, 1, 2) ].det() = 3
A[ (1, 2, 3) , (0, 1, 3) ].det() = 11
A[ (1, 2, 3) , (0, 2, 3) ].det() = 17
A[ (1, 2, 3) , (1, 2, 3) ].det() = 4
A[ (0, 1, 2, 3) , (0, 1, 2, 3) ].det() = -35
And we can copy+paste from each of the above lines the determinant computation to convince ourselves that the corresponding relation is true, for instance:
sage: A[ (0, 1, 3) , (0, 1, 2) ].det()
17
where the submatrix is...
sage: A[ (0, 1, 3) , (0, 1, 2) ]
[2 3 1]
[1 2 3]
[3 1 1]
2 | No.2 Revision |
A possible solution illustrating slicing for submatrices of a given matrix is as follows:
A = matrix( ZZ, 4, 4, [ 2,3,1,1, 1,2,3,1, 1,1,2,3, 3,1,1,2 ] )
print "The matrix A is:\n%s" % A
parts = sorted( [ tuple(S) for S in Set( [0,1,2,3] ).subsets() if S ]
, key=lambda S: (len(S), S) )
for S in parts:
for T in parts:
if len(S) != len(T):
continue
print ( "A[ %s , %s ].det() = %s"
% ( S, T, A.matrix_from_rows_and_columns(S, T).det() ) )
The results are:
The matrix A is:
[2 3 1 1]
[1 2 3 1]
[1 1 2 3]
[3 1 1
And we can copy+paste from each of the above lines the determinant computation to convince ourselves that the corresponding relation is true, for instance:
sage: A[ (0, 1, 3) , (0, 1, 2) ].det()
17
where the submatrix is...
sage: A[ (0, 1, 3) , (0, 1, 2) ]
[2 3 1]
[1 2 3]
[3 1 1]