Error: Singular Matrix

Tarik Riadi picture Tarik Riadi · May 4, 2015 · Viewed 17.2k times · Source

I'm having an error in my code, I hope you can help me!: (When I paste the code something weird happens (not all of it is written like code) but here we go:

I want to linalg.solve(A,Res) . The first one (A) has 10 rows and 10 columns,i.e, matrix([10 arrays, 10 elements]) and the second one has 10 rows and 1 column, i.e, matrix([1 array, 10 elements]).

When I executed the code it throws the following error: Singular Matrix

I don't know what to do. When I don't ask to linalg.solve, but ask to print both matrices, both are fine: 10 equations, 10 variables. So I don't know what's going on. Please Help!!!

If you need me to paste the code (as horrible as it looks) I can do it.

Thank you

Answer

vsoftco picture vsoftco · May 4, 2015

A singular matrix is a matrix that cannot be inverted, or, equivalently, that has determinant zero. For this reason, you cannot solve a system of equations using a singular matrix (it may have no solution or multiple solutions, but in any case no unique solution). So better make sure your matrix is non-singular (i.e., has non-zero determinant), since numpy.linalg.solve requires non-singular matrices.

Here is some decent explanation about what's going on for 2 x 2 matrices (but the generalization is straightforward to N x N).