Listing all k-minors of a matrix?

1,285 views
Skip to first unread message

janwil

unread,
Feb 1, 2010, 7:10:24 AM2/1/10
to sage-support
Hi all,

Is there a way to get all the k-minors of a matrix as a list of
matrices? Currently there is a method M.minors(2), but this only
produces the list of determinants. What about the matrices themselves?
Obviously, Sage must have them somewhere internally to compute the
determinants, but how to get access to them?

Best regards,
Jan

javier

unread,
Feb 1, 2010, 10:12:57 AM2/1/10
to sage-support
You can see the source of the "minors" method using

sage: M.minors??

(you need to have defined M beforehand).

By browsing at that source one can easily find the general way of
doing it:

sage: A = Matrix(QQ, 3, [1,2,3,4,5,6,7,8,9])
sage: [A.matrix_from_rows_and_columns(rows, cols) for cols in
combinations_iterator(range(A.ncols()), 2) for rows in
combinations_iterator(range(A.nrows()),2)]
[
[1 2] [1 2] [4 5] [1 3] [1 3] [4 6] [2 3] [2 3] [5 6]
[4 5], [7 8], [7 8], [4 6], [7 9], [7 9], [5 6], [8 9], [8 9]
]

Cheers
J

Jason Grout

unread,
Feb 1, 2010, 10:15:57 PM2/1/10
to sage-s...@googlegroups.com
On 02/01/2010 08:12 AM, javier wrote:
> You can see the source of the "minors" method using
>
> sage: M.minors??
>
> (you need to have defined M beforehand).
>
> By browsing at that source one can easily find the general way of
> doing it:
>
> sage: A = Matrix(QQ, 3, [1,2,3,4,5,6,7,8,9])
> sage: [A.matrix_from_rows_and_columns(rows, cols) for cols in
> combinations_iterator(range(A.ncols()), 2) for rows in
> combinations_iterator(range(A.nrows()),2)]
> [
> [1 2] [1 2] [4 5] [1 3] [1 3] [4 6] [2 3] [2 3] [5 6]
> [4 5], [7 8], [7 8], [4 6], [7 9], [7 9], [5 6], [8 9], [8 9]
> ]
>


Or slightly easier to read:

sage: A = Matrix(QQ, 3, [1,2,3,4,5,6,7,8,9])

sage: [A[rows,cols] for cols in Combinations(A.ncols(),2) for rows in
Combinations(A.nrows(),2)]


[
[1 2] [1 2] [4 5] [1 3] [1 3] [4 6] [2 3] [2 3] [5 6]
[4 5], [7 8], [7 8], [4 6], [7 9], [7 9], [5 6], [8 9], [8 9]
]

Thanks,

Jason

--
Jason Grout

Peter K.H. Gragert

unread,
Feb 2, 2010, 5:57:31 AM2/2/10
to sage-s...@googlegroups.com
Hi,
the second solution is indeed very nice.
I tested with
 A = Matrix(QQ, 2,3, [1,2,3,4,5,6]);A
giving:             
[1 2 3]
[4 5 6]
res=[A[rows,cols] for cols in Combinations(A.ncols(),2) for rows in Combinations(A.nrows(),2)];res
             

[[1 2]
[4 5], [1 3]
[4 6], [2 3]
[5 6]]

this is more or less my question this output is not really readable though correct.
for i in range(len(res)):print res[i].det()
             
-3
-6
-3
A.minors(2)
[-3, -6, -3]

And some different, how do Ishow output easier, is HERE a possibility to show a picture (screen capture) of sage-sheet?

Greets
   Peter

2010/2/2 Jason Grout <jason...@creativetrax.com>


--
To post to this group, send email to sage-s...@googlegroups.com
To unsubscribe from this group, send email to sage-support...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

Jason Grout

unread,
Feb 2, 2010, 10:29:16 AM2/2/10
to sage-s...@googlegroups.com
On 02/02/2010 03:57 AM, Peter K.H. Gragert wrote:
> Hi,
> the second solution is indeed very nice.
> I tested with
> A = Matrix(QQ, 2,3, [1,2,3,4,5,6]);A
> giving:
> [1 2 3]
> [4 5 6]
> res=[A[rows,cols] for cols in Combinations(A.ncols(),2) for rows in
> Combinations(A.nrows(),2)];res
>
>
> [[1 2]
> [4 5], [1 3]
> [4 6], [2 3]
> [5 6]]
>
> this is more or less my question this output is not really readable
> though correct.
> for i in range(len(res)):print res[i].det()
>
> -3
> -6
> -3
> A.minors(2)
> [-3, -6, -3]
>
> And some different, how do Ishow output easier, is HERE a possibility to
> show a picture (screen capture) of sage-sheet?
>


You can upgrade your sage in order to take advantage of the nice
printing you saw in our output:


sage: A = Matrix(QQ, 2,3, [1,2,3,4,5,6]);A


[1 2 3]
[4 5 6]

sage: res=[A[rows,cols] for cols in Combinations(A.ncols(),2) for rows
in Combinations(A.nrows(),2)];res
[
[1 2] [1 3] [2 3]
[4 5], [4 6], [5 6]
]
sage: [det(m) for m in res]
[-3, -6, -3]

Thanks,

Jason


Peter K.H. Gragert

unread,
Feb 3, 2010, 9:54:04 AM2/3/10
to sage-s...@googlegroups.com
I will try, it is Ubuntu on a Vbox and apt-get will probably work, not yet
it is sagemath to install not sage?!
Hmm, that succeeded, but if I read it all correct it is version 3.0.5  (2008 ??!!) and that I used is 4.2.1 ..
And version 3.0.5 is (for a UBUNTU) newbie not correct, it can not plot e.g..
I think I will remove it .. (freeing probably nearly 1GB)

Greetings
     Peter



2010/2/2 Jason Grout <jason...@creativetrax.com>
On 02/02/2010 03:57 AM, Peter K.H. Gragert wrote:

Jason Grout

unread,
Feb 3, 2010, 11:57:21 AM2/3/10
to sage-s...@googlegroups.com
On 02/03/2010 07:54 AM, Peter K.H. Gragert wrote:
> I will try, it is Ubuntu on a Vbox and apt-get will probably work, not yet
> it is sagemath to install not sage?!
> Hmm, that succeeded, but if I read it all correct it is version 3.0.5
> (2008 ??!!) and that I used is 4.2.1 ..
> And version 3.0.5 is (for a UBUNTU) newbie not correct, it can not plot
> e.g..
> I think I will remove it .. (freeing probably nearly 1GB)
>

Yes, definitely uninstall the Ubuntu sagemath package and install a
newer version.

Jason

Peter K.H. Gragert

unread,
Feb 4, 2010, 4:11:03 AM2/4/10
to sage-s...@googlegroups.com
Thanks Jason ...
the outputproblem is not urgent.
Gretings
    Peter

2010/2/3 Jason Grout <jason...@creativetrax.com>


Jason

Reply all
Reply to author
Forward
0 new messages