MathGroup Archive 2002

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

Search the Archive

Re: How to use error message return values

  • To: mathgroup at smc.vnet.net
  • Subject: [mg37731] Re: [mg37705] How to use error message return values
  • From: Andrzej Kozlowski <andrzej at tuins.ac.jp>
  • Date: Sun, 10 Nov 2002 05:38:32 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

One possibility:

inv[M_, p_] := Block[{$Messages = {}}, Check[Inverse[M, Modulus -> p], 
"Your
     matrix has no inverse modulo " <> ToString[p] <> ". Use another 
one."]]

In[2]:=
a = {{5, 17}, {4, 15}};

In[3]:=
b= {{5, 5}, {5, 5}};


In[4]:=
inv[a, 26]

Out[4]=
{{17,5},{18,23}}

In[5]:=
inv[b,26]

Out[5]=
Your matrix has no inverse modulo 26. Use another one.



Andrzej Kozlowski
Yokohama, Japan
http://www.mimuw.edu.pl/~akoz/
http://platon.c.u-tokyo.ac.jp/andrzej/





On Saturday, November 9, 2002, at 02:29 PM, flip wrote:

> Hello,
>
> I have a module which allows a user to definea matrix.
>
> This matrix may, of course, have an inverse or not have an inverse.
>
> As an example,
>
> In[15]:=
> c = {{5, 17}, {4, 15}};
>
> In[16]:=
> cinv = Inverse[c, Modulus -> 26]
>
> Out[16]=
> {{17, 5}, {18, 23}}
>
> In[17]:=
> c = {{5, 5}, {5, 5}};
>
> In[18]:=
> cinv = Inverse[c, Modulus -> 26]
>
> Inverse::"sing": "Matrix \!\({\(\({5, 5}\)\), \(\({5, 5}\)\)}\) is
> singular."
>
> Out[18]=
> Inverse[{{5, 5}, {5, 5}}, Modulus -> 26]
>
> How can I have my module fail in the case where an inverse does not 
> exist?
> I want to end the module and give the user an error message stating to 
> use a
> new matrix: this one does not have an inverse modulo 26.
>
> How can we in general take advantage of error messages or error return
> values in order to do this?
>
> Thanks, Flip
>
> Note: remove "_alpha" to send me an email.
>
>
>
>
>



  • Prev by Date: Re: Mathematica 4.2: Problem with online help.
  • Next by Date: Re: FindRoot and Inequalities
  • Previous by thread: How to use error message return values
  • Next by thread: Re: How to use error message return values