# The minimum of a matrix

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 ...
edit retag close merge delete

Sort by ยป oldest newest most voted

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.

more

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!

more