[Date Index]
[Thread Index]
[Author Index]
Re: HoldAll for Integrate
*To*: mathgroup at smc.vnet.net
*Subject*: [mg97974] Re: [mg97923] HoldAll for Integrate
*From*: "David Park" <djmpark at comcast.net>
*Date*: Fri, 27 Mar 2009 05:32:52 -0500 (EST)
*References*: <23611142.1238066136237.JavaMail.root@m02>
I would never write a statement like x = 10; x is too common a symbol to
give it a value and doing so just gets you into the kind of problem that you
did get into. Localize variables like x. For example make it an argument in
a function definition, f[x_] := something, or set it in a With statement
that contains expressions that use it.
But if you do give it a Global value, then localize it (with Block or
Module) where you don't want it to have a value.
x = 10;
Block[{x},
Integrate[x^2, {x, 0, 1}]]
1/3
David Park
djmpark at comcast.net
http://home.comcast.net/~djmpark/
From: Tammo Jan Dijkema [mailto:T.J.Dijkema at gmail.com]
The following commands yield unexpected output:
x=10;
Integrate[x^2, {x,0,1}]
That is because Integrate does not have attributes HoldAll, so that the
second command will be interpreted as Integrate[100, {10,0,1}] which is
not a command that Integrate can work with (so a warning message is
returned).
However, I can add the attribute HoldAll to Integrate myself:
SetAttributes[Integrate, HoldAll];
I'm not very sure what to expect when now trying the same experiment
(the correct answer 1/3 would be nice), but the actual output surprised
me:
x=10;
Integrate[x^2, {x,0,1}]
Yields as output: 0 (without any warnings). Could anyone explain why I
should have expected this result?
On a side note, I found a similar in the Tech Support column of the
Mathematica Journal Volume 6, Issue 2, by Carl Roy. He tried the
integral without limits:
x=10;
SetAttributes[Integrate, HoldAll];
Integrate[x^2, x]
In the journal, the output 1000/3 is mentioned, whereas in Mathematica
7.0.1 this outputs 1000.
Again, does anyone understand this?
Regards,
Tammo Jan Dijkema
Prev by Date:
**Re: solving nonlinear simultaneous equations**
Next by Date:
**Re: Asking PlotRange to take a Dynamic value**
Previous by thread:
**Re: HoldAll for Integrate**
Next by thread:
**Re: HoldAll for Integrate**
| |