On Feb 21, 7:07 am, cidex <[email protected]> wrote:

Hi,

> I have tracked down an error in one of my SAGE scripts down to
> following behavior of SAGE:
>
> The following code does what you'd expect:
>
> M= Matrix([[1,0,0],[0,1,0],[0,0,1]]);
> M=M*91/100; #the line we modify later
> print M;
> N= M.inverse(); #or: N= M^(-1)
> print N;
> print N*M #result, should be neutral element

For algebraic types yes, for numerical types no - see blow.

> If you replace the line with the command M=M*91/100; by: M=M*0.91;
> then following error message shows up:
> ZeroDivisionError: self is not invertible

The root cause here is that if you multiply M with 0.91 you change the
entry type of the matrix from a beautiful algebraic type to a
numerical type:

----------------------------------------------------------------------
| Sage Version 3.3, Release Date: 2009-02-21                         |
| Type notebook() for the GUI, and license() for information.        |
----------------------------------------------------------------------
sage: M= Matrix([[1,0,0],[0,1,0],[0,0,1]]);
sage: M=M*91/100
sage: type(M[0][0])
<type 'sage.rings.rational.Rational'>
sage: M= Matrix([[1,0,0],[0,1,0],[0,0,1]]);
sage: M=M*0.91
sage: type(M[0][0])
<type 'sage.rings.real_mpfr.RealNumber'>


> (I find it very interesting that the command: M=M*0.9; does not
> produce this error)

Well, once you go with numerical types all the things you expect to
always work "correclty" like rank(), inversion()  and so on do no
longer work.

> Also interesting is that i can supress the error by inserting: M=
> M*0.91; M= M.n(20); into the line. Unfortunately
> this does not work in my original programm.

This is likely just luck since then the numerical imprecision in this
case does not cause any trouble. Switch to a different CPU or a
different compiler and things will not work or vice versa. We have had
tests in Sage to check for non-invertible matrices for numerical types
and if the matrix is near non-full rank it can be invertible or
singular depending on the CPU and compiler used.

> How can I invert a matrix with such elements?

Stick with algebraic rings, don't use numerical types if you don't
have to.

Cheers,

Michael
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to