Re: the Union of real numbers
- To: mathgroup at smc.vnet.net
- Subject: [mg7029] Re: the Union of real numbers
- From: adams (Adam Strzebonski)
- Date: Fri, 2 May 1997 21:30:54 -0400 (EDT)
- Organization: Wolfram Research, Inc.
- Sender: owner-wri-mathgroup at wolfram.com
SameTest option allows to specify a function to be used by Union
to decide which elements should be considered equal:
In[1]:= N[{Pi, Pi+10^-10, Pi-10^-10}]
Out[1]= {3.14159, 3.14159, 3.14159}
In[2]:= Union[%]
Out[2]= {3.14159, 3.14159, 3.14159}
In[3]:= t = If[NumericQ[#1] && NumericQ[#2],
Abs[N[#1 - #2]] < 10^-6,
#1===#2]&;
In[4]:= Union[%1, SameTest->t]
Out[4]= {3.14159}
Adam Strzebonski
Wolfram Research
In article <5k9gf9$m55 at smc.vnet.net> rustybel at foothill.net (Russell Towle)
writes:
> Hi,
>
> I am trying to apply the Union function to a list of real numbers, in
which
> many duplicates occur. However, small differences between the numbers
> cause some of the duplicates to be retained instead of discarded.
>
> Suppose the list of real numbers is called k, my present work-around is
as
> follows:
>
> Union [ Rationalize [ k, 10^-6 ] ].
>
> This does discard the duplicates. Is there a better method?
>
> Russell Towle
> Giant Gap Press: books on California history, digital topographic maps
> P.O. Box 141
> Dutch Flat, California 95714
> ------------------------------
> Voice: (916) 389-2872
> e-mail: rustybel at foothill.net
> ------------------------------
>
>