Re: Replacing Values Close to One
- To: mathgroup at smc.vnet.net
- Subject: [mg105292] Re: Replacing Values Close to One
- From: "M.Roellig" <markus.roellig at googlemail.com>
- Date: Thu, 26 Nov 2009 06:14:30 -0500 (EST)
- References: <hekug7$921$1@smc.vnet.net>
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
- Follow-Ups:
- Re: Re: Replacing Values Close to One
- From: Yuri Kandrashkin <spinalgebra@gmail.com>
- Re: Re: Replacing Values Close to One