John H Palmieri wrote:
> On Nov 12, 6:41 am, Jason Grout <[EMAIL PROTECTED]> wrote:
>> John H Palmieri wrote:
>>> an error in matrix_double_dense, which I couldn't find on trac (should
>>> I create a ticket?):
>>> sage -t devel/sage/sage/matrix/matrix_double_dense.pyx
>>> **********************************************************************
>>> File "/Applications/sage/devel/sage/sage/matrix/
>>> matrix_double_dense.pyx", line 444:
>>> sage: ~A
>>> Expected:
>>> Traceback (most recent call last):
>>> ...
>>> LinAlgError: singular matrix
>>> Got:
>>> [-4.50359962737e+15 9.00719925474e+15 -4.50359962737e+15]
>>> [ 9.00719925474e+15 -1.80143985095e+16 9.00719925474e+15]
>>> [-4.50359962737e+15 9.00719925474e+15 -4.50359962737e+15]
>> Hmm. This code was just moved to a numpy backend. Scipy correctly saw
>> this matrix as singular on my system. However, it looks like you are
>> seeing a spurious inverse, most likely due to numerical issues.
>>
>> Could you post the output of the following commands:
>>
>> sage: A = matrix(RDF,3,range(1,10));A
>> sage: A.determinant()
>> sage: ~A
>> sage: b=A.numpy(); b
>> sage: import scipy
>> sage: import scipy.linalg
>> sage: scipy.linalg.det(b)
>> sage: scipy.linalg.inv(b)
>
> sage: A = matrix(RDF,3,range(1,10));A
>
> [1.0 2.0 3.0]
> [4.0 5.0 6.0]
> [7.0 8.0 9.0]
> sage: A.determinant()
> 0.0
> sage: -A
>
> [-1.0 -2.0 -3.0]
> [-4.0 -5.0 -6.0]
> [-7.0 -8.0 -9.0]
> sage: b = A.numpy(); b
>
> array([[ 1., 2., 3.],
> [ 4., 5., 6.],
> [ 7., 8., 9.]])
> sage: import scipy
> sage: import scipy.linalg
> sage: scipy.linalg.det(b)
> 0.0
> sage: scipy.linalg.inv(b)
>
> array([[ -4.50359963e+15, 9.00719925e+15, -4.50359963e+15],
> [ 9.00719925e+15, -1.80143985e+16, 9.00719925e+15],
> [ -4.50359963e+15, 9.00719925e+15, -4.50359963e+15]])
>
> That last pair of results looks suspicious, doesn't it?
One more time, could you do the following sequence of commands so that I
can report them to the numpy mailing list. I've left the output from my
run; it's interesting that the numpy.linalg.inv on my computer gives the
same ridiculous answers that your scipy.linalg.inv command gives. It
looks like it is scaling by dividing by the determinant or something.
sage: import numpy
sage: a=numpy.array([[1,2,3],[4,5,6],[7,8,9]],dtype="float64")
sage: import scipy
sage: import scipy.linalg
sage: import numpy.linalg
sage: scipy.linalg.det(a)
0.0
sage: scipy.linalg.inv(a)
---------------------------------------------------------------------------
LinAlgError Traceback (most recent call
[snip]
LinAlgError: singular matrix
sage: numpy.linalg.det(a)
-1.3325928902019335e-15
sage: numpy.linalg.inv(a)
array([[ 2.25125019e+15, -4.50250038e+15, 2.25125019e+15],
[ -4.50250038e+15, 9.00500077e+15, -4.50250038e+15],
[ 2.25125019e+15, -4.50250038e+15, 2.25125019e+15]])
Thanks,
Jason
--~--~---------~--~----~------------~-------~--~----~
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-devel
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---