Re: How does NIntegrate suppress messages?

• To: mathgroup at smc.vnet.net
• Subject: [mg62614] Re: How does NIntegrate suppress messages?
• From: Andrew Moylan <andrew.moylan at anu.edu.au>
• Date: Tue, 29 Nov 2005 04:46:21 -0500 (EST)
• References: <dm95bd\$6q1\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Excellent, thanks Ingolf. I think your post answers all the questions

Ingolf Dahl wrote:
> Hi
> A general method to suppress messages from Check is the following:
>
>   Block[{\$Messages = {}}, Check[expr, failexpr]]
>
> My theory is that Nintergrate uses the same mechanism. Can we find a way to
> unsuppress the messages?
>
> One example:
>
>   func[x_]:=1/x;
>
>   x=0;Check[func[x],"Divide by zero"]
>
> gives both a message and evalutated failexpr, but
>
>   x = 0; Block[{Set[\$Messages, {}]}, Check[func[x], "Divide by zero"]]
>
> just evaluates failexpr. We might turn on the messages by redefining the
> function:
>
>   newfunc[x_] := Block[{Set[\$Messages, {OutputStream["stdout", 1]}]},
> func[x]];
>
>   x = 0; Block[{Set[\$Messages, {}]}, Check[newfunc[x], "Divide by zero"]]
>
> will give us the message back. To apply the same on NIntegrate is a bit
> tricky.Define first
>
>   f::err = "error"; f[x_?NumericQ] := ( Message[f::err]; x )
>
> Then
>
>   NIntegrate[f[x], {x, 0, 1}]
>
> will give no messages. Embedd f in a new function in the following ways:
>
>    newf[ x_?NumericQ]:= ( Block[ { \$MessageList=msl, \$Messages= {
> OutputStream[     "stdout",1]}}, { f[x], msl=\$MessageList}[[1]]])
>
>   msl = {}; NIntegrate[newf[x], {x, 0, 1}]
>
> will then give you error messages. The NumericQ test is essential.
>
> Best regards
>
> Ingolf Dahl
> Sweden
>
>
>
>
>>-----Original Message-----
>>From: Andrew Moylan [mailto:andrew.moylan at anu.edu.au]
To: mathgroup at smc.vnet.net
>>Sent: den 25 november 2005 08:25
>>Subject: [mg62614]  Re: How does NIntegrate suppress messages?
>>
>>It's quite a mystery. My guess is that NIntegrate temporarily
>>redefines the Message[...] function.
>>
>>Personally, I want to know because I want to copy this
>>behaviour of NIntegrate for my own functions, if it is easy.
>>Often I write code that uses Check, and I don't want the
>>messages generated and appearing as errors and clogging up the output.
>>
>>"Alan" <info at optioncity.REMOVETHIS.net> wrote in message
>>news:dm499k\$srh\$1 at smc.vnet.net...
>>
>>>"Andrew Moylan" <andrew.moylan at anu.edu.au> wrote in message
>>>news:dm1b0v\$ic1\$1 at smc.vnet.net...
>>>
>>>>Whenever the integrand in NIntegrate generates messages
>>
>>(by calling
>>
>>>>Message), the output of these messages are suppressed,
>>
>>although they
>>
>>>>are still generated in the sense that they can be caught
>>
>>using Check.
>>
>>>>Does anyone know how NIntegrate does this?
>>>
>>
>>behavior which
>>
>>>has always seemed a puzzle. Often I will wrap a complicated
>>>computation in a Check in order to Abort[] on any message. Then, I
>>>will sometimes get an Abort[], but no message! And, indeed,
>>
>>often an
>>
>>>NIntegrate is involved. When that occurs, I have never been able to
>>>re-write the code to retrieve those missing messages.
>>>So if there is a way to "unsuppress", that will be helpful
>>
>>to me, too.
>>
>>>regards,
>>>alan
>>>
>>>
>>
>>
>>
>
>

```

• Prev by Date: Re: FW: 3D plot question
• Next by Date: Re: Bypassing built-in functions in differentiation
• Previous by thread: Re: Re: How does NIntegrate suppress messages?
• Next by thread: How to print on paper big matrixes ?