MathGroup Archive 2003

[Date Index] [Thread Index] [Author Index]

Search the Archive

RE: Testing for invertible matrix

  • To: mathgroup at smc.vnet.net
  • Subject: [mg39701] RE: [mg39676] Testing for invertible matrix
  • From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.com>
  • Date: Mon, 3 Mar 2003 04:24:50 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

>-----Original Message-----
>From: Bob Harris [mailto:NspamITmeLION at MINDnotSPRING.COM]
To: mathgroup at smc.vnet.net
>Sent: Saturday, March 01, 2003 8:49 AM
>To: mathgroup at smc.vnet.net
>Subject: [mg39701] [mg39676] Testing for invertible matrix
>
>
>Howdy,
>
>If there some means to test whether a square matrix is 
>invertible, rather
>than trying Invert[] and having it fail?
>
>I'm working on a notebook that's searching through randomly generated
>matrices, looking for one for which the inverse has certain properties.
>Thus inside my search function I have a loop something like this:
>
>    While [... some condition ,
>        t = ... create a matrix   ;
>        q = Inverse[t] ;
>
>        ... perform some computation using the entries in q
>            to determine if the exit condition will be met
>        ];
>
>But if t is singular, computing the inverse fails.  
>Nevertheless my loop
>keeps running for a while, but generates a few more annoying messages
>(because access to q fails) before it finally quits.
>
>What I would rather do is something like this:
>
>    While [... some condition ,
>        t = ... create a matrix   ;
>        If [ t is singular, Continue[]];
>
>        q = ... inverse of matrix ;
>
>        ... perform some computation using the entries in q
>            to determine if the exit condition will be met
>        ];
>
>But looking through the mathematica book, I haven't come 
>across a way to do
>that.  I also considered that Inverse[] would have some means 
>for me to tell
>it how to handle the failure condition, but I don't see 
>anything in the book
>about that.
>
>Thanks in advance for any help,
>Bob H
>Lawrenceville, GA
>
>
>

You may just try and catch the faulty case with Check:

In[13]:=
n = 0; noExit = True;
While[++n < 50 && noExit,
    t = Partition[Table[Random[Integer, {-5, 5}], {4}], 2]; 
    q = Check[Inverse[t], Continue[], Inverse::"sing"];
    noExit = Tr[q] > -2.5
    ];
ToString[n] <> " trys"

>From In[13]:=
Inverse::"sing": "Matrix {{\(-3, 0}, {0, 0}} is singular."
>From In[13]:=
Inverse::"sing": "Matrix {{0, 0}, {5, -3}} is singular."

Out[15]= "45 trys"

--
Hartmut Wolf



  • Prev by Date: RE: Incrementing a "For" loop - "For loop.nb" 5893 Bytes yEnc
  • Next by Date: Re: Help Providing a Module
  • Previous by thread: Re: Testing for invertible matrix
  • Next by thread: Re: Testing for invertible matrix