Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2003
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2003

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

Search the Archive

Re: Finding the closest number from a list

  • To: mathgroup at smc.vnet.net
  • Subject: [mg39562] Re: Finding the closest number from a list
  • From: Bill Rowe <listuser at earthlink.net>
  • Date: Sun, 23 Feb 2003 05:00:29 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

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