Re: Distance from point to set

*To*: mathgroup at smc.vnet.net*Subject*: [mg55338] Re: Distance from point to set*From*: "Steve Luttrell" <steve_usenet at _removemefirst_luttrell.org.uk>*Date*: Sat, 19 Mar 2005 04:46:32 -0500 (EST)*References*: <d1eblq$ek7$1@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

Here is how you would define a function to do this for a Euclidean distance measure: d[x_,A_]:=Min[Map[#.#&[x-#]&,A]]; More generally you could pass a 3rd argument to this function to specify a function for measuring distance: d[x_,A_,norm_]:=Min[Map[norm[x,#]&,A]]; Try out this function (the 2 argument version): n=2; x=Table[Random[Real,{-1,1}],{2}] A=Table[Random[Real,{-1,1}],{10},{2}] d[x,A] Steve Luttrell "Piotr Kowalski" <pkowalsk at ibspan.waw.pl> wrote in message news:d1eblq$ek7$1 at smc.vnet.net... > Hello, > > I would like to compute distance d(x,A) from a point 'x' to a set 'A', > (all in R^n, where n=2 or n=3) that is: > > d(x,A) = min ||x - a|| (forall a in A) > where: n=2 or n=3, > x is point in R^n, A is subset of R^n > || || is norm (euclidean, max, etc). > > Can I find Mathematica function or package for such problem ? > > Thank you in advance, > P. Kowalski >