Message Boards Message Boards

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

Possible bug on Plot and ReplaceAll

Posted 9 years ago

Hi, I use ReplaceAll a lot, and I've been having some trouble with it. This

Plot[a x,{x,-5,5}]/.a->3

does not give the result I was expecting

Plot[3 x,{x,-5,5}]

and gives instead blank graphics with an axis. Any ideas why?

POSTED BY: Darwin Kim
Posted 9 years ago

If you compare

Plot[a x, {x, -5, 5}] /. a -> 3

and

Plot[a x /. a -> 3, {x, -5, 5}]

I think you might be able to guess that the first one is first trying to do the Plot, not knowing the value of 'a' and failing, and perhaps then considering the substitution

while the second one is first doing the substitution and then doing the Plot.

You might test this idea under other circumstances, perhaps even using ReplaceAll[a x,a->3] instead of the /. and try to see if you can recognize a general pattern in the way that evaluation of expressions is done within Mathematica.

This may be somewhat complicated because Plot and some other functions do not perform evaluation in exactly the same way that generic expressions do.

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

Group Abstract Group Abstract