MathGroup Archive 2006

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

Search the Archive

question about Block

  • To: mathgroup at smc.vnet.net
  • Subject: [mg69661] question about Block
  • From: dimmechan at yahoo.com
  • Date: Wed, 20 Sep 2006 02:44:07 -0400 (EDT)

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 machine-size 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: Re: attention 64 bit Mathematica users - would you please test a command for me?
  • Next by Date: Re: an equation containg radicals
  • Previous by thread: Re: Iterative constants and variables definitions
  • Next by thread: Re: question about Block