MathGroup Archive 2003

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

Search the Archive

Re: Finding the closest number from a list


On 2/22/03 at 3:38 AM, drbob at bigfoot.com (Dr Bob) wrote:

>I think this works just as well, and a little faster:
>
>closest[list_?VectorQ, things_?VectorQ] := Module[{sorted, lint,
>first, last, n = Length[list], lower, upper}, \ sorted = Sort[list];
>first = Max[Min[things], First[sorted]] - 1; last = Min[Max[things],
>Last[sorted]] + 1; lint = ListInterpolation[Join[{1}, Range[n], {n}],
>{ Join[{first}, sorted, {last}]}, InterpolationOrder -> 1];
>list[[Round@lint@things]]
>]

I think that last line of code should be sorted[[Round@lint@things]]


  • Prev by Date: Problems with Parsing !
  • Next by Date: Re: Epsilon-Delta proofs
  • Previous by thread: Re: Finding the closest number from a list
  • Next by thread: Re: Finding the closest number from a list