Skip to main content
7 events
when toggle format what by license comment
Jun 11, 2016 at 6:26 vote accept xzczd
Jun 10, 2016 at 7:36 comment added Alexey Popkov @xzczd You can force Plot to work like NIntegrate using undocumented option Evaluated -> True: Plot[D[x, x], {x, 0, 1}, Evaluated -> True].
Jun 10, 2016 at 7:32 comment added Alexey Popkov @xzczd Yes, but these details aren't from the HoldAll attribute: it is internal working of these functions. Actually Plot also evaluates f with variables being symbolic as you can see from f[x_Symbol] := Print["symbolic evaluation!"]; f[x_Real] := x; Plot[f[x], {x, 0, 1}];.
Jun 10, 2016 at 7:19 comment added xzczd No, they're not same, as mentioned by Marius Ladegård Meyer in the answer above: "NIntegrate first localizes the values of all variables, then evaluates f with the variables being symbolic, and then repeatedly evaluates the result numerically." If *Plot/*Plot3D works like this, then D[x, x] will become 1 before the numeric value is plugged in.
Jun 10, 2016 at 6:26 comment added Alexey Popkov @xzczd Actually Plot and Plot3D also work the same way: they do have the HoldAll attribute but in version 10 somehow it is not listed when you evaluate Plot // Attributes (in previous versions it was listed). You can receive direct evidence that the attribute does work by evaluating Trace[Plot[x + x, {x, 0, 2}]][[;; 2]]. As to "Why Plot[D[x, x], {x, 0, 1}] doesn't work?", it is easy to understand it you remember that Plot localizes variables like Block (read the first point under the "Details and Options" section!). So with Block[{x = 1}, D[x, x]] you get exactly the same!
Jun 10, 2016 at 4:47 comment added xzczd I think now I understand the meaning of this design, if NIntegrate just owns HoldRest, something like x = 0; NIntegrate[x + x, {x, 1, 2}] won't give the desired result, but then another question comes to my mind: why *Plot/*Plot3D isn't designed to be like this? If so, there won't be any "Why Plot[D[x, x], {x, 0, 1}] doesn't work?" question!… well, maybe I should once again start a new question?
Jun 9, 2016 at 9:35 history answered Alexey Popkov CC BY-SA 3.0