thouis / numpy-trac-migration

numpy Trac to github issues migration
2 stars 3 forks source link

failure to solve system of linear equations (Trac #2186) #5976

Closed numpy-gitbot closed 11 years ago

numpy-gitbot commented 11 years ago

_Original ticket http://projects.scipy.org/numpy/ticket/2186 on 2012-07-16 by trac user alkhwarizmi, assigned to atmention:pv.

Sadly, numpy.linalg.solve is giving me crap:

a = numpy.matrix('[1 2 -2 0; 1 0 0 -2; 3 2 -1 -6; 0 1 0 -1]')
b = numpy.matrix('0; 0; 0; 0')
numpy.linalg.solve(a, b)

outputs a zero vector.

If it means anything, I'm not just trying to break numpy; this is a real system of stoichiometric equations. The computer algebra system Maxima outputs the correct answer. In Maxima what I did was type in:

linsolve([r0 + 2*r1 = 2*p0, r0 = 2*p1, 3*r0 + 2*r1 = p0 + 6*p1, r1 = p1], [r0, r1, p0, p1]);

It outputs:

[r0 = 2 %r2, r1 = %r2, p0 = 2 %r2, p1 = %r2]

Thanks in advance for your hard work.

numpy-gitbot commented 11 years ago

atmention:pv wrote on 2012-07-16

The current behavior is absolutely correct --- the problem is that this not the way to look for the null space of a matrix. Ask e.g. stackoverflow on the mailing lists for more explanation.

numpy-gitbot commented 11 years ago

_trac user alkhwarizmi wrote on 2012-07-16

Replying to [comment:1 pv]:

The current behavior is absolutely correct --- the problem is that this not the way to look for the null space of a matrix. Ask e.g. stackoverflow on the mailing lists for more explanation.

Looking at the Wikipedia article for matrix kernels, I see your point. Didn't even know. Found a satisfactory method for use with NumPy on the mailing list. Thanks.