I am experiencing unexpected behavior from Plot and D, and I would like to understand why. If I try this:
Plot[D[x,x],{x,1,10}]
I get a General::ivar error, but if I do this:
f = D[x,x]
Plot[f,{x,1,10}]
it works just fine. I come from a Python/Julia background, so I find this behavior baffling. What is going on here?
D[some number, some number], which of course does not make sense. You need to force pre-evaluation ofD, which is exactly what you achieve when you definef. You would obtain the same result withPlot[Evaluate@D[x, x], {x, 1, 10}]. Take a look at Evaluation of Expressions and in particular the part about non-standard evaluation. – MarcoB Apr 30 '20 at 19:44Dis a built-in function so you should probably choose another name. – anderstood Apr 30 '20 at 19:50