thouis / numpy-trac-migration

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

Poor precision using linalg.solve for certain matrices (Trac #1655) #5456

Closed numpy-gitbot closed 12 years ago

numpy-gitbot commented 12 years ago

Original ticket http://projects.scipy.org/numpy/ticket/1655 on 2010-10-30 by trac user zoof, assigned to atmention:pv.

There appears to be a bug in either the linear system solver or in the way than linalg computes LU decompositions. On a number of different distributions, using somewhat different versions of numpy, I get much better precision by inverting the matrix (linalg.inv) and multiplying than by either linalg.solve alone or linalg.cholesky in combination with linalg.solve. An example has been posted to: http://pastebin.com/KpXdTVh7

numpy 1.3.0 on Ubuntu Lucid numpy 1.5.0 on Arch numpy 1.5.1rc1 on Centos

numpy-gitbot commented 12 years ago

Milestone changed to 1.5.1 by trac user zoof on 2010-10-30

numpy-gitbot commented 12 years ago

atmention:pv wrote on 2010-10-30

Not a bug.

If you want right solve, do

p=linalg.solve(Q.T,a)
numpy-gitbot commented 12 years ago

trac user zoof wrote on 2010-10-31

The help file indicates that it solves systems of the form A x = b. From what I understand is happening is that because my "b" is a row vector, it is solving x A = b. Either linalg.solve should throw an error when it gets a row vector or else the documentation should be amended.

numpy-gitbot commented 12 years ago

atmention:pv wrote on 2010-10-31

No, linalg.solve is always solving "A x = b", i.e., it does the left inverse. In your code, you assume it solves "x A = b", which it does not.