Re: question about Block

*To*: mathgroup at smc.vnet.net*Subject*: [mg69788] Re: question about Block*From*: dimmechan at yahoo.com*Date*: Sat, 23 Sep 2006 04:44:20 -0400 (EDT)*References*: <eeqpqm$oel$1@smc.vnet.net><eetv8f$9uk$1@smc.vnet.net>

Dear Jens, Because maybe I was not very clear, I will state gain my question. Both of the following commands fail to prevent the presence of the NIntegrate::inum message. Can you understand why? lst={1/x,1/x^2}; 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}] Thanks Î?/Î? Jens-Peer Kuska ÎÎ³Ï?Î±Ï?Îµ: > 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 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 > |