MathGroup Archive 2009

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

Search the Archive

Re: Replacing Values Close to One


On 26 Nov., 05:00, Gregory Lypny <gregory.ly... at videotron.ca> wrote:
> Hello everyone,
>
> Is there a replacement rule that I can apply to
>
>         {-8, .7, 0, 1.003}  /.  [what goes here?] -> 1
>
> to replace values that are close to 1, like 1.003, by 1?
>
> Regards,
>
>         Gregory

Hi,

you can use Chop which sets numbers close to zero to zero:

{-8, .7, 0, 1.003} /. x_ :> (Chop[x - 1, 0.01] + 1)


here I gave 0.01 as tolerance. Change it to your needs.

Cheers,

Markus


  • Prev by Date: Re: Replacing Values Close to One
  • Next by Date: Re: Replacing Values Close to One
  • Previous by thread: Re: Replacing Values Close to One
  • Next by thread: Re: Re: Replacing Values Close to One