On 8/17/10 9:40 AM, Jason Grout wrote:
On 8/17/10 6:20 AM, vgermrk wrote:
I discussed the following issue with<logix> @IRC:


sage: rank(matrix(2,[1.5,1.75,-1.5,-1.75]))
2


gives a wrong answer.

Multiplying with a full rank matrix also gives unexpected results:


sage: rank( matrix(2,2,[1,0,0,1]) * matrix(2,[1.5,1.75,-1.5,-1.75]) )
2
sage: rank( matrix(2,2,[1,0,1,1]) * matrix(2,[1.5,1.75,-1.5,-1.75]) )
1


And even more serious: multiplying with another rank one matrix:

sage: rank( matrix(2,2,[1,0,1,0]) * matrix(2,[1.5,1.75,-1.5,-1.75]) )
2

Right now, Sage's computations with numeric matrices are woefully
inadequate using the RR field (which is what is used above). People are
working on this right now by making an interface with ALGLIB.

If you want to use numeric matrices to do computations right now, it's
best to use RDF or CDF; those usually call out to numpy, which does a
much more appropriate thing. However, in this case, we don't call out to
numpy. Here are related tickets from a while ago to fix these kinds of
bugs for RDF/RR:

http://trac.sagemath.org/sage_trac/ticket/3162

http://trac.sagemath.org/sage_trac/ticket/7392


See also:

http://stackoverflow.com/questions/2473983/calculate-matrix-rank-using-scipy

for an explanation of this function:

sage: a=matrix(RR, 2,[1.5,1.75,-1.5,-1.75])
sage: def rank(A, eps=1e-12):
....:         import scipy
....:     import scipy.linalg
....:     u, s, vh = scipy.linalg.svd(A.numpy())
....:     return len([x for x in s if abs(x) > eps])
....:
sage: rank(a)
1


It would be great if someone volunteered to clean up the above function and submit it to the Sage library for RDF/CDF matrices!

Jason

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

Reply via email to