Services & ResourcesWolfram Forums
 MathGroup Archive
 2006 January February March April May June July August September October November December

Re: programming problem about elements taken

• To: mathgroup at smc.vnet.net
• Subject: [mg72475] Re: [mg72470] programming problem about elements taken
• From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
• Date: Sun, 31 Dec 2006 05:11:01 -0500 (EST)
• References: <200612301039.FAA21673@smc.vnet.net>

On 30 Dec 2006, at 19:39, Barrow wrote:

> Dear all,
>   I have a list of numbers (A),in fact, they are numbers distributed
> over [0,1].  Given parameter \epsilon, I have to choose elements
> from A
> such that their distances are larger than \epsilon, so the elements
> are
> "distringuishable". My goal is to find the maximum number of elements
> from A to meet the above "distinct criterion".
>   How to do it with the functions build-in in mathematica ??
>   Thanks in advence.           Sincerely           Barrow
>

Consider this list of 5 numbers:

ls = Sort[Table[Random[], {5}]]
{0.165874, 0.256035, 0.556211, 0.811305, 0.865799}
Suppose we take epsilon = 0.3 and identify the numbers distant by
less than that from one another. Then

Union[ls, SameTest -> (Abs[#1 - #2] < 0.3 &)]
{0.165874, 0.556211, 0.865799}
gives us just three numbers.

With epsilon =0.5 we get

Union[ls, SameTest -> (Abs[#1 - #2] < 0.5 &)]
{0.165874, 0.811305}

and setting epsilon to 0.7

Union[ls, SameTest -> (Abs[#1 - #2] < 0.7 &)]

{0.165874}

Note that when two numbers are identified it is the smaller one that
is kept.
If you prefer to return just the number of elements rather than a
minimal set (which is, of course, not unique) then use

Length[Union[ls, SameTest -> (Abs[#1 - #2] < 0.5 &)]]
2

Andrzej Kozlowski



• Prev by Date: Re: programming problem about elements taken
• Next by Date: NDSolve with a constraint : how ?