Re: Minimization
- To: mathgroup at smc.vnet.net
- Subject: [mg42271] Re: [mg42256] Minimization
- From: Selwyn Hollis <selwynh at earthlink.net>
- Date: Thu, 26 Jun 2003 05:36:25 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Here's my candidate: nClosest[pts_, target_, n_] := With[{dists = (#.#)^(1/2)& /@ ((#-target &) /@ pts)}, pts[[Flatten[Position[dists,#]& /@ Sort[dists][[Range[n]]] ] ]] ] pts = Table[{Random[],Random[],Random[]}, {10000}]; nClosest[pts, {0, 1, 0}, 5] // Timing {0.28 Second, {{0.0277056, 0.986619, 0.0229535}, {0.0640714, 0.962999, 0.0156905}, {0.0742468, 0.980008, 0.0194012}, {0.0196177, 0.918258, 0.0146842}, {0.0438055, 0.98697, 0.0753717}}} ----- Selwyn Hollis http://www.math.armstrong.edu/faculty/hollis On Wednesday, June 25, 2003, at 01:53 AM, Moranresearch at aol.com wrote: > > I have a list of points l1= (xi,yi, zi) and a target point (x0,y0,z0) > how > would I efficiently find the 5 points in l1 closest to, ie with the > smallest > Euclidian disance to, the target point? Thank you. > John > >