 
 
 
 
 
 
Re: SameTest in Union
- To: mathgroup at smc.vnet.net
- Subject: [mg61119] Re: SameTest in Union
- From: "Jose M. Martinez" <martinez at cs.utwente.nl>
- Date: Tue, 11 Oct 2005 03:20:10 -0400 (EDT)
- Organization: University of Twente, The Netherlands
- References: <did38g$qht$1@smc.vnet.net>
- Reply-to: martinez at cs.utwente.nl
- Sender: owner-wri-mathgroup at wolfram.com
Hi Jack,
Here is one possible solution:
In[1]:=lst = {1.1101, 1.11095, 1.11076, 1.09, 2.3523, 2.352, 2.35211};
In[2]:=Union[lst, SameTest -> (Abs[#1 - #2] < 1*^-2 &)]
Out[2]:={1.09, 1.1101, 2.352}
regards,
-----------------------------------------------------------------------
Jose M. Martinez
Ph.D. Student
Design and Analysis of Communication Systems
Faculty of Electrical Engineering, Mathematics and Computer Science
University of Twente
P.O.Box 217, 7500 AE Enschede, The Netherlands
Jack Goldberg wrote:
> Hi Folks,
> 
> I know there is a simple answer to this question but the help index  
> idoes not help!
> 
> I have a list, something like this:
> 
> lst = {1.1101, 1.11095, 1.11076, 1.09, 2.3523, 2.352. 2.35211}
> 
> I want to remove from the list those entries which are near each  
> other but not identical, leaving only one representative for each of  
> these numbers.  One approach is to use  Union with the option   
> SameTest->???.   Here the same test might be that the difference  
> between entries is less than, say 10^(-2).   But I can't seem to get  
> SameTest to work.  So, what I want is
> 
> Union[ lst, SameTest- > ?]
> 
> so that  the union returns
> 
> {1.1101,  2.35211}
> 
> Here, I chose 2 representatives.  Any other choice is OK;   say,
> 
> {1.11095,  2.352}
> 
> is also satisfactory.
> 
> There may be other ways to do this, but I thought of  Union  first.   
> Perhaps, Cases  or Select  might be better.  Any help is appreciated.
> 
> Jack
> 

