numpy (matrix solver) - python vs. matlab

Steven_Lord slord at mathworks.com
Wed May 2 10:47:57 EDT 2012



"Russ P." <russ.paielli at gmail.com> wrote in message 
news:2275231f-405f-4ee3-966a-40c821b7c0a8 at 2g2000yqp.googlegroups.com...
> On May 1, 11:52 am, someone <newsbo... at gmail.com> wrote:
>> On 04/30/2012 03:35 AM, Nasser M. Abbasi wrote:
>>
>> > On 04/29/2012 07:59 PM, someone wrote:
>> > I do not use python much myself, but a quick google showed that pyhton
>> > scipy has API for linalg, so use, which is from the documentation, the
>> > following code example
>>
>> > X = scipy.linalg.solve(A, B)
>>
>> > But you still need to check the cond(). If it is too large, not good.
>> > How large and all that, depends on the problem itself. But the rule of
>> > thumb, the lower the better. Less than 100 can be good in general, but 
>> > I
>> > really can't give you a fixed number to use, as I am not an expert in
>> > this subjects, others who know more about it might have better
>> > recommendations.
>>
>> Ok, that's a number...
>>
>> Anyone wants to participate and do I hear something better than "less
>> than 100 can be good in general" ?
>>
>> If I don't hear anything better, the limit is now 100...
>>
>> What's the limit in matlab (on the condition number of the matrices), by
>> the way, before it comes up with a warning ???

I'm not going to answer, and the reason why is that saying "the limit is X" 
may lead you to believe that "as long as my condition number is less than X, 
I'm safe." That's not the case. The threshold above which MATLAB warns is 
the fence that separates the tourists from the edge of the cliff of 
singularity -- just because you haven't crossed the fence doesn't mean 
you're not in danger of tripping and falling into the ravine.

> The threshold of acceptability really depends on the problem you are
> trying to solve.

I agree with this statement, although you generally don't want it to be too 
big. The definition of "too big" is somewhat fluid, though.

>  I haven't solved linear equations for a long time,
> but off hand, I would say that a condition number over 10 is
> questionable.

That seems pretty low as a general bound IMO.

> A high condition number suggests that the selection of independent
> variables for the linear function you are trying to fit is not quite
> right. For a poorly conditioned matrix, your modeling function will be
> very sensitive to measurement noise and other sources of error, if
> applicable. If the condition number is 100, then any input on one
> particular axis gets magnified 100 times more than other inputs.
> Unless your inputs are very precise, that is probably not what you
> want.
>
> Or something like that.

Russ, you and the OP (and others) may be interested in one of the books that 
Cleve Moler has written and made freely available on the MathWorks website:

http://www.mathworks.com/moler/

The chapter Linear Equations in "Numerical Computing with MATLAB" includes a 
section (section 2.9, starting on page 14 if I remember correctly) that 
discusses norm and condition number and gives a more formal statement of 
what you described. The code included in the book is written in MATLAB, but 
even if you don't use MATLAB (since I know this has been cross-posted to 
comp.lang.python) there's plenty of good, crunchy mathematics in that 
section.

-- 
Steve Lord
slord at mathworks.com
To contact Technical Support use the Contact Us link on 
http://www.mathworks.com 




More information about the Python-list mailing list