MathGroup Archive 1999

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

Search the Archive

Re: Newbie question about rules

  • To: mathgroup at smc.vnet.net
  • Subject: [mg21373] Re: Newbie question about rules
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Wed, 29 Dec 1999 23:18:46 -0500 (EST)
  • References: <84dn7q$31a@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Doug,

exp := Plot[Sin[x], {x, 0, 2 Pi}]
exp

[ display cut]

-Graphics-

The output here is indicated by -Graphics- this contains the line object of
the form Line[{{x1,y1},{x2,y2},...}] that has been constructed from Sin[x]
and then shown in the display (the  display is not the output - it is a side
effect)
You can see the code in -Graphics- by looking at

InputForm[%] (*% is the previous output*)

The important thing to  notice is that Sin does not appear in -Graphics-

Now,

exp /. Sin -> Cos

Evaluates as follows:
1. exp evaluates as before, displaying the sine curve and giving the same
output,
2. output/.Sin->Cos is just output since output has no Sin to be replaced.
3. even if there had been a change th eresult would only have been displayed
if Show had been used


exp /. ln : Line[_] -> {Hue[0], ln}

Changes the code to that for a red line.
But we have to tell Mathematica to show this:

Show[%]


Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565



"Doug Nelson" <dougn_NOspam at gte.net> wrote in message
news:84dn7q$31a at smc.vnet.net...
> 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
>



  • Prev by Date: Re: Newbie question about rules
  • Next by Date: Re: Newbie question about rules
  • Previous by thread: Re: Newbie question about rules
  • Next by thread: Symbolize and Notation