MathGroup Archive 1999

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

Search the Archive

Re: Newbie question about rules

  • To: mathgroup at smc.vnet.net
  • Subject: [mg21371] Re: [mg21363] Newbie question about rules
  • From: "David Park" <djmp at earthlink.net>
  • Date: Wed, 29 Dec 1999 23:18:44 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

Doug,

The question is more: Why did the rule work in exp2? What happens is that the rhs is
evaluated. Then the rule is applied. In exp2 the evaluation did not change the
expression so Sin was still there for the rule to act upon. With exp, the Plot
statement was evaluated to produce the plot, and there was no Sin left for the rule
to act upon.

A different approach to your problem might be

plotfun[f_] := Plot[f[x], {x, 0, 2 Pi}]

plotfun[Sin]
- a Sin wave -

plotfun[Cos]
- a Cos wave -

Check out "Suggestions about learning Mathematica" in the front of The Mathematica
Book. Also work through as many of the relevant sections as you can in Part 1 of the
book. I would hate to say how many rules I've written that never matched! The clue is
order of evaluation, and checking the FullForm of the expression you are trying to
match.

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

>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: Re: Newbie question about rules