MathGroup Archive 1999

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

Search the Archive

Re: Newbie question about rules

  • To: mathgroup at smc.vnet.net
  • Subject: [mg21369] Re: Newbie question about rules
  • From: "Atul Sharma" <atulksharma at yahoo.com>
  • Date: Wed, 29 Dec 1999 23:18:43 -0500 (EST)
  • References: <84dn7q$31a@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Plot has the Attribute HoldAll

Attributes[Plot]

{HoldAll, Protected}

This means that the arguement is not evaluated in advance, and your
transformation rule is not applied before the function is plotted. Wrap the
expression in Evaluate to force evaluation of the rule and you will get the
result you want:

 Plot[Evaluate[(Sin[x] /. Sin -> Cos)], {x, 0, 2 Pi}]

A. Sharma
--------------------------------------------------
Atul Sharma MD, FRCP(C)
Pediatric Nephrologist,
McGill University/Montreal Children's Hospital



Doug Nelson wrote in message <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: Number Format, Padded Form
  • Next by Date: FourierTransform[Sign[t], t, w, FourierParameters -> {1, -1}]
  • Previous by thread: Re: Newbie question about rules
  • Next by thread: Re: Newbie question about rules