MathGroup Archive 2005

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

Search the Archive

Re: Dropping Similar Numbers from List

  • To: mathgroup at smc.vnet.net
  • Subject: [mg60596] Re: Dropping Similar Numbers from List
  • From: Peter Pein <petsie at dordos.net>
  • Date: Wed, 21 Sep 2005 03:20:37 -0400 (EDT)
  • References: <dgolfn$hrg$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

andre schrieb:
> My data set has some numbers which differ by a small amount, say one
> part in 10^-15, that I don't want to appear more than once.  If they
> were identical, I would just use Union[data] and be finished.  Is there
> a way to set a tollerance for the Union function?
> 
> I tried to use SetPrecision to get rid of the unwanted extra digits,
> but Union[SetPrecision[data,n]] gives the same result as Union[data].
> What exactly does SetPrecision do?  It seems that it's not just
> dropping the digits beyond the limit I set.
> 
> Andre
> 
Hi Andre,

 have a look at the documentation. You can specify as Option SameTest a
function to decide which elements of a set are considered equal.

In[1]:=
x0 = 1.234;
vec = x0 + Range[3]/10^10;
Outer[Equal, vec, vec, 1]
Out[3]=
{{True, False, False},
  {False, True, False},
  {False, False, True}}
In[4]:=
Union[vec]
Out[4]= {1.2340000001, 1.2340000002, 1.2340000003}
In[5]:= Union[vec, SameTest -> (Abs[#1 - #2] < Abs[#1 + #2]/10^8 & )]
Out[5]=
{1.2340000001}

-- 
Peter Pein, Berlin
GnuPG Key ID: 0xA34C5A82
http://people.freenet.de/Peter_Berlin/


  • Prev by Date: Re: init.m
  • Next by Date: Problem in loading the Statistics package.
  • Previous by thread: Re: Dropping Similar Numbers from List
  • Next by thread: init.m