Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2004
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Substitution ignored?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg48745] Re: Substitution ignored?
  • From: Bill Rowe <readnewsciv at earthlink.net>
  • Date: Sat, 12 Jun 2004 23:33:35 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

On 6/11/04 at 11:59 PM, Jos.Lastname at Companyname.com (Jos R
Bergervoet) wrote:

>Why is the following going wrong?
>
>f = x^2 
>Plot[{  f,  f /. x->x-1  }, {x,0,2}]   (* Identical functions plotted !!! *)

This is due to the non-standard way Plot evaluates its arguments. What happens is Plot substitutes a numeric value for x before the rule is applied. Of course, when this happens there is no match and it is as if there were no rule at all. If you force evaluation of the expression before Plot substitutes a numeric value for x, i.e., do Plot[Evaluatate@{f,f/.x->x-1},{x,0,2}] then you will get the two curves you expect.

>g = f /. x->x-1 
>Plot[{f, g}, {x,0,2}]     (* OK, different functions plotted *)

And this works because it evaluates f/.x->x-1 before Plot assigns numeric values.

--
To reply via email subtract one hundred and four


  • Prev by Date: Re: How to plot a direction field?
  • Next by Date: RE: (**) comments highlighted - newbie
  • Previous by thread: Re: Substitution ignored?
  • Next by thread: RE: Substitution ignored?