Group Abstract Group Abstract

Message Boards Message Boards

0
|
1.5K Views
|
4 Replies
|
5 Total Likes
View groups...
Share
Share this post:

Why is Evaluate[ ] needed for D[ ] inside Plot[ ]?

Why do I need the Evaluate[] in the code below?

cdf = CDF[NormalDistribution[0, 1], x]
Plot[D[cdf, x], {x, -3, 3}] (* Doesn't work *)
Plot[Evaluate[D[cdf, x]], {x, -3, 3}]  (* Works *)
POSTED BY: Jay Gourley
4 Replies
POSTED BY: Michael Rogers

One more explanation:

Plot has the attribute HoldAll - for good reasons! Just mimic of not having this attirbute (and try):

x = 3;
Plot[Evaluate@Sin[x], {x, 0, 2 Pi}]
POSTED BY: Henrik Schachner

Mathematica users must get used to this. Plot gives a numerical value to x before it evaluates the derivative, resulting in something like (d f(1)) / (d1) from (d f(x)) / (dx). Evaluate forces the symbolic calculation of the derivatives before the numerical values come in. Also compare

Plot[RandomReal[], {x, 0, 1}]
Plot[Evaluate[RandomReal[]], {x, 0, 1}]
POSTED BY: Gianluca Gorni
Posted 6 months ago

Plot can be thought of as an extended Table, with the difference that Plot gives a graphical output.

Testing your example with Table gives some insight from the error messages and in the output:

POSTED BY: Hans Milton
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard