Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2009

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

Search the Archive

Re: HoldAll for Integrate

  • To: mathgroup at smc.vnet.net
  • Subject: [mg97997] Re: HoldAll for Integrate
  • From: David Bailey <dave at removedbailey.co.uk>
  • Date: Fri, 27 Mar 2009 05:37:18 -0500 (EST)
  • References: <gqfknb$kht$1@smc.vnet.net>

Tammo Jan Dijkema wrote:
> 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
> 
> 
Changing an attribute for a function, is like making a change to its 
code - the effect is completely unpredictable!

The purpose of the HoldAll attribute is to let the writer of the 
function get access to the original expression, but that expression may 
also get evaluated internally within the function, as the following 
example illustrates:

SetAttributes[debugPrint,HoldAll];

debugPrint[x_]:=Print[Unevaluated[x],"=",x];

(try it - it is quite useful)

The correct way to perform your calculation, is

x = 10;
Integrate[y^2, {y, 0, x}]

(where y does not have a value)

David Bailey
http://www.dbaileyconsultancy.co.uk




  • Prev by Date: Re: animation in version 7.0 looks bad
  • Next by Date: Interpolation with Method->Spline
  • Previous by thread: Re: HoldAll for Integrate
  • Next by thread: Re: HoldAll for Integrate