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: [mg48751] RE: [mg48738] Substitution ignored?
  • From: "David Park" <djmp at earthlink.net>
  • Date: Sat, 12 Jun 2004 23:33:40 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Jos,

Let's look at a simpler case.

f = x^2;
Plot[f /. x -> x - 1, {x, 0, 2}];

The arguments of Plot are held unevaluated until all the substitutions are
made. For each value of x, f and x are substituted into the held expression
and then the expression is evaluated.

The following illustrates the process for a particular value of x. (Copy it
and evaluate in a notebook.)

Print["The first argument held"]
Hold[f /. x -> x - 1]
Print["For each plotting value the routine substitutes for f"]
%% /. HoldPattern[f] -> x^2
Print["And also substitutes the current choice for x, say 0.01"]
%% /. x -> 0.01
Print["Then it releases the Hold to obtain the value"]
%% // ReleaseHold

The rule does not match because 0.01^2  is evaluated first to 0.0001.

If you evaluate the first argument, then it will work because the rule is
applied before any numerical values are substituted.

f = x^2
Plot[{  f,  f /. x -> x - 1  } // Evaluate, {x, 0, 2}];

David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/

From: Jos R Bergervoet [mailto:Jos.Lastname at Companyname.com]
To: mathgroup at smc.vnet.net


Dear MathGroup,

Why is the following going wrong?

f = x^2
Plot[{  f,  f /. x->x-1  }, {x,0,2}]   (* Identical functions plotted !!! *)

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


-- Jos





  • Prev by Date: RE: (**) comments highlighted - newbie
  • Next by Date: Re: Substitution ignored?
  • Previous by thread: Re: Substitution ignored?
  • Next by thread: Integral of a bivariate function