f



Can I convert a warning message to a error message to use try...catch?

Hi guys:

I am trying to use "try catch" to find a singular matrix and then take
inverse of non-singular matrix! However, there is only a warning
message for inv() command. How can I convert a warning to a error then
I can use try and catch?


Thanks

0
Fei
4/18/2006 11:37:05 AM
comp.soft-sys.matlab 211266 articles. 25 followers. lunamoonmoon (257) is leader. Post Follow

6 Replies
755 Views

Similar Articles

[PageSpeed] 19

"Fei" <joey_qf@163.com> wrote in message 
news:1145360225.610363.128650@i39g2000cwa.googlegroups.com...
> Hi guys:
>
> I am trying to use "try catch" to find a singular matrix and then take
> inverse of non-singular matrix! However, there is only a warning
> message for inv() command. How can I convert a warning to a error then
> I can use try and catch?

Don't.  Check the condition number of the matrix first (using COND or RCOND) 
to see if it's ill-conditioned or singular, and/or use the backslash 
operator instead of computing the inverse.

-- 
Steve Lord
slord@mathworks.com 


0
slord (13689)
4/19/2006 3:56:33 AM
Fei skrev:
> Hi guys:
>
> I am trying to use "try catch" to find a singular matrix and then take
> inverse of non-singular matrix!

Error-handling stuff like divide-by-zero signals, interrupts and
try-catch
don't work very well as substitutes for control loops. I remember
trying
to used the divide-by-zero signal to catch the x==0 case in a sin(x)/x
expression, to avoid the test 'if x==0' for every single element.

It turned out to be a very bad idea. First, it detected that *a*
computation had been a divide-by-zero, but no information about
*which*one* was kept at a useful place, as the OS got into
error-handling mode.

And even if you could get that, there was no way of knowing
where to resume computations afterwards. Keeping track of
how many computations had been done, how many remained,
and so on, turned out to be a nightmare. It was far easier to
use the familiar 'if x==0' test.

Basically, try-catch for numerical problems are ways to detect
(and handle) the numerical problems you did not foresee while
programming. If your program throws an exception, you have to
analyze what happened and see if there was some sort of
"anormal" feature somewhere that you as programmer forgot
to account for the first time around.

Rune

0
allnor (8509)
4/19/2006 4:25:46 AM
Thank you! Steve!

0
Fei
4/26/2006 4:40:11 PM
Thank you! Steve!

0
Fei
4/26/2006 4:40:14 PM
Thank you! Steve!

0
Fei
4/26/2006 4:40:26 PM
Thank you Rune too!

0
Fei
4/26/2006 4:41:00 PM
Reply: