First time here? Check out the FAQ!

Ask Your Question
0

The minimum of a matrix

asked 12 years ago

Svemmy gravatar image

updated 12 years ago

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)
Preview: (hide)

2 Answers

Sort by » oldest newest most voted
3

answered 12 years ago

fidbc gravatar image

updated 12 years ago

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.

Preview: (hide)
link
0

answered 12 years ago

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!

Preview: (hide)
link

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: 12 years ago

Seen: 1,012 times

Last updated: Jun 01 '12