Group Abstract Group Abstract

Message Boards Message Boards

0
|
2.8K Views
|
1 Reply
|
0 Total Likes
View groups...
Share
Share this post:

When do Plot[] arguments get evaluated?

Posted 11 years ago

When I try to Plot[] and the second plot wants to be D[], I don't get the correct display. Instead, mathematica reports an error on execution.

Here's a simple example: Plot[{x, D[x, x]}, {x, 0, 5}]

I can get around this easily as f'[x] gets plotted properly as the second argument, ie

f[_x]:=x; Plot[{f[x],f'[x]},{x,0,5}]

works ok.

Shouldn't D[x,x] be evaluated before Plot gets to apply the values of x?

POSTED BY: Cal Page

Hi Cal,

this one would work:

Plot[{x, D[y, y] /. y -> x}, {x, 0, 5}]

It calculates the derivative first and then substitutes the value for x. This is trivial in this case, of course, as D[y,y] is identical 1. But it gives the same plot as

f[_x]:=x; Plot[{f[x],f'[x]},{x,0,5}]

Likewise,

Plot[{x, Evaluate[D[x, x]]}, {x, 0, 5}]

forces the evaluation of D[x,x] first and gives the desired result.

Cheers,

Marco

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