1

Example code:

f[y_] := NIntegrate[x, {x, 0, y}]
Plot[f[y], {y, 0, 1}]

It works in v10.4, but in v11.0, even though Mathematica shows the plot, it also gives (the same) errors:

NIntegrate:x=y is not a valid limit of integration.
NIntegrate:x=y is not a valid limit of integration.

The error is nonsense to me since Plot has attributes HoldAll, and I know I can suppress the errors by adding ?NumericQ to the parameter y, however, the question is

WHY?

luyuwuli
  • 2,814
  • 19
  • 25
  • out of curiosity, what do you get evaluating Trace[Plot[f[y], {y, 0, 1}], f]? Or better yet, what evaluating Trace[Plot[f[y], {y, 0, 1}], f, TraceInternal -> True]? An evaluation of the form f[y] should explain why this happen (I don't see any in v10.4, and I do not experience this behaviour) – glS Sep 17 '16 at 10:57
  • @glS The nontrival part is NIntegrate[x, {x, 0, 0.0000204286}], both in v11 and 10.4 – luyuwuli Sep 17 '16 at 11:02
  • what if you try with the TraceInternal option? – glS Sep 17 '16 at 11:03
  • @glS I think they are the same. The form is f[val],NIntegrate[x,{x,0,val}] where val is the points between 0 and 1. – luyuwuli Sep 17 '16 at 11:08
  • 2
    As Plot[f[Echo[y]], {y, 0.01, 1}] shows, the function is evaluated symbolically at one point. As you already stated, one can prevent the symbolic evaluation by using ?NumericQ. What precisely is your question? Why there is a symbolic evaluation or why it is different in v11 than in v10? – Karsten7 Sep 17 '16 at 11:16
  • 2
    Specifically this answer: http://mathematica.stackexchange.com/a/26037/12 and http://support.wolfram.com/kb/12502 The fact that it worked in 10.4 doesn't mean that doing it this way is correct. You do need NumericQ there. Plot uses heuristics to try to save you from this mistake but it's not foolproof. – Szabolcs Sep 17 '16 at 11:24
  • @Szabolcs Thanks for the link, but I'm still confused after reading it. Since Plot hold its arguments, the seems no reason for f[y] to be pre-evaluated, i.e. y will always be a numeric value, so it should be no warnings despite of its low efficiency. – luyuwuli Sep 17 '16 at 11:40
  • 2
    @luyuwuli HoldAll means that the argument is passed into a function without evaluation, so the function can do whatever it wants with it. That includes evaluating it. Plot does evaluate it. Example: SetAttributes[fun, HoldAll]; fun[x_] := x. When you call fun[x], x gets evaluated at some point, just a little later than it would be without HoldAll. – Szabolcs Sep 17 '16 at 11:43
  • @Szabolcs Ah. I understand it. Thanks! (What a silly mistake I've made.) – luyuwuli Sep 17 '16 at 11:45
  • @luyuwuli Plot even has an undocumented Evaluated option which controls what sorts of evaluations it will attempts internally. I don't fully understand its effect, and setting it to False doesn't fix things here ... Maybe something is wrong with v11. One reason why Plot would evaluate the function with a symbolic argument is that it may do symbolic processing to determine the Exclusions. – Szabolcs Sep 17 '16 at 11:49
  • 1
    @luyuwuli You may be interested in this post. –  Sep 17 '16 at 11:53
  • @Szabolcs Yes, I've also tried Evaluated->False, it dosen't prevent the error (even thougth I didn't post it in the question.) I thought it was the same as the HoldAll attributes. Your comment reminds me that indeed some non-trival part is modified in v11. – luyuwuli Sep 17 '16 at 11:55

0 Answers0