MathGroup Archive 2009

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

Search the Archive

Re: Replace and ReplaceAll -- simple application

  • To: mathgroup at smc.vnet.net
  • Subject: [mg105938] Re: [mg105922] Replace and ReplaceAll -- simple application
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Sun, 27 Dec 2009 02:24:33 -0500 (EST)
  • Reply-to: hanlonr at cox.net

expr = 1. (y1 - 1. yr);

expr /. x_?NumericQ -> Round[x]

y1-yr

expr // Rationalize

y1-yr

expr /. x_ :> Rationalize[x]

y1-yr


Bob Hanlon

---- amannuc1 <Anthony.J.Mannucci at jpl.nasa.gov> wrote: 

=============
I am doing some manipulations in Mathematica and end up with
constructs such as "1." in the expressions. I want to convert these to
"1" and thereby eliminate them. However, these examples don't seem to
work. This is Mathematica 7 on OS X.

In[40]:=
Replace[1.(y1-1.yr),1.->1]
Out[40]= 1. (y1-1. yr) (* Nothing happens *)

In[39]:=
ReplaceAll[1.(y1-1.yr),1.->1]
Out[39]= y1-1. yr (* Only first one is replaced *)

Any help is appreciated. Thanks.

-Tony



  • Prev by Date: Re: Manipulate Plot command - blank plot
  • Next by Date: Re: Replace and ReplaceAll -- simple application
  • Previous by thread: Re: Replace and ReplaceAll -- simple application
  • Next by thread: Re: Replace and ReplaceAll -- simple application