I’m using scipy.linalg to solve a matrix equation A*x = b
The following code does not work:
from scipy import *
from pylab import *
from scipy.sparse import lil_matrix
from scipy.sparse.linalg import spsolve, factorized
from numpy.random import rand
from numpy import ones
def build_matrix(n):
A_lil = lil_matrix((n, n))
A_lil.setdiag(rand(n))
A_lil.setdiag(rand(n-10), k = 10)
A_lil.setdiag(rand(n-10), k = -10)
A_csr = A_lil.tocsr()
return A_csr
A = build_matrix(500)
fsolve = factorized(A)
b = rand(500,1)
fsolve(b)
Traceback (most recent call last):
File "<pyshell#70>", line 1, in <module>
fsolve(b)
SystemError: gstrs was called with invalid arguments
(Edit: actually, the console does not say fsolve(b,trans), it says self.solve(b,trans), so the part below is probably wrong)
If I type in fsolve manually into the console I see that fsolve requires two arguments ‘b’, and ‘trans’. This for some reason is not mentioned in the documentation for factorized here: http://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.linalg.factorized.html. Adding in the argument ‘N’ gives the following error
>> fsolve(b, 'N')
Traceback (most recent call last):
File "<pyshell#55>", line 1, in <module>
fsolve(b,'N')
SystemError: gstrs was called with invalid arguments
Any help?
You seem to have an error in:
it needs to be:
else the array gets ‘too deep’. Hope that helps.