#SVD version to solve general matrix problem Ax=b #with singular values smaller then 1e-10 considered zero. import numpy as np import numpy.linalg as la A = np.loadtxt("matrix") b = np.loadtxt("vector") b = b.reshape(len(b),1) U,s,V = la.svd(A) print( A) print( b) print() print() print( U) print( s) print( V) print( "Condition = ", s[0]/s[len(s)-1]) x=np.dot(np.transpose(U),b) x=x[0:len(s)] for i in range(len(s)): if s[i] >1e-10: x[i,0]=x[i,0]/s[i] else: print( "+ any amount", V[i]) x=np.dot(np.transpose(V[0:len(s)]),x) print( x)