I came across the following issue when trying to use Sympy to compute an LU 
decomposition of a matrix. I'd like to determine the number of solutions a 
system of equations has, for example, if

A = sympy.Matrix([[1,2,3],[4,5,6],[7,8,9]])
b = sympy.Matrix([4, 13, 22])

then the system A*x=b has infinitely many solutions, all of which can be 
written as

x0 + t*n

where
x0 = sympy.Matrix([2,1,0])
n = sympy.Matrix([1,-2,1])
t = sympy.Symbol('t')

This solution can be computed from the LU decomposition of A, however the 
following code fails to compute the factors L and U.

>>> import sympy
>>> A = sympy.Matrix([[1,2,3],[4,5,6],[7,8,9]])
>>> LU, perm = A.LUdecomposition()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Python/2.7/site-packages/sympy/matrices/matrices.py", line 
1297, in LUdecomposition
    combined, p = self.LUdecomposition_Simple(iszerofunc=_iszero)
  File "/Library/Python/2.7/site-packages/sympy/matrices/matrices.py", line 
1341, in LUdecomposition_Simple
    raise ValueError("No nonzero pivot found; inversion failed.")
ValueError: No nonzero pivot found; inversion failed.

A is square and noninvertible, which explains the message in the stack 
trace about the elimination algorithm encountering a zero subcolumn below 
the pivot position. Regardless, A can still be written as the product of 
lower triangular L with unit diagonal, and upper triangular U, where
L = sympy.Matrix([[1, 0, 0], [4, 1, 0], [7, 2, 1]])
U = sympy.Matrix([[1,  2,  3], [0, -3, -6], [0,  0,  0]])

Is A.LUdecomposition() the wrong function to call if I want to compute the 
LU decomposition of A in the case where A is noninvertible, or not square? 
I wrote my own LU decomposition routine to handle these cases, which I'd be 
happy to contribute, but I'd like to know if this functionality exists in 
Sympy.

Thanks in advance for your input,
Tom

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sympy+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/fd7d07b6-4261-4c70-bb9a-5c9961834439%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to