numpy (matrix solver) - python vs. matlab

someone newsboost at gmail.com
Sun Apr 29 20:17:44 EDT 2012


On 04/30/2012 12:39 AM, Kiuhnm wrote:

>> So Matlab at least warns about "Matrix is close to singular or badly
>> scaled", which python (and I guess most other languages) does not...
>
> A is not just close to singular: it's singular!

Ok. When do you define it to be singular, btw?

>> Which is the most accurate/best, even for such a bad matrix? Is it
>> possible to say something about that? Looks like python has a lot more
>> digits but maybe that's just a random result... I mean.... Element 1,1 =
>> 2.81e14 in Python, but something like 3e14 in Matlab and so forth -
>> there's a small difference in the results...
>
> Both results are *wrong*: no inverse exists.

What's the best solution of the two wrong ones? Best least-squares 
solution or whatever?

>> With python, I would also kindly ask about how to avoid this problem in
>> the future, I mean, this maybe means that I have to check the condition
>> number at all times before doing anything at all ? How to do that?
>
> If cond(A) is high, you're trying to solve your problem the wrong way.

So you're saying that in another language (python) I should check the 
condition number, before solving anything?

> You should try to avoid matrix inversion altogether if that's the case.
> For instance you shouldn't invert a matrix just to solve a linear system.

What then?

Cramer's rule?



More information about the Python-list mailing list