[SciPy-User] scipy.sparse.linalg.bicg for Non Symmetric Matrix.

Dag Sverre Seljebotn dagss@student.matnat.uio...
Fri Dec 10 06:57:25 CST 2010


On 12/10/2010 01:51 PM, Pauli Virtanen wrote:
> Thu, 09 Dec 2010 21:12:28 -0430, Raul Acuña wrote:
>    
>> Am using the iterative methods of scipy.sparse.linalg for solving a
>> linear system of equations Ax = b. My matrix A is non symmetric. I've
>> been using the scipy.sparse.linalg.cg() function multiplying both matrix
>> "A" and "b" with the transpose of A so the matrix will become symmetric:
>>
>> Asym = matrix(dot(A.T,A))
>> bsym = matrix(dot(A.T,b))
>> sol = cg(A,b,tol = 1e-10,maxiter=30)
>>      
> [clip]
>    
>> sol = bicg(A,b,tol = 1e-10,maxiter=30)
>>      
> [clip]
>    
>>            raise ValueError('expected square matrix (shape=%s)' % shape)
>>      
> [clip]
>
> The error is saying that your matrix is not a square matrix.
> For a non-square matrix A, (A.T*A) is a square matrix, so that's why the
> CG algorithm works. So it's not about symmetry of the matrix.
>
> You should check that you have the same number of equations as unknowns.
> Otherwise the solution either does not exists or is not unique.
>    

Note the NameError in the original post as well though -- that is, there 
may be a bug in the exception raising code as well.

Dag Sverre



More information about the SciPy-User mailing list