13.07.2015 Views

Mathematica Tutorial: Notebooks And Documents - Wolfram Research

Mathematica Tutorial: Notebooks And Documents - Wolfram Research

Mathematica Tutorial: Notebooks And Documents - Wolfram Research

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

140 <strong>Notebooks</strong> and <strong>Documents</strong>In[14]:=Out[14]= 1Evaluating 1^0 produces no messages, so the result of the evaluation is returned.Check@1^0, errDIn[15]:=Evaluating 0^0 produces a message, so the second argument of Check is returned.Check@0^0, errDOut[15]= errPower::indet : Indeterminate expression 0 0 encountered. àCheck@expr, failexprD tests for all messages that are actually printed out. It does not test formessages whose output has been suppressed using Off.In some cases you may want to test only for a specific set of messages, say ones associatedwith numerical overflow. You can do this by explicitly telling Check the names of the messagesyou want to look for.In[16]:=The message generated by Sin@1, 2D is ignored by Check, since it is not the one specified.Check@Sin@1, 2D, err, General::indDOut[16]= Sin@1, 2DSin::argx : Sin called with 2 arguments; 1 argument is expected. àMessage@s::tagDMessage@s::tag,expr 1 ,…Dprint a messageprint a message, with the expr i spliced into its string formGenerating messages.By using the function Message, you can mimic all aspects of the way in which built-in <strong>Mathematica</strong>functions generate messages. You can for example switch on and off messages using On andOff, and Message will automatically look for General::tag if it does not find the specificmessage s::tag.This defines the text of a message associated with f.In[17]:= f::overflow = "Factorial argument `1` too large."Out[17]= Factorial argument `1` too large.In[18]:=Here is the function f.f@x_D := If@x > 10, HMessage@f::overflow, xD; InfinityL, x!DWhen the argument of f is greater than 10, the message is generated.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!