[Scipy-tickets] [SciPy] #1730: LinAlgError("singular matrix") failed to raise when using linalg.solve()

SciPy Trac scipy-tickets@scipy....
Wed Sep 19 03:41:20 CDT 2012


#1730: LinAlgError("singular matrix") failed to raise  when using linalg.solve()
--------------------------+-------------------------------------------------
 Reporter:  mokchie       |       Owner:  somebody   
     Type:  defect        |      Status:  new        
 Priority:  normal        |   Milestone:  Unscheduled
Component:  scipy.linalg  |     Version:  0.9.0      
 Keywords:                |  
--------------------------+-------------------------------------------------
 I'm learning Scipy, and when I ran these codes using python 2.7.3 on
 Ubuntu 12.04 platform to test the behavior of solve():

 {{{
 Python 2.7.3 (default, Aug  1 2012, 05:16:07)
 [GCC 4.6.3] on linux2
 Type "help", "copyright", "credits" or "license" for more information.
 >>> import scipy as sp
 >>> from scipy import linalg
 >>> A=sp.mat([[1,2,3],[4,5,6],[7,8,9]])
 >>> b=sp.mat([[1],[2],[3]])
 >>> x=linalg.solve(A,b)
 >>> x
 array([[-0.26193963],
        [ 0.52387926],
        [ 0.0713937 ]])
 >>> linalg.det(A)
 0.0
 >>>

 }}}
 It surprised me that there is no Error raised, because the matrix
 A=[1,2,3; 4,5,6; 7,8,9] is clearly singular. Then I changed to another
 machine running Window XP SP3 platform to run the same codes on python
 2.7.2:

 {{{
 Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)]
 on win32
 Type "copyright", "credits" or "license()" for more information.
 >>> import scipy as sp
 >>> from scipy import linalg
 >>> A=sp.mat([[1,2,3],[4,5,6],[7,8,9]])
 >>> b=sp.mat([[1],[2],[3]])
 >>> x=linalg.solve(A,b)

 Traceback (most recent call last):
   File "<pyshell#4>", line 1, in <module>
     x=sp.linalg.solve(A,b)
   File "C:\Python27\lib\site-packages\scipy\linalg\basic.py", line 70, in
 solve
     raise LinAlgError("singular matrix")
 LinAlgError: singular matrix
 >>> linalg.det(A)
 0.0
 >>>
 }}}
 this time it goes as expected. I have checked the Scipy's version, and
 both are 0.9.0.

-- 
Ticket URL: <http://projects.scipy.org/scipy/ticket/1730>
SciPy <http://www.scipy.org>
SciPy is open-source software for mathematics, science, and engineering.


More information about the Scipy-tickets mailing list