[Date Index]
[Thread Index]
[Author Index]
Re: question about Block
 To: mathgroup at smc.vnet.net
 Subject: [mg69718] Re: question about Block
 From: "JensPeer Kuska" <kuska at informatik.unileipzig.de>
 Date: Thu, 21 Sep 2006 07:31:08 0400 (EDT)
 Organization: Uni Leipzig
 References: <eeqpqm$oel$1@smc.vnet.net>
Hi,
since there is no function, that tell you the
answer to the question
is message func::xyz On or Off you can't switch
off
the message in your functions, because you will
change a global
state. So, if you wish to turn off the messages
inside of your
function but don't change the global state you
have to use
the Block[{Message},..] construction.
Regards
Jens
<dimmechan at yahoo.com> schrieb im Newsbeitrag
news:eeqpqm$oel$1 at smc.vnet.net...
 Hello to all.

 Block as it is well known to the members of this
forum does have some
 nice applications.
 For example

 $Version
 "5.2 for Microsoft Windows (June 20, 2005)"

 Block[{Message}, Integrate[1/x, {x, 1, 2}]]
 Infinity
 Block[{Message}, NIntegrate[Sin[x]/x, {x, 0,
Infinity}]]
 2.6457805920701

 (execute the commands without Block to see the
messages)

 Let me now define a list of two functions.

 lst = {1/x, 1/x^2};

 Then

 NIntegrate[lst, {x, 1, 2}]
 \!\(NIntegrate::"inum" : "Integrand \!\({1\/x,
 1\/x\^2}\) is not numerical at \!\({x}\) =
{1.5`}."\)
 NIntegrate[lst, {x, 1, 2}]

 because NIntegrate has the attribute HoldAll

 Attributes[NIntegrate]
 {HoldAll, Protected}

 Of course

 NIntegrate[Evaluate[lst], {x, 1, 2}]
 {0.693147180559947, 0.5000000000000211}

 Now to my surprise I discovered that the
following commands fail to
 prevent the appearance of NIntegrate::inum
message.

 Block[{Message}, NIntegrate[lst, {x, 1, 2}]]
 \!\(NIntegrate::"inum" : "Integrand \!\({1\/x,
 1\/x\^2}\) is not numerical at \!\({x}\) =
{1.5`}."\)
 NIntegrate[lst, {x, 1, 2}]

 Block[{$Messages = {}}, NIntegrate[lst, {x, 1,
2}]]
 \!\(NIntegrate::"inum" : "Integrand \!\({1\/x,
 1\/x\^2}\) is not numerical at \!\({x}\) =
{1.5`}."\)
 NIntegrate[lst, {x, 1, 2}]

 What is more strange is that the relevant
Plot::plnr message can be
 prevented.

 Plot[lst, {x, 1, 2}, DisplayFunction >
Identity];
 Plot::plnr : lst is not a machinesize real
number at x =
 1.0000000416666666`. (...3 times...)
 General::stop : Further output of Plot::plnr
will be suppressed during
 this \
 calculation.

 Attributes[Plot]
 {HoldAll, Protected}

 Block[{Message}, Plot[lst, {x, 1, 2},
DisplayFunction > Identity]];
 Block[{$Messages = {}}, Plot[lst, {x, 1, 2},
DisplayFunction >
 Identity]];

 Of course someone can simply switch off the
message.

 Off[NIntegrate::inum]
 NIntegrate[lst, {x, 1, 2}]
 NIntegrate[lst, {x, 1, 2}]

 On[NIntegrate::inum]

 but the question remains why exist this strange
(at least for me)
 situation.

 Any comments/suggestions?

 Dimitris

Prev by Date:
sum up
Next by Date:
Re: an equation containg radicals
Previous by thread:
Re: question about Block
Next by thread:
Re: question about Block
 