Ask Your Question
0

The minimum of a matrix

asked 2012-06-01 07:34:52 +0200

Svemmy gravatar image

updated 2012-06-01 07:43:35 +0200

So I have been writing some code using Sage, which by the way is awesome so far. And I had some simple check to do, i.e. all elements of some matrices have to be nonnegative. So I figured I would just see if the minimum of these matrices is nonnegative. In programms like matlab this is usualy achieved by min(min(A)) for some matrix A. I figured it would be the same for sage, so I tested this to be sure and everything seemed to work. But then I stumbeled upon something weird and I found this case (that is this is some of the output of the case). These are the 5 matrices followed by the minima of the same 5 matrices respectively.

[ 1.0000 0.00000 0.00000 0.00000 0.00000]
[0.00000  3.0000 0.00000 0.00000 0.00000]
[0.00000 0.00000  10.000 0.00000 0.00000]
[0.00000 0.00000 0.00000  5.0000 0.00000]
[0.00000 0.00000 0.00000 0.00000  1.0000]
-------------------------------------------------------------
[ 0.00000   1.0000  0.00000  0.00000  0.00000]
[  1.0000   1.0000  0.00000  0.00000   1.0000]
[ 0.00000  0.00000   4.4444   5.5556  0.00000]
[ 0.00000  0.00000   5.5556 -0.55556  0.00000]
[ 0.00000   1.0000  0.00000  0.00000  0.00000]
-------------------------------------------------------------
[0.00000 0.00000  1.0000 0.00000 0.00000]
[0.00000 0.00000  1.3333  1.6667 0.00000]
[ 1.0000  1.3333  4.4444  2.2222  1.0000]
[0.00000  1.6667  2.2222  1.1111 0.00000]
[0.00000 0.00000  1.0000 0.00000 0.00000]
-------------------------------------------------------------
[ 0.00000  0.00000  0.00000   1.0000  0.00000]
[ 0.00000  0.00000   3.3333 -0.33333  0.00000]
[ 0.00000   3.3333   4.4444   2.2222  0.00000]
[  1.0000 -0.33333   2.2222   1.1111   1.0000]
[ 0.00000  0.00000  0.00000   1.0000  0.00000]
-------------------------------------------------------------
[0.00000 0.00000 0.00000 0.00000  1.0000]
[0.00000  3.0000 0.00000 0.00000 0.00000]
[0.00000 0.00000  10.000 0.00000 0.00000]
[0.00000 0.00000 0.00000  5.0000 0.00000]
[ 1.0000 0.00000 0.00000 0.00000 0.00000]
-----minima--------------------------------------------------
[0, 0, 0, 0, 0]

Now I actually have a case which is very similar, that is, it is a permutation of these set of matrices above and for those I do get the correct answers

[ 1.0000 0.00000 0.00000 0.00000 0.00000]
[0.00000  3.0000 0.00000 0.00000 0.00000]
[0.00000 0.00000  5.0000 0.00000 0.00000]
[0.00000 0.00000 0.00000  10.000 0.00000]
[0.00000 0.00000 0.00000 0.00000  1.0000]
-------------------------------------------------------------
[ 0.00000   1.0000  0.00000  0.00000  0.00000]
[  1.0000   1.0000  0.00000  0.00000   1.0000]
[ 0.00000  0.00000 -0.55556   5.5556  0.00000]
[ 0.00000  0.00000   5.5556   4 ...
(more)
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2012-06-01 08:58:17 +0200

Svemmy gravatar image

You were right, this worked. Someone should probably add this to the help file for the min function. That is, the fact that it picks the minimum row lexicograpically is something I did not manage to find in there.

Either way thanks!

edit flag offensive delete link more
3

answered 2012-06-01 08:09:36 +0200

fidbc gravatar image

updated 2012-06-01 08:10:20 +0200

Hi,

Say A is a matrix. It seems that min(A) just returns the "minimum row" ordered lexicographically, which may not necessarily contain the minimum entry.

You can use A's list function to get a list of its entries and then take the minimum over that, so min(A.list()) gets the minimum entry of A.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2012-06-01 07:34:52 +0200

Seen: 845 times

Last updated: Jun 01 '12