Re: Newbie question about rules
- To: mathgroup at smc.vnet.net
- Subject: [mg21370] Re: [mg21363] Newbie question about rules
- From: Andrzej Kozlowski <andrzej at tuins.ac.jp>
- Date: Wed, 29 Dec 1999 23:18:43 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
What you are doing is evaluating: ReplaceAll[Plot[Sin[x], List[x, 0, Pi]], Rule[Sin, Cos]] However: In[10]:= Attributes[ReplaceAll] Out[10]= {Protected} This means that RepaceAll evaluates its arguments, so the replacement is doneonly after the graph is plotted and has no effect. This has nothing to do with Plot, you get the same result in: In[14]:= Sin[Pi/2] /. Sin -> Cos Out[14]= 1 So what you have to do is to prevent early evaluation, e.g.: Unevaluated[Plot[Sin[x], {x, 0, Pi}]] /. Sin -> Cos will give the graph of Cos. > From: dougn_NOspam at gte.net (Doug Nelson) To: mathgroup at smc.vnet.net > Date: Wed, 29 Dec 1999 14:15:49 -0500 (EST) > To: mathgroup at smc.vnet.net > Subject: [mg21370] [mg21363] Newbie question about rules > > Hello All, > > I just received my copy of Mathematica 4.0 and I've been reading Mastering > Mathematica. > > I'm trying to apply a rule that changes "Sin" to "Cos" in an expression. It > seems to work fine with normal expressions, but not with a Plot function. > > This works: > exp2 := Abcfunc[Sin[x]] > exp2 /. Sin -> Cos > out = Abcfunc[Cos[x]] > > However, the following gives me a sine wave plot in both cases: > > exp := Plot[Sin[x], {x,0,2 Pi}] > exp > out = < a sine wave plot > > > exp /. Sin -> Cos > out = < another sine wave plot ! > > > Why don't I get a cosine plot? > > Thanks in advance, > Doug >