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: [mg37815] Re: [mg37705] How to use error message return values
  • From: Omega Consulting <omega_consulting at yahoo.com>
  • Date: Wed, 13 Nov 2002 01:13:29 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

At 11:29 PM 11/8/2002, 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.

There have been a couple responses using Check, which is just fine, but you 
can also use the return value.

f[c_]:=
Module[{cinv},
   cinv = Block[{$Messages={}},
     Inverse[c, Modulus->26]
   ];
   If[Head[cinv] === Inverse,
     Message[...]; Return[$Failed]
   ];
   ...
]

--------------------------------------------------------------
Omega Consulting
"The final answer to your Mathematica needs"



  • Prev by Date: Re: Literate Programming (Was: Comments are KILLING me)
  • Next by Date: Re: InequalitySolve
  • Previous by thread: RE: Re: How to use error message return values
  • Next by thread: TeXForm and array-like output